• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中jsonc-parser.getLocation函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getLocation函数的具体用法?TypeScript getLocation怎么用?TypeScript getLocation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了getLocation函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: provideCompletionItems

	public provideCompletionItems(position: vscode.Position, token: vscode.CancellationToken): vscode.ProviderResult<vscode.CompletionItem[]> {
		const location = getLocation(this.document.getText(), this.document.offsetAt(position));
		const range = this.document.getWordRangeAtPosition(position) || new vscode.Range(position, position);

		// window.title
		if (location.path[0] === 'window.title') {
			return this.provideWindowTitleCompletionItems(location, range);
		}

		// files.association
		if (location.path[0] === 'files.associations') {
			return this.provideFilesAssociationsCompletionItems(location, range);
		}

		// files.exclude, search.exclude
		if (location.path[0] === 'files.exclude' || location.path[0] === 'search.exclude') {
			return this.provideExcludeCompletionItems(location, range);
		}

		// files.defaultLanguage
		if (location.path[0] === 'files.defaultLanguage') {
			return this.provideLanguageCompletionItems(location, range);
		}

		return this.provideLanguageOverridesCompletionItems(location, position);
	}
开发者ID:FabianLauer,项目名称:vscode,代码行数:26,代码来源:settingsDocumentHelper.ts


示例2: activate

export function activate(context) {

	const commands = vscode.commands.getCommands(true);

	//keybindings.json command-suggestions
	const disposable = vscode.languages.registerCompletionItemProvider({ pattern: '**/keybindings.json' }, {

		provideCompletionItems(document, position, token) {
			const location = getLocation(document.getText(), document.offsetAt(position));
			if (location.path[1] === 'command') {

				const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);

				return commands.then(ids => ids.map(id => {
					const item = new vscode.CompletionItem(`"${id}"`);
					item.kind = vscode.CompletionItemKind.Value;
					item.textEdit = {
						range,
						newText: item.label
					};
					return item;
				}));
			}
		}
	});

	context.subscriptions.push(disposable);
}
开发者ID:bobmagicii,项目名称:vscode,代码行数:28,代码来源:extension.ts


示例3: provideCompletionItems

	public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Thenable<CompletionList> {

		let fileName = basename(document.fileName);

		let currentWord = this.getCurrentWord(document, position);
		let overwriteRange : Range;

		let items: CompletionItem[] = [];
		let isIncomplete = false;

		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 Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
		} else {
			overwriteRange = new Range(document.positionAt(offset - currentWord.length), position);
		}
		let filterText = document.getText(new Range(overwriteRange.start, position));

		let proposed: { [key: string]: boolean } = {};
		let collector: ISuggestionsCollector = {
			add: (suggestion: CompletionItem) => {
				if (!proposed[suggestion.label]) {
					proposed[suggestion.label] = true;
					suggestion.textEdit = TextEdit.replace(overwriteRange, suggestion.insertText);
					suggestion.filterText = filterText;

					items.push(suggestion);
				}
			},
			setAsIncomplete: () => isIncomplete = true,
			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;
			let isLast = this.isLast(document, position);
			collectPromise = this.jsonContribution.collectPropertySuggestions(fileName, location, currentWord, addValue, isLast, collector);
		} else {
			if (location.path.length === 0) {
				collectPromise = this.jsonContribution.collectDefaultSuggestions(fileName, collector);
			} else {
				collectPromise = this.jsonContribution.collectValueSuggestions(fileName, location, collector);
			}
		}
		if (collectPromise) {
			return collectPromise.then(() => {
				if (items.length > 0) {
					return new CompletionList(items, isIncomplete);
				}
				return null;
			});
		}
		return null;
	}
开发者ID:Aarushi-Ign,项目名称:vscode,代码行数:60,代码来源:jsonContributions.ts


示例4: registerExtensionsCompletions

