本文整理汇总了TypeScript中vscode-languageserver.ITextDocument类的典型用法代码示例。如果您正苦于以下问题:TypeScript ITextDocument类的具体用法?TypeScript ITextDocument怎么用?TypeScript ITextDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ITextDocument类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getEOL
function getEOL(document: ITextDocument): string {
let text = document.getText();
if (document.lineCount > 1) {
let to = document.offsetAt(Position.create(1, 0));
let from = to;
while (from > 0 && isEOL(text, from - 1)) {
from--;
}
return text.substr(from, to - from);
}
return '\n';
}
示例2: validateTextDocument
function validateTextDocument(textDocument: ITextDocument): void {
let linterBinPath = path.join(__dirname, '../../server/glualint');
connection.console.log("lel");
connection.console.log(linterBinPath);
let stdout = childProcess.execFileSync(linterBinPath, ['stdin'], {input: textDocument.getText()});
let diagnostics: Diagnostic[] = [];
let lines = stdout.toString().split('\n');
for (let i = 0; i < lines.length; i++) {
let m = errorRegex.exec(lines[i]);
if (m != null) {
var severity = DiagnosticSeverity.Error;
if (m[1] == 'Warning') {
severity = DiagnosticSeverity.Warning;
}
diagnostics.push({
severity: severity,
range: {
start: { line: parseInt(m[2]) - 1, character: parseInt(m[3]) - 1},
end: { line: parseInt(m[2]) - 1, character: parseInt(m[3]) - 1 + 3 }
},
message: m[4],
source: 'glualint'
});
}
}
// Send the computed diagnostics to VSCode.
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
}
示例3: getOutline
function getOutline(value: string): Promise<SymbolInformation[]> {
var uri = 'test://test.json';
var symbolProvider = new JSONDocumentSymbols();
var document = ITextDocument.create(uri, value);
var jsonDoc = Parser.parse(value);
return symbolProvider.compute(document, jsonDoc);
}
示例4: format
function format(unformatted: string, expected: string, insertSpaces = true) {
let range: Range = null;
let uri = 'test://test.json';
let rangeStart = unformatted.indexOf('|');
let rangeEnd = unformatted.lastIndexOf('|');
if (rangeStart !== -1 && rangeEnd !== -1) {
// remove '|'
var unformattedDoc = ITextDocument.create(uri, unformatted);
unformatted = unformatted.substring(0, rangeStart) + unformatted.substring(rangeStart + 1, rangeEnd) + unformatted.substring(rangeEnd + 1);
let startPos = unformattedDoc.positionAt(rangeStart);
let endPos = unformattedDoc.positionAt(rangeEnd);
range = Range.create(startPos, endPos);
}
var document = ITextDocument.create(uri, unformatted);
let edits = Formatter.format(document, range, { tabSize: 2, insertSpaces: insertSpaces });
let formatted = applyEdits(document, edits);
assert.equal(formatted, expected);
}
示例5: makeDiagnostic
function makeDiagnostic(document: ITextDocument, message: PhpcsReportMessage): Diagnostic {
let lines = document.getText().split("\n");
let line = message.line - 1;
let lineString = lines[line];
// Process diagnostic start and end columns.
let start = message.column - 1;
let end = message.column;
let charCode = lineString.charCodeAt(start);
if (cc.isWhitespace(charCode)) {
for (var i = start + 1, len = lineString.length; i < len; i++) {
charCode = lineString.charCodeAt(i);
if (!cc.isWhitespace(charCode)) {
break;
}
end = i;
}
} else if (cc.isAlphaNumeric(charCode) || cc.isSymbol(charCode)) {
// Get the whole word
for (var i = start + 1, len = lineString.length; i < len; i++) {
charCode = lineString.charCodeAt(i);
if (!cc.isAlphaNumeric(charCode) && charCode !== 95) {
break;
}
end += 1;
}
// Move backwards
for (var i = start, len = 0; i > len; i--) {
charCode = lineString.charCodeAt(i - 1);
if (!cc.isAlphaNumeric(charCode) && !cc.isSymbol(charCode) && charCode !== 95) {
break;
}
start -= 1;
}
}
// Process diagnostic severity.
let severity = DiagnosticSeverity.Error;
if (message.type === 'WARNING') {
severity = DiagnosticSeverity.Warning;
}
let diagnostic: Diagnostic = {
range: {
start: { line, character: start },
end: { line, character: end }
},
severity,
message: `${ message.message }`
};
return diagnostic;
};
示例6: testComputeInfo
function testComputeInfo(value: string, schema: JsonSchema.IJSONSchema, position: Position): Thenable<Hover> {
var uri = 'test://test.json';
var schemaService = new SchemaService.JSONSchemaService(requestService);
var hoverProvider = new JSONHover(schemaService);
var id = "http://myschemastore/test1";
schemaService.registerExternalSchema(id, ["*.json"], schema);
var document = ITextDocument.create(uri, value);
var textDocumentLocation = TextDocumentPosition.create(uri, position);
var jsonDoc = Parser.parse(value);
return hoverProvider.doHover(document, textDocumentLocation, jsonDoc);
}
示例7: applyEdits
export function applyEdits(document: ITextDocument, edits: TextEdit[]) : string {
let formatted = document.getText();
let sortedEdits = edits.sort((a, b) => document.offsetAt(b.range.start) - document.offsetAt(a.range.start));
let lastOffset = formatted.length;
sortedEdits.forEach(e => {
let startOffset = document.offsetAt(e.range.start);
let endOffset = document.offsetAt(e.range.end);
assert.ok(startOffset <= endOffset);
assert.ok(endOffset <= lastOffset);
formatted = formatted.substring(0, startOffset) + e.newText + formatted.substring(endOffset, formatted.length);
lastOffset = startOffset;
});
return formatted;
}
示例8: function
var testSuggestionsFor = function(value: string, stringAfter: string, schema: JsonSchema.IJSONSchema, test: (items: CompletionItem[], document: ITextDocument) => void) : Thenable<void> {
var uri = 'test://test.json';
var idx = stringAfter ? value.indexOf(stringAfter) : 0;
var schemaService = new SchemaService.JSONSchemaService(requestService);
var completionProvider = new JSONCompletion(schemaService, console);
if (schema) {
var id = "http://myschemastore/test1";
schemaService.registerExternalSchema(id, ["*.json"], schema);
}
var document = ITextDocument.create(uri, value);
var textDocumentLocation = TextDocumentPosition.create(uri, Position.create(0, idx));
var jsonDoc = Parser.parse(value);
return completionProvider.doSuggest(document, textDocumentLocation, jsonDoc).then(list => list.items).then(completions => {
test(completions, document);
return null;
})
};
示例9: validateTextDocument
function validateTextDocument(textDocument: ITextDocument): void {
let diagnostics: Diagnostic[] = [];
let lines = textDocument.getText().split(/\r?\n/g);
let problems = 0;
for (var i = 0; i < lines.length && problems < maxNumberOfProblems; i++) {
let line = lines[i];
let index = line.indexOf('typescript');
if (index >= 0) {
problems++;
diagnostics.push({
severity: DiagnosticSeverity.Warning,
range: {
start: { line: i, character: index},
end: { line: i, character: index + 10 }
},
message: `${line.substr(index, 10)} should be spelled TypeScript`
});
}
}
// Send the computed diagnostics to VSCode.
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
}
示例10:
sortedEdits.forEach(e => {
let startOffset = document.offsetAt(e.range.start);
let endOffset = document.offsetAt(e.range.end);
assert.ok(startOffset <= endOffset);
assert.ok(endOffset <= lastOffset);
formatted = formatted.substring(0, startOffset) + e.newText + formatted.substring(endOffset, formatted.length);
lastOffset = startOffset;
});