本文整理汇总了TypeScript中vscode-languageserver-types.TextDocument类的典型用法代码示例。如果您正苦于以下问题:TypeScript TextDocument类的具体用法?TypeScript TextDocument怎么用?TypeScript TextDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextDocument类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: applyEdits
function applyEdits(oldStr: string, newStr: string): void {
let doc = TextDocument.create('untitled://1', 'markdown', 0, oldStr)
let changes = getContentChanges(doc, newStr)
let res = TextDocument.applyEdits(doc, changes.map(o => {
return { range: o.range, newText: o.text }
}))
expect(res).toBe(newStr)
}
开发者ID:demelev,项目名称:coc.nvim,代码行数:8,代码来源:diff.test.ts
示例2: getTagNameRange
function getTagNameRange(tokenType: TokenType, document: TextDocument, startOffset: number): Range | null {
const scanner = createScanner(document.getText(), startOffset);
let token = scanner.scan();
while (token !== TokenType.EOS && token !== tokenType) {
token = scanner.scan();
}
if (token !== TokenType.EOS) {
return { start: document.positionAt(scanner.getTokenOffset()), end: document.positionAt(scanner.getTokenEnd()) };
}
return null;
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:11,代码来源:htmlHighlighting.ts
示例3: applyEdits
function applyEdits(oldStr: string, newStr: string): void {
let doc = TextDocument.create('untitled://1', 'markdown', 0, oldStr)
let change = getChange(doc.getText(), newStr)
let start = doc.positionAt(change.start)
let end = doc.positionAt(change.end)
let edit: TextEdit = {
range: { start, end },
newText: change.newText
}
let res = TextDocument.applyEdits(doc, [edit])
expect(res).toBe(newStr)
}
开发者ID:illarionvk,项目名称:dotfiles,代码行数:12,代码来源:diff.test.ts
示例4: getEmbeddedDocument
function getEmbeddedDocument(document: TextDocument, contents: EmbeddedRegion[], languageId: string): TextDocument {
const oldContent = document.getText();
let result = '';
for (const c of contents) {
if (c.languageId === languageId) {
result = oldContent.substring(0, c.start).replace(/./g, ' ');
result += oldContent.substring(c.start, c.end);
break;
}
}
return TextDocument.create(document.uri, languageId, document.version, result);
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:12,代码来源:embeddedSupport.ts
示例5: getValueAndRange
function getValueAndRange(document: TextDocument, currRange: Range): { value: string; range: Range } {
let value = document.getText();
let range = currRange;
if (currRange) {
const startOffset = document.offsetAt(currRange.start);
const endOffset = document.offsetAt(currRange.end);
value = value.substring(startOffset, endOffset);
} else {
range = Range.create(Position.create(0, 0), document.positionAt(value.length));
}
return { value, range };
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:13,代码来源:index.ts
示例6: getLanguageRangeByType
function getLanguageRangeByType(
document: TextDocument,
contents: EmbeddedRegion[],
type: EmbeddedType
): LanguageRange | undefined {
for (const c of contents) {
if (c.type === type) {
return {
start: document.positionAt(c.start),
end: document.positionAt(c.end),
languageId: c.languageId
};
}
}
}
开发者ID:tiravata,项目名称:vetur,代码行数:15,代码来源:embeddedSupport.ts
示例7: assertEmbeddedLanguageContent
function assertEmbeddedLanguageContent(value: string, languageId: string, expectedContent: string): void {
let document = TextDocument.create('test://test/test.html', 'html', 0, value);
let docRegions = embeddedSupport.getDocumentRegions(htmlLanguageService, document);
let content = docRegions.getEmbeddedDocument(languageId);
assert.equal(content.getText(), expectedContent);
}
开发者ID:AllureFer,项目名称:vscode,代码行数:7,代码来源:embedded.test.ts
示例8: assertCompletions
function assertCompletions(syntax: string, value: string, expectedProposal: string, expectedProposalDoc: string): void {
const offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);
const document = TextDocument.create('test://test/test.' + syntax, syntax, 0, value);
const position = document.positionAt(offset);
const documentRegions = getLanguageModelCache<embeddedSupport.HTMLDocumentRegions>(10, 60, document => embeddedSupport.getDocumentRegions(htmlLanguageService, document));
const mode = syntax == 'html' ? getHTMLMode(htmlLanguageService) : getCSSMode(documentRegions);
const emmetCompletionList: CompletionList = {
isIncomplete: true,
items: undefined
}
mode.setCompletionParticipants([getEmmetCompletionParticipants(document, position, document.languageId, {}, emmetCompletionList)])
const list = mode.doComplete!(document, position);
assert.ok(list);
assert.ok(emmetCompletionList)
if (expectedProposal && expectedProposalDoc) {
let actualLabels = emmetCompletionList!.items.map(c => c.label).sort();
let actualDocs = emmetCompletionList!.items.map(c => c.documentation).sort();
assert.ok(actualLabels.indexOf(expectedProposal) !== -1, 'Not found:' + expectedProposal + ' is ' + actualLabels.join(', '));
assert.ok(actualDocs.indexOf(expectedProposalDoc) !== -1, 'Not found:' + expectedProposalDoc + ' is ' + actualDocs.join(', '));
} else {
assert.ok(!emmetCompletionList || !emmetCompletionList.items);
}
}
开发者ID:sameer-coder,项目名称:vscode,代码行数:29,代码来源:emmet.test.ts
示例9:
sortedEdits.forEach(e => {
const startOffset = document.offsetAt(e.range.start);
const endOffset = document.offsetAt(e.range.end);
assert.ok(startOffset <= endOffset);
assert.ok(endOffset <= lastOffset);
text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
lastOffset = startOffset;
});
开发者ID:tiravata,项目名称:vetur,代码行数:8,代码来源:completion-test-util.ts
示例10:
const ranges = applicableRanges.map(pair => {
return {
range: Range.create(
document.positionAt(pair[0]),
document.positionAt(pair[1])
),
kind: SelectionRangeKind.Statement
};
});
开发者ID:Microsoft,项目名称:vscode-css-languageservice,代码行数:9,代码来源:cssSelectionRange.ts
注:本文中的vscode-languageserver-types.TextDocument类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论