function registerExtensionsCompletions(): vscode.Disposable {
	return vscode.languages.registerCompletionItemProvider({ pattern: '**/extensions.json' }, {
		provideCompletionItems(document, position, token) {
			const location = getLocation(document.getText(), document.offsetAt(position));
			const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
			if (location.path[0] === 'recommendations') {
				const config = parse(document.getText());
				const alreadyEnteredExtensions = config && config.recommendations || [];
				if (Array.isArray(alreadyEnteredExtensions)) {
					return vscode.extensions.all
						.filter(e => !(
							e.id.startsWith('vscode.')
							|| e.id === 'Microsoft.vscode-markdown'
							|| alreadyEnteredExtensions.indexOf(e.id) > -1
						))
						.map(e => {
							const item = new vscode.CompletionItem(e.id);
							const insertText = `"${e.id}"`;
							item.kind = vscode.CompletionItemKind.Value;
							item.insertText = insertText;
							item.range = range;
							item.filterText = insertText;
							return item;
						});
				}
			}
			return [];
		}
	});
}
开发者ID:FabianLauer,项目名称:vscode,代码行数:30,代码来源:extension.ts


示例5: provideCompletionItems

	public provideCompletionItems(position: vscode.Position, token: vscode.CancellationToken): vscode.ProviderResult<vscode.CompletionItem[]> {
		const location = getLocation(this.document.getText(), this.document.offsetAt(position));

		if (location.path.length >= 2 && location.path[1] === 'configurationDefaults') {
			return this.provideLanguageOverridesCompletionItems(location, position);
		}

	}
开发者ID:diarmaidm,项目名称:vscode,代码行数:8,代码来源:packageDocumentHelper.ts


示例6: 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


示例7: registerKeybindingsCompletions

function registerKeybindingsCompletions(): vscode.Disposable {
	const commands = vscode.commands.getCommands(true);

	return vscode.languages.registerCompletionItemProvider({ pattern: '**/keybindings.json' }, {

		provideCompletionItems(document, position, token) {
			const location = getLocation(document.getText(), document.offsetAt(position));
			if (location.path[1] === 'command') {

				const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
				return commands.then(ids => ids.map(id => newCompletionItem(id, range)));
			}
		}
	});
}
开发者ID:elemongw,项目名称:vscode,代码行数:15,代码来源:extension.ts


示例8: activate

export function activate(context) {

	const commands = vscode.commands.getCommands(true);

	//keybindings.json command-suggestions
	const disposable = vscode.languages.registerCompletionItemProvider({ pattern: '**/keybindings.json' }, {

		provideCompletionItems(document, position, token) {
			const location = getLocation(document.getText(), document.offsetAt(position));
			if (location.path[1] === 'command') {
				return commands.then(ids => ids.map(id => new vscode.CompletionItem(id, vscode.CompletionItemKind.Value)));
			}
		}
	});

	context.subscriptions.push(disposable);
}
开发者ID:1Hgm,项目名称:vscode,代码行数:17,代码来源:extension.ts


示例9: provideHover

	public provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.Hover> {
		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) {
			let promise = this.jsonContribution.getInfoContribution(document.fileName, location);
			if (promise) {
				return promise.then(htmlContent => {
					let range = new vscode.Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
					let result: vscode.Hover = {
						contents: htmlContent,
						range: range
					};
					return result;
				});
			}
		}
		return null;
	}
开发者ID:claudiug,项目名称:code-d,代码行数:19,代码来源:json-contributions.ts


示例10: provideHover

	public provideHover(document: TextDocument, position: Position, _token: CancellationToken): Thenable<Hover> | null {
		const fileName = basename(document.fileName);
		const offset = document.offsetAt(position);
		const location = getLocation(document.getText(), offset);
		if (!location.previousNode) {
			return null;
		}
		const node = location.previousNode;
		if (node && node.offset <= offset && offset <= node.offset + node.length) {
			const promise = this.jsonContribution.getInfoContribution(fileName, location);
			if (promise) {
				return promise.then(htmlContent => {
					const range = new Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
					const result: Hover = {
						contents: htmlContent || [],
						range: range
					};
					return result;
				});
			}
		}
		return null;
	}
开发者ID:developers23,项目名称:vscode,代码行数:23,代码来源:jsonContributions.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript jsonc-parser.parse函数代码示例发布时间:2022-05-25
下一篇:
TypeScript jsonc-parser.findNodeAtLocation函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap