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


TypeScript TextDocument.getWordRangeAtPosition方法代码示例

本文整理汇总了TypeScript中vscode.TextDocument.getWordRangeAtPosition方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextDocument.getWordRangeAtPosition方法的具体用法?TypeScript TextDocument.getWordRangeAtPosition怎么用?TypeScript TextDocument.getWordRangeAtPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vscode.TextDocument的用法示例。


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

示例1: buildDiagnostic

export function buildDiagnostic(componentFailure): Diagnostic {
    let lineNumber: number = 0;
    let columnNumber: number = 0;

    if(componentFailure.lineNumber){
        lineNumber = componentFailure.lineNumber - 1;
    }
    if(componentFailure.columnNumber){
        columnNumber = componentFailure.columnNumber - 1;
    }

    let start = new Position(lineNumber, columnNumber);
    let end = new Position(lineNumber+1, 0);
    let range = new Range(start, end);

    if(componentFailure.document){
        let document: TextDocument = componentFailure.document;
        let wordRange = document.getWordRangeAtPosition(start); 
        if(wordRange){
            range = wordRange;
        }
    }

    let newDiagnostic = new Diagnostic(range, componentFailure.problem);

    return newDiagnostic;
}
开发者ID:joeferraro,项目名称:MavensMate-VisualStudioCode,代码行数:27,代码来源:diagnosticFactory.ts

示例2: constructor

	constructor(
		public position: Position,
		public document: TextDocument,
		entry: CompletionEntry,
		enableDotCompletions: boolean,
		enableCallCompletions: boolean
	) {
		super(entry.name);
		this.sortText = entry.sortText;
		this.kind = MyCompletionItem.convertKind(entry.kind);
		this.position = position;
		this.commitCharacters = MyCompletionItem.getCommitCharacters(enableDotCompletions, enableCallCompletions, entry.kind);
		if (entry.replacementSpan) {
			let span: protocol.TextSpan = entry.replacementSpan;
			// The indexing for the range returned by the server uses 1-based indexing.
			// We convert to 0-based indexing.
			this.textEdit = TextEdit.replace(new Range(span.start.line - 1, span.start.offset - 1, span.end.line - 1, span.end.offset - 1), entry.name);
		} else {
			// Try getting longer, prefix based range for completions that span words
			const wordRange = document.getWordRangeAtPosition(position);
			const text = document.getText(new Range(position.line, Math.max(0, position.character - entry.name.length), position.line, position.character)).toLowerCase();
			const entryName = entry.name.toLowerCase();
			for (let i = entryName.length; i >= 0; --i) {
				if (text.endsWith(entryName.substr(0, i)) && (!wordRange || wordRange.start.character > position.character - i)) {
					this.range = new Range(position.line, Math.max(0, position.character - i), position.line, position.character);
					break;
				}
			}
		}
	}
开发者ID:hungys,项目名称:vscode,代码行数:30,代码来源:completionItemProvider.ts

示例3: provideHover

    public async provideHover(document: TextDocument, position: Position, token: CancellationToken): Promise<Hover> {
        if (!VariableUtility.isVariableReference(document, position)) {
            return;
        }

        let wordRange = document.getWordRangeAtPosition(position);
        let selectedVariableName = document.getText(wordRange);

        if (await FileVariableProvider.Instance.has(document, selectedVariableName)) {
            const { name, value, error, warning } = await FileVariableProvider.Instance.get(document, selectedVariableName);
            if (!warning && !error) {
                const contents: MarkedString[] = [value as string, new MarkdownString(`*File Variable* \`${name}\``)];
                return new Hover(contents, wordRange);
            }

            return;
        }

        if (await EnvironmentVariableProvider.Instance.has(document, selectedVariableName)) {
            const { name, value, error, warning } = await EnvironmentVariableProvider.Instance.get(document, selectedVariableName);
            if (!warning && !error) {
                const contents: MarkedString[] = [value as string, new MarkdownString(`*Environment Variable* \`${name}\``)];
                return new Hover(contents, wordRange);
            }

            return;
        }

        return;
    }
开发者ID:Huachao,项目名称:vscode-restclient,代码行数:30,代码来源:customVariableHoverProvider.ts

示例4: resolve

        return new Promise<Command[]>((resolve, reject) => {
            let commands: Command[] = [
                {
                    command: 'python.sortImports',
                    title: 'Sort Imports'
                }
            ];

            if (vscode.window.activeTextEditor.document === document && !vscode.window.activeTextEditor.selection.isEmpty) {
                let wordRange = document.getWordRangeAtPosition(range.start);
                // If no word has been selected by the user, then don't display rename
                // If something has been selected, then ensure we have selected a word (i.e. end and start matches the word range) 
                if (wordRange && !wordRange.isEmpty && wordRange.isEqual(vscode.window.activeTextEditor.selection)) {
                    let word = document.getText(wordRange).trim();
                    if (word.length > 0) {
                        commands.push({ command: 'editor.action.rename', title: 'Rename Symbol' });
                    }
                }
            }

            if (!range.isEmpty) {
                let word = document.getText(range).trim();
                if (word.trim().length > 0) {
                    commands.push({ command: 'python.refactorExtractVariable', title: 'Extract Variable', arguments: [range] });
                    commands.push({ command: 'python.refactorExtractMethod', title: 'Extract Method', arguments: [range] });
                }
            }
            resolve(commands);
        });
开发者ID:walkoncross,项目名称:pythonVSCode,代码行数:29,代码来源:codeActionProvider.ts

示例5: provideCompletionItems

	public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Promise<CompletionItem[]> {

		let wordToComplete = '';
		let range = document.getWordRangeAtPosition(position);
		if (range) {
			wordToComplete = document.getText(new Range(range.start, position));
		}

		let req = createRequest<protocol.AutoCompleteRequest>(document, position);
		req.WordToComplete = wordToComplete;
		req.WantDocumentationForEveryCompletionResult = true;
		req.WantKind = true;

		return serverUtils.autoComplete(this._server, req).then(values => {

			if (!values) {
				return;
			}

			let result: CompletionItem[] = [];
			let completions: { [c: string]: CompletionItem[] } = Object.create(null);

			// transform AutoCompleteResponse to CompletionItem and
			// group by code snippet
			for (let value of values) {
				let completion = new CompletionItem(value.CompletionText.replace(/\(|\)|<|>/g, ''));
				completion.detail = value.DisplayText;
				completion.documentation = plain(value.Description);
				completion.kind = _kinds[value.Kind] || CompletionItemKind.Property;

				let array = completions[completion.label];
				if (!array) {
					completions[completion.label] = [completion];
				} else {
					array.push(completion);
				}
			}

			// per suggestion group, select on and indicate overloads
			for (let key in completions) {

				let suggestion = completions[key][0],
					overloadCount = completions[key].length - 1;

				if (overloadCount === 0) {
					// remove non overloaded items
					delete completions[key];

				} else {
					// indicate that there is more
					suggestion.detail = `${suggestion.detail} (+ ${overloadCount} overload(s))`;
				}
				result.push(suggestion);
			}

			return result;
		});
	}
开发者ID:Jeffiy,项目名称:omnisharp-vscode,代码行数:58,代码来源:completionItemProvider.ts

示例6: provideCompletionItems

    public async provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Promise<CompletionItem[]> {
        if (!VariableUtility.isPartialRequestVariableReference(document, position)) {
            return [];
        }


        const wordRange = document.getWordRangeAtPosition(position, /\{\{(\w+)\.(.*?)?\}\}/);
        let lineRange = document.lineAt(position);

        let fullPath = this.getRequestVariableCompletionPath(wordRange, lineRange, position);

        if (!fullPath) {
            return undefined;
        }

        const match = fullPath.match(/(\w+)\.(.*?)?/);
        if (!match || !this.checkIfRequestVariableDefined(document, match[1])) {
            return [];
        }

        if (firstPartRegex.test(fullPath)) {
            return [
                new CompletionItem("request", CompletionItemKind.Field),
                new CompletionItem("response", CompletionItemKind.Field),
            ];
        } else if (secondPartRegex.test(fullPath)) {
            return [
                new CompletionItem("body", CompletionItemKind.Field),
                new CompletionItem("headers", CompletionItemKind.Field),
            ];
        }

        const requestVariables = await RequestVariableProvider.Instance.getAll(document);
        for (const { name, value } of requestVariables) {
            // Only add completion items for headers
            const regex = new RegExp(`^(${name})\.(?:request|response)\.headers\.$`);
            if (regex.test(fullPath)) {
                // Remove last dot if present
                fullPath = fullPath.replace(/\.$/, '');

                const result = RequestVariableCacheValueProcessor.resolveRequestVariable(value as RequestVariableCacheValue, fullPath);
                if (result.state === ResolveState.Warning && result.message === ResolveWarningMessage.MissingHeaderName) {
                    const {value} = result;
                    return Object.keys(value).map(p => {
                        let item = new CompletionItem(p);
                        item.detail = `HTTP ${ElementType[ElementType.RequestCustomVariable]}`;
                        item.documentation = new MarkdownString(`Value: \`${value[p]}\``);
                        item.insertText = p;
                        item.kind = CompletionItemKind.Field;
                        return item;
                    });
                }
            }
        }

        return;
    }
开发者ID:Huachao,项目名称:vscode-restclient,代码行数:57,代码来源:requestVariableCompletionItemProvider.ts

示例7: Range

 .map((selection): Range => {
   // 为空选择集自动选择光标所在位置的单词
   if (selection.isEmpty) {
     let position = selection.active;
     return doc.getWordRangeAtPosition(position);
   } else {
     return new Range(selection.start, selection.end);
   }
 })
开发者ID:Maroon1,项目名称:px2rem,代码行数:9,代码来源:util.ts

示例8: previousTokenPosition

	private previousTokenPosition(document: TextDocument, position: Position): Position {
		while (position.character > 0) {
			let word = document.getWordRangeAtPosition(position);
			if (word) {
				return word.start;
			}
			position = position.translate(0, -1);
		}
		return null;
	}
开发者ID:YanLinAung,项目名称:vscode-go,代码行数:10,代码来源:goSignature.ts

示例9: isVariableDefinition

    public static isVariableDefinition(document: TextDocument, position: Position): boolean {
        let wordRange = document.getWordRangeAtPosition(position);
        let lineRange = document.lineAt(position);
        if (!wordRange
            || wordRange.start.character < 1
            || lineRange.text[wordRange.start.character - 1] !== '@') {
            // not a custom variable definition syntax
            return false;
        }

        return true;
    }
开发者ID:Huachao,项目名称:vscode-restclient,代码行数:12,代码来源:variableUtility.ts

示例10: provideDefinition

    public async provideDefinition(document: TextDocument, position: Position, token: CancellationToken): Promise<Definition> {
        if (!VariableUtility.isVariableReference(document, position)) {
            return;
        }

        let documentLines = document.getText().split(Constants.LineSplitterRegex);

        let wordRange = document.getWordRangeAtPosition(position);
        let selectedVariableName = document.getText(wordRange);

        let locations = VariableUtility.getDefinitionRanges(documentLines, selectedVariableName);
        return locations.map(location => new Location(document.uri, location));
    }
开发者ID:Huachao,项目名称:vscode-restclient,代码行数:13,代码来源:customVariableDefinitionProvider.ts


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