本文整理汇总了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)
}
示例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;
}
示例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)
}
示例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);
}
示例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 };
}
示例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
};
}
}
}
示例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);
}
示例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);
}
}
示例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;
});
示例10:
const ranges = applicableRanges.map(pair => {
return {
range: Range.create(
document.positionAt(pair[0]),
document.positionAt(pair[1])
),
kind: SelectionRangeKind.Statement
};
});