当前位置: 首页>>代码示例>>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;未经允许,请勿转载。