本文整理汇总了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;未经允许,请勿转载。 |
请发表评论