本文整理匯總了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 [];
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例10:
/**
* Returns true only if the stream is at the end of the file.
* @returns {Boolean}
*/
eof() {
return this.pos.isAfterOrEqual(this._eof);
}