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


TypeScript TextDocument.lineAt方法代碼示例

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


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

示例1: getCells

    public static getCells(document: TextDocument): Cell[] {
        const cells: Cell[] = [];
        for (let index = 0; index < document.lineCount; index++) {
            const line = document.lineAt(index);
            if (CellIdentifier.test(line.text)) {
                const results = CellIdentifier.exec(line.text);
                if (cells.length > 0) {
                    const previousCell = cells[cells.length - 1];
                    previousCell.range = new Range(previousCell.range.start, document.lineAt(index - 1).range.end);
                }
                cells.push({
                    range: line.range,
                    title: results.length > 1 ? results[2].trim() : ''
                });
            }

        }

        if (cells.length >= 1) {
            const line = document.lineAt(document.lineCount - 1);
            const previousCell = cells[cells.length - 1];
            previousCell.range = new Range(previousCell.range.start, line.range.end);
        }
        return cells;
    }
開發者ID:walkoncross,項目名稱:pythonVSCode,代碼行數:25,代碼來源:cellHelper.ts

示例2: getModifiedRange

export function getModifiedRange(textDocument: TextDocument, diff: LineChange): Range {
	if (diff.modifiedEndLineNumber === 0) {
		if (diff.modifiedStartLineNumber === 0) {
			return new Range(textDocument.lineAt(diff.modifiedStartLineNumber).range.end, textDocument.lineAt(diff.modifiedStartLineNumber).range.start);
		} else {
			return new Range(textDocument.lineAt(diff.modifiedStartLineNumber - 1).range.end, textDocument.lineAt(diff.modifiedStartLineNumber).range.start);
		}
	} else {
		return new Range(textDocument.lineAt(diff.modifiedStartLineNumber - 1).range.start, textDocument.lineAt(diff.modifiedEndLineNumber - 1).range.end);
	}
}
開發者ID:burhandodhy,項目名稱:azuredatastudio,代碼行數:11,代碼來源:staging.ts

示例3: findNextWord

	public static findNextWord(doc: TextDocument, pos: Position, wordCharacterClass: WordCharacters): IWord {

		let lineContent = doc.lineAt(pos.line).text;
		let wordType = WordType.NONE;
		let len = lineContent.length;

		for (let chIndex = pos.character; chIndex < len; chIndex++) {
			let chCode = lineContent.charCodeAt(chIndex);
			let chClass = (wordCharacterClass[chCode] || CharacterClass.REGULAR);

			if (chClass === CharacterClass.REGULAR) {
				if (wordType === WordType.SEPARATOR) {
					return this._createWord(lineContent, wordType, this._findStartOfWord(lineContent, wordCharacterClass, wordType, chIndex - 1), chIndex);
				}
				wordType = WordType.REGULAR;
			} else if (chClass === CharacterClass.WORD_SEPARATOR) {
				if (wordType === WordType.REGULAR) {
					return this._createWord(lineContent, wordType, this._findStartOfWord(lineContent, wordCharacterClass, wordType, chIndex - 1), chIndex);
				}
				wordType = WordType.SEPARATOR;
			} else if (chClass === CharacterClass.WHITESPACE) {
				if (wordType !== WordType.NONE) {
					return this._createWord(lineContent, wordType, this._findStartOfWord(lineContent, wordCharacterClass, wordType, chIndex - 1), chIndex);
				}
			}
		}

		if (wordType !== WordType.NONE) {
			return this._createWord(lineContent, wordType, this._findStartOfWord(lineContent, wordCharacterClass, wordType, len - 1), len);
		}

		return null;
	}
開發者ID:DanEEStar,項目名稱:vscode-vim,代碼行數:33,代碼來源:words.ts

示例4: parseInt

                outputLines.forEach(line => {
                    try {
                        if (line.trim().length === 0) {
                            return;
                        }
                        let lineNumber = parseInt(line.substring(0, line.indexOf(' ')));
                        let part = line.substring(line.indexOf(':') + 1).trim();
                        let code = part.substring(0, part.indexOf(':')).trim();
                        let message = part.substring(part.indexOf(':') + 1).trim();

                        let sourceLine = document.lineAt(lineNumber - 1).text;
                        let trmmedSourceLine = sourceLine.trim();
                        let sourceStart = sourceLine.indexOf(trmmedSourceLine);

                        diagnostics.push({
                            code: code,
                            message: message,
                            column: sourceStart,
                            line: lineNumber,
                            type: '',
                            provider: this.Id
                        });
                    }
                    catch (ex) {
                        // Hmm, need to handle this later
                    }
                });
開發者ID:,項目名稱:,代碼行數:27,代碼來源:

示例5: toDecorationRange

 public toDecorationRange(start: number, document: TextDocument): Range {
     const pos = document.positionAt(start);
     const line = pos.line;
     const documentLine = document.lineAt(line);
     const lineRange = documentLine.range;
     return new Range(lineRange.end.line, lineRange.end.character, lineRange.end.line, lineRange.end.character);
 }
