本文整理汇总了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';
}
开发者ID:13572293130,项目名称:vscode,代码行数:12,代码来源:jsonFormatter.ts
示例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 });
}
开发者ID:wyozi-gmod,项目名称:vscode-gluaserver,代码行数:34,代码来源:server.ts
示例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);
}
开发者ID:13572293130,项目名称:vscode,代码行数:9,代码来源:documentSymbols.test.ts
示例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);
}
开发者ID:1833183060,项目名称:vscode,代码行数:20,代码来源:formatter.test.ts
示例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;
};
开发者ID:mizunashi-mana,项目名称:vscode-phpcs,代码行数:54,代码来源:linter.ts
示例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);
}
开发者ID:13572293130,项目名称:vscode,代码行数:13,代码来源:hover.test.ts
示例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;
}
开发者ID:13572293130,项目名称:vscode,代码行数:14,代码来源:textEditSupport.ts
示例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;
})
};
开发者ID:578723746,项目名称:vscode,代码行数:19,代码来源:completion.test.ts
示例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 });
}
开发者ID:babakness,项目名称:vscode-pgsql,代码行数:22,代码来源:server.ts
示例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;
});
开发者ID:13572293130,项目名称:vscode,代码行数:8,代码来源:textEditSupport.ts
注:本文中的vscode-languageserver.ITextDocument类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论