当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript jsonc-parser.createScanner函数代码示例

本文整理汇总了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;
	}
开发者ID:developers23,项目名称:vscode,代码行数:9,代码来源:jsonContributions.ts

示例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;
	}
开发者ID:claudiug,项目名称:code-d,代码行数:53,代码来源:json-contributions.ts


注:本文中的jsonc-parser.createScanner函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。