本文整理汇总了TypeScript中vscode-languageserver-types.TextDocument.getText方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextDocument.getText方法的具体用法?TypeScript TextDocument.getText怎么用?TypeScript TextDocument.getText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode-languageserver-types.TextDocument
的用法示例。
在下文中一共展示了TextDocument.getText方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createDiagnosis
export function createDiagnosis(
doc: TextDocument,
fileProcessor: FileProcessor<StylableMeta>,
requireModule: typeof require
): Diagnostic[] {
if (!doc.uri.endsWith('.st.css')) {
return [];
}
const file = fromVscodePath(doc.uri);
const transformer = new StylableTransformer({
diagnostics: new Diagnostics(),
fileProcessor,
requireModule
});
const docPostCSSRoot = safeParse(doc.getText(), { from: path.resolve(file) });
const meta = process(docPostCSSRoot);
fileProcessor.add(file, meta);
try {
transformer.transform(meta);
} catch { /**/ }
return meta.diagnostics.reports
.concat(meta.transformDiagnostics ? meta.transformDiagnostics.reports : [])
.map(reportToDiagnostic);
// stylable diagnostic to protocol diagnostic
function reportToDiagnostic(report: StylableDiagnostic) {
const severity = report.type === 'error' ? 1 : 2;
const range = createRange(report);
return Diagnostic.create(range, report.message, severity);
}
}
示例2: provideCompletionItems
export function provideCompletionItems(document: TextDocument, position: Position): CompletionList {
const start = document.offsetAt(Position.create(position.line, 0));
const end = document.offsetAt(position);
const text = document.getText();
const currentWord = text.slice(start, end).trim();
const value = isValue(cssSchema, currentWord);
let completions: CompletionItem[] = [];
if (value) {
const values = getValues(cssSchema, currentWord);
const symbols = getAllSymbols(text, currentWord, position).filter(
item => item.kind === CompletionItemKind.Variable || item.kind === CompletionItemKind.Function
);
completions = completions.concat(values, symbols, builtIn);
} else {
const atRules = getAtRules(cssSchema, currentWord);
const properties = getProperties(cssSchema, currentWord, false);
const symbols = getAllSymbols(text, currentWord, position).filter(
item => item.kind !== CompletionItemKind.Variable
);
completions = completions.concat(properties, atRules, symbols);
}
return {
isIncomplete: false,
items: completions
};
}
示例3: stylusHover
export function stylusHover(document: TextDocument, position: Position): Hover {
const ast = buildAst(document.getText());
if (!ast) {
return {
contents: ''
};
}
const node = findNodeAtPosition(ast, position);
if (!node) {
return {
contents: 'no node found!'
};
}
if (node.__type === 'Property') {
const property = node.segments[0].name;
const properties = cssSchema.data.css.properties;
const item = _.find(properties, item => item.name === property);
const lineno = node.lineno - 1;
const column = node.column;
return {
contents: (item && item.desc) || 'unknown property',
range: Range.create(lineno, column, lineno, column + properties.length)
};
}
return {
contents: []
};
}
示例4: function
let assertLink = function (links: DocumentLink[], expected: ItemDescription, document: TextDocument) {
let matches = links.filter(link => {
return document.offsetAt(link.range.start) === expected.offset;
});
assert.equal(matches.length, 1, `${expected.offset} should only existing once: Actual: ${links.map(l => document.offsetAt(l.range.start)).join(', ')}`);
let match = matches[0];
assert.equal(document.getText(match.range), expected.value);
assert.equal(match.target, expected.target);
};
示例5: doValidation
export function doValidation(document: TextDocument, engine: CLIEngine): Diagnostic[] {
const rawText = document.getText();
// skip checking on empty template
if (rawText.replace(/\s/g, '') === '') {
return [];
}
const text = rawText.replace(/ {10}/, '<template>') + '</template>';
const report = engine.executeOnText(text, document.uri);
return report.results[0] ? report.results[0].messages.map(toDiagnostic) : [];
}
示例6: 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;
}
示例7: provideDocumentSymbols
export function provideDocumentSymbols(document: TextDocument): SymbolInformation[] {
const text = document.getText();
const ast = buildAst(text);
if (!ast) {
return [];
}
const rawSymbols = _.compact(flattenAndFilterAst(ast));
const symbolInfos = processRawSymbols(rawSymbols, text.split('\n'));
return _.uniqBy(symbolInfos, _buildHashFromSymbol);
}
示例8: 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);
}
示例9: 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 };
}
示例10: applyEdits
function applyEdits(document: TextDocument, edits: TextEdit[]): string {
let text = document.getText();
const sortedEdits = edits.sort((a, b) => document.offsetAt(b.range.start) - document.offsetAt(a.range.start));
let lastOffset = text.length;
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;
});
return text;
}