本文整理匯總了TypeScript中jsonc-parser.createScanner函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createScanner函數的具體用法?TypeScript createScanner怎麽用?TypeScript createScanner使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了createScanner函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: isLast
private isLast(document: TextDocument, position: Position): boolean {
const scanner = createScanner(document.getText(), true);
scanner.setPosition(document.offsetAt(position));
let nextToken = scanner.scan();
if (nextToken === SyntaxKind.StringLiteral && scanner.getTokenError() === ScanError.UnexpectedEndOfString) {
nextToken = scanner.scan();
}
return nextToken === SyntaxKind.CloseBraceToken || nextToken === SyntaxKind.EOF;
}
示例2: provideCompletionItems
public provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.CompletionList> {
let currentWord = this.getCurrentWord(document, position);
let overwriteRange = null;
let items: vscode.CompletionItem[] = [];
let offset = document.offsetAt(position);
let location = getLocation(document.getText(), offset);
let node = location.previousNode;
if (node && node.offset <= offset && offset <= node.offset + node.length && (node.type === 'property' || node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) {
overwriteRange = new vscode.Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
} else {
overwriteRange = new vscode.Range(document.positionAt(offset - currentWord.length), position);
}
let proposed: { [key: string]: boolean } = {};
let collector: ISuggestionsCollector = {
add: (suggestion: vscode.CompletionItem) => {
if (!proposed[suggestion.label]) {
proposed[suggestion.label] = true;
if (overwriteRange) {
suggestion.textEdit = vscode.TextEdit.replace(overwriteRange, suggestion.insertText);
}
items.push(suggestion);
}
},
error: (message: string) => console.error(message),
log: (message: string) => console.log(message)
};
let collectPromise: Thenable<any> = null;
if (location.isAtPropertyKey) {
let addValue = !location.previousNode || !location.previousNode.columnOffset && (offset == (location.previousNode.offset + location.previousNode.length));
let scanner = createScanner(document.getText(), true);
scanner.setPosition(offset);
scanner.scan();
let isLast = scanner.getToken() === SyntaxKind.CloseBraceToken || scanner.getToken() === SyntaxKind.EOF;
collectPromise = this.jsonContribution.collectPropertySuggestions(document.fileName, location, currentWord, addValue, isLast, collector);
} else if (location.path.length !== 0)
collectPromise = this.jsonContribution.collectValueSuggestions(document.fileName, location, collector);
if (collectPromise) {
return collectPromise.then(() => {
if (items.length > 0) {
return new vscode.CompletionList(items);
}
return null;
});
}
return null;
}