開發者ID:kisstkondoros,項目名稱:codemetrics,代碼行數:7,代碼來源:MetricsUtil.ts

示例6: applyChanges

export function applyChanges(original: TextDocument, modified: TextDocument, diffs: LineChange[]): string {
	const result: string[] = [];
	let currentLine = 0;

	for (let diff of diffs) {
		const isInsertion = diff.originalEndLineNumber === 0;
		const isDeletion = diff.modifiedEndLineNumber === 0;

		result.push(original.getText(new Range(currentLine, 0, isInsertion ? diff.originalStartLineNumber : diff.originalStartLineNumber - 1, 0)));

		if (!isDeletion) {
			let fromLine = diff.modifiedStartLineNumber - 1;
			let fromCharacter = 0;

			if (isInsertion && diff.originalStartLineNumber === original.lineCount) {
				fromLine = original.lineCount - 1;
				fromCharacter = original.lineAt(fromLine).range.end.character;
			}

			result.push(modified.getText(new Range(fromLine, fromCharacter, diff.modifiedEndLineNumber, 0)));
		}

		currentLine = isInsertion ? diff.originalStartLineNumber : diff.originalEndLineNumber;
	}

	result.push(original.getText(new Range(currentLine, 0, original.lineCount, 0)));

	return result.join('');
}
開發者ID:m-khosravi,項目名稱:vscode,代碼行數:29,代碼來源:staging.ts

示例7: peek

	/**
	 * Returns the next character code in the stream without advancing it.
	 * Will return NaN at the end of the file.
	 * @returns {Number}
	 */
	peek() {
		if (this.eof()) {
			return NaN;
		}
		const line = this.document.lineAt(this.pos.line).text;
		return this.pos.character < line.length ? line.charCodeAt(this.pos.character) : this._eol.charCodeAt(this.pos.character - line.length);
	}
開發者ID:FabianLauer,項目名稱:vscode,代碼行數:12,代碼來源:bufferStream.ts

示例8: transform

export function transform(
	editorconfig: editorconfig.knownProps,
	textDocument: TextDocument
): TextEdit[] {
	const editorTrimsWhitespace = workspace
		.getConfiguration('files')
		.get('trimTrailingWhitespace', false);

	if (editorTrimsWhitespace) {
		if (editorconfig.trim_trailing_whitespace === false) {
			window.showWarningMessage([
				'The trimTrailingWhitespace workspace or user setting is',
				'overriding the EditorConfig setting for this file.'
			].join(' '));
		}
		return [];
	}

	if (!editorconfig.trim_trailing_whitespace) {
		return [];
	}

	const trimmingOperations: TextEdit[] = [];

	for (let i = 0; i < textDocument.lineCount; i++) {
		const edit = trimLineTrailingWhitespace(textDocument.lineAt(i));

		if (edit) {
			trimmingOperations.push(edit);
		}
	}

	return trimmingOperations;
}
開發者ID:rlugojr,項目名稱:editorconfig-vscode,代碼行數:34,代碼來源:trimTrailingWhitespace.ts

示例9: run

	public run(doc: TextDocument, pos: Position, state: MotionState): Position {
		let lineContent = doc.lineAt(pos.line).text;

		if (pos.character >= lineContent.length - 1) {
			// cursor at end of line
			return ((pos.line + 1 < doc.lineCount) ? new Position(pos.line + 1, 0) : pos);
		}

		let nextWord = Words.findNextWord(doc, pos, state.wordCharacterClass);

		if (!nextWord) {
			// return end of the line
			return Motions.EndOfLine.run(doc, pos, state);
		}

		if (nextWord.start <= pos.character && pos.character < nextWord.end) {
			// Sitting on a word
			let nextNextWord = Words.findNextWord(doc, new Position(pos.line, nextWord.end), state.wordCharacterClass);
			if (nextNextWord) {
				// return start of the next next word
				return new Position(pos.line, nextNextWord.start);
			} else {
				// return end of line
				return Motions.EndOfLine.run(doc, pos, state);
			}
		} else {
			// return start of the next word
			return new Position(pos.line, nextWord.start);
		}
	}
開發者ID:ydcoming,項目名稱:vscode-extension-samples,代碼行數:30,代碼來源:motions.ts

