當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript vscode.Position類代碼示例

本文整理匯總了TypeScript中vscode.Position的典型用法代碼示例。如果您正苦於以下問題:TypeScript Position類的具體用法?TypeScript Position怎麽用?TypeScript Position使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Position類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: provideEdits

    provideEdits(document: TextDocument, position: Position, ch: string, options: FormattingOptions, line: TextLine): TextEdit[] {
        // We can have else for the following blocks:
        // if:
        // elif x:
        // for x in y:
        // while x:

        // We need to find a block statement that is less than or equal to this statement block (but not greater)
        for (let lineNumber = position.line - 1; lineNumber >= 0; lineNumber--) {
            const prevLine = document.lineAt(lineNumber);
            const prevLineText = prevLine.text;

            // Oops, we've reached a boundary (like the function or class definition)
            // Get out of here
            if (this.boundaryRegExps.some(value => value.test(prevLineText))) {
                return [];
            }

            const blockRegEx = this.previousBlockRegExps.find(value => value.test(prevLineText));
            if (!blockRegEx) {
                continue;
            }

            const startOfBlockInLine = prevLine.firstNonWhitespaceCharacterIndex;
            if (startOfBlockInLine > line.firstNonWhitespaceCharacterIndex) {
                continue;
            }

            const startPosition = new Position(position.line, 0);
            const endPosition = new Position(position.line, line.firstNonWhitespaceCharacterIndex - startOfBlockInLine);

            if (startPosition.isEqual(endPosition)) {
                // current block cannot be at the same level as a preivous block
                continue;
            }
            if (options.insertSpaces) {
                return [
                    TextEdit.delete(new Range(startPosition, endPosition))
                ];
            }
            else {
                // Delete everything before the block and insert the same characters we have in the previous block
                const prefixOfPreviousBlock = prevLineText.substring(0, startOfBlockInLine);

                const startDeletePosition = new Position(position.line, 0);
                const endDeletePosition = new Position(position.line, line.firstNonWhitespaceCharacterIndex);

                return [
                    TextEdit.delete(new Range(startDeletePosition, endDeletePosition)),
                    TextEdit.insert(startDeletePosition, prefixOfPreviousBlock)
                ];
            }
        }

        return [];
    }
開發者ID:walkoncross,項目名稱:pythonVSCode,代碼行數:56,代碼來源:codeBlockFormatProvider.ts

示例2: apply

    apply(from: Position, option: {preferedCharacter?: number} = {}): Position {
        if (! this.isCharacterUpdated && option.preferedCharacter !== undefined) {
            from = from.with(undefined, option.preferedCharacter);
        }

        return super.apply(from);
    }
開發者ID:Alcan-Phoenix,項目名稱:amVim-for-VSCode,代碼行數:7,代碼來源:Character.ts

示例3: provideCompletionItems

 async provideCompletionItems(document: TextDocument, position: Position):
         Promise<CompletionItem[]> {
     // TODO(gabriel): use LeanInputAbbreviator.active() instead
     if (!isInputCompletion(document, position)) {
         const message = await this.server.complete(document.fileName, position.line + 1, position.character);
         const completions: CompletionItem[] = [];
         if (message.completions) {
             for (const completion of message.completions) {
                 const item = new CompletionItem(completion.text, CompletionItemKind.Function);
                 item.range = new Range(position.translate(0, -message.prefix.length), position);
                 if (completion.tactic_params) {
                     item.detail = completion.tactic_params.join(' ');
                 } else {
                     item.detail = completion.type;
                 }
                 item.documentation = new MarkdownString(completion.doc);
                 completions.push(item);
             }
         }
         for (const kw of keywords) {
             completions.push(new CompletionItem(kw, CompletionItemKind.Keyword));
         }
         return completions;
     } else {
         return null;
     }
 }
開發者ID:bryangingechen,項目名稱:vscode-lean,代碼行數:27,代碼來源:completion.ts

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

示例5: syncWindows

    public syncWindows() {
        let editor = window.activeTextEditor;
        if (!editor) {
            return;
        }

        let doc = editor.document;

        let editors: TextEditor[] = window.visibleTextEditors;
        var i = 0;
        var previousEditorPos = 0;
        let previousPos: Position;
    
        for (var theEditor of editors) {
            console.log(theEditor.document.positionAt);

            if (theEditor.viewColumn != ViewColumn.One) {
                theEditor.revealRange(new Range(previousPos, previousPos.translate(theEditor.document.lineCount)));
            } else {
                previousPos = theEditor.selection.active;
            }
        }
    }
開發者ID:Xography,項目名稱:vscode-scrollsync,代碼行數:23,代碼來源:extension.ts

示例6: apply

    apply(from: Position): Position {
        from = super.apply(from);

        const activeTextEditor = window.activeTextEditor;

        if (! activeTextEditor || this.line === undefined) {
            return from;
        }

        const document = activeTextEditor.document;

        let line = this.line;
        line = Math.max(0, this.line);
        line = Math.min(document.lineCount, this.line);

        return from.with(line);
    }
開發者ID:Alcan-Phoenix,項目名稱:amVim-for-VSCode,代碼行數:17,代碼來源:Document.ts

示例7: prepForDocCompletion

	/**
	 * Prepare the area around the position for insertion of the jsdoc.
	 *
	 * Removes any the prefix and suffix of a possible jsdoc
	 */
	private prepForDocCompletion(editor: TextEditor, position: Position): Thenable<Position> {
		const line = editor.document.lineAt(position.line).text;
		const prefix = line.slice(0, position.character).match(/\/\**\s*$/);
		const suffix = line.slice(position.character).match(/^\s*\**\//);
		if (!prefix && !suffix) {
			// Nothing to remove
			return Promise.resolve(position);
		}

		const start = position.translate(0, prefix ? -prefix[0].length : 0);
		return editor.edit(
			edits => {
				edits.delete(new Range(start, position.translate(0, suffix ? suffix[0].length : 0)));
			}, {
				undoStopBefore: true,
				undoStopAfter: false
			}).then(() => start);
	}
開發者ID:yuit,項目名稱:vscode,代碼行數:23,代碼來源:jsDocCompletionProvider.ts

示例8: findEndRange

    protected findEndRange(document:TextDocument, anchor: Position): Range {
        let matchingCount = 0;
        let lineIndex = anchor.line;

        do {

            const lineText = document.lineAt(lineIndex).text;

            let characterIndex = lineIndex === anchor.line ? anchor.character : 0;

            while (characterIndex < lineText.length) {

                if (lineText[characterIndex] === this.openingCharacter) {
                    // Don't count opening character on anchor.
                    if (! anchor.isEqual(new Position(lineIndex, characterIndex))) {
                        matchingCount++;
                    }
                }
                else if (lineText[characterIndex] === this.closingCharacter) {
                    if (matchingCount === 0) {
                        return new Range(
                            lineIndex, characterIndex,
                            lineIndex, characterIndex + 1
                        );
                    }
                    else {
                        matchingCount--;
                    }
                }

                characterIndex++;

            }

            lineIndex++;

        } while (lineIndex < document.lineCount);

        return null;
    }
開發者ID:vavans,項目名稱:amVim-for-VSCode,代碼行數:40,代碼來源:Block.ts

示例9: next

	/**
	 * Returns the next character in the stream and advances it.
	 * Also returns NaN when no more characters are available.
	 * @returns {Number}
	 */
	next() {
		if (this.eof()) {
			return NaN;
		}

		const line = this.document.lineAt(this.pos.line).text;
		let code: number;
		if (this.pos.character < line.length) {
			code = line.charCodeAt(this.pos.character);
			this.pos = this.pos.translate(0, 1);
		} else {
			code = this._eol.charCodeAt(this.pos.character - line.length);
			this.pos = new Position(this.pos.line + 1, 0);
		}

		if (this.eof()) {
			// restrict pos to eof, if in case it got moved beyond eof
			this.pos = new Position(this._eof.line, this._eof.character);
		}

		return code;
	}
開發者ID:FabianLauer,項目名稱:vscode,代碼行數:27,代碼來源:bufferStream.ts

示例10:

	/**
	 * Returns true only if the stream is at the end of the file.
	 * @returns {Boolean}
	 */
	eof() {
		return this.pos.isAfterOrEqual(this._eof);
	}
開發者ID:FabianLauer,項目名稱:vscode,代碼行數:7,代碼來源:bufferStream.ts


注:本文中的vscode.Position類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。