當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。