示例10:

			return this.client.execute('formatonkey', args, token).then((response): TextEdit[] => {
				let edits = response.body;
				let result: TextEdit[] = [];
				if (!edits) {
					return result;
				}
				for (let edit of edits) {
					let textEdit = this.codeEdit2SingleEditOperation(edit);
					let range = textEdit.range;
					// Work around for https://github.com/Microsoft/TypeScript/issues/6700.
					// Check if we have an edit at the beginning of the line which only removes white spaces and leaves
					// an empty line. Drop those edits
					if (range.start.character === 0 && range.start.line === range.end.line && textEdit.newText === '') {
						let lText = document.lineAt(range.start.line).text;
						// If the edit leaves something on the line keep the edit (note that the end character is exclusive).
						// Keep it also if it removes something else than whitespace
						if (lText.trim().length > 0 || lText.length > range.end.character) {
							result.push(textEdit);
						}
					} else {
						result.push(textEdit);
					}
				}
				return result;
			}, (err: any) => {
開發者ID:m-khosravi,項目名稱:vscode,代碼行數:25,代碼來源:formattingProvider.ts

示例11: walkBackwardsToBeginningOfCall

	private walkBackwardsToBeginningOfCall(document: TextDocument, position: Position): { openParen: Position, commas: Position[] } {
		let currentLine = document.lineAt(position.line).text.substring(0, position.character);
		let parenBalance = 0;
		let commas = [];
		for (let char = position.character; char >= 0; char--) {
			switch (currentLine[char]) {
				case '(':
					parenBalance--;
					if (parenBalance < 0) {
						return {
							openParen: new Position(position.line, char),
							commas: commas
						};
					}
					break;
				case ')':
					parenBalance++;
					break;
				case ',':
					if (parenBalance === 0) {
						commas.push(new Position(position.line, char));
					}
			}
		}
		return null;
	}
開發者ID:YanLinAung,項目名稱:vscode-go,代碼行數:26,代碼來源:goSignature.ts

示例12: fitIntoDocument

    // The official TextDocument.validatePosition is buggy (https://github.com/Microsoft/vscode/issues/5704).
    static fitIntoDocument(document: TextDocument, from: Position): Position {
        const lineCount = document.lineCount;

        let {line, character} = from;

        const maxLine = document.lineCount - 1;

        if (line < 0) {
            line = 0;
            character = 0;
        }
        else if (line > maxLine) {
            line = maxLine;
            character = Infinity;
        }

        const maxCharacter = document.lineAt(line).text.length;

        if (character < 0) {
            character = 0;
        }
        else if (character > maxCharacter) {
            character = maxCharacter;
        }

        return new Position(line, character);
    }
開發者ID:Alcan-Phoenix,項目名稱:amVim-for-VSCode,代碼行數:28,代碼來源:Position.ts

示例13: applyLineChanges

export function applyLineChanges(original: TextDocument, modified: TextDocument, diffs: LineChange[]): string {
	const result: string[] = [];
	let currentLine = 0;

	for (let diff of diffs) {
		const isInsertion = diff.originalEndLineNumber === 0;
		const isDeletion = diff.modifiedEndLineNumber === 0;

		result.push(original.getText(new Range(currentLine, 0, isInsertion ? diff.originalStartLineNumber : diff.originalStartLineNumber - 1, 0)));

		if (!isDeletion) {
			let fromLine = diff.modifiedStartLineNumber - 1;
			let fromCharacter = 0;

			// if this is an insertion at the very end of the document,
			// then we must start the next range after the last character of the
			// previous line, in order to take the correct eol
			if (isInsertion && diff.originalStartLineNumber === original.lineCount) {
				fromLine -= 1;
				fromCharacter = modified.lineAt(fromLine).range.end.character;
			}

			result.push(modified.getText(new Range(fromLine, fromCharacter, diff.modifiedEndLineNumber, 0)));
		}

		currentLine = isInsertion ? diff.originalStartLineNumber : diff.originalEndLineNumber;
	}

	result.push(original.getText(new Range(currentLine, 0, original.lineCount, 0)));

	return result.join('');
}
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:32,代碼來源:staging.ts

示例14: provideCompletionItems

	public provideCompletionItems(
		document: TextDocument,
		position: Position,
		_token: CancellationToken
	): CompletionItem[] {
		if (!this.client.apiVersion.has230Features()) {
			return [];
		}

		const file = this.client.normalizePath(document.uri);
		if (!file) {
			return [];
		}

		const line = document.lineAt(position.line).text;
		const prefix = line.slice(0, position.character);
		const match = prefix.match(/^\s*\/\/+\s?(@[a-zA-Z\-]*)?$/);
		if (match) {
			return directives.map(directive => {
				const item = new CompletionItem(directive.value, CompletionItemKind.Snippet);
				item.detail = directive.description;
				item.range = new Range(position.line, Math.max(0, position.character - (match[1] ? match[1].length : 0)), position.line, position.character);
				return item;
			});
		}
		return [];
	}
開發者ID:AllureFer,項目名稱:vscode,代碼行數:27,代碼來源:directiveCommentCompletionProvider.ts

示例15: provideCompletionItems

  public provideCompletionItems(
    document: TextDocument, position: Position, token: CancellationToken): CompletionList
  {
    const line_text = document.lineAt(position).text

    return new CompletionList([])
  }
開發者ID:seL4,項目名稱:isabelle,代碼行數:7,代碼來源:completion.ts


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