本文整理汇总了TypeScript中vscode.TextEdit类的典型用法代码示例。如果您正苦于以下问题:TypeScript TextEdit类的具体用法?TypeScript TextEdit怎么用?TypeScript TextEdit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextEdit类的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(): TextEdit {
switch (this.action) {
case EditTypes.EDIT_INSERT:
return TextEdit.insert(this.start, this.text);
case EditTypes.EDIT_DELETE:
return TextEdit.delete(new Range(this.start, this.end));
case EditTypes.EDIT_REPLACE:
return TextEdit.replace(new Range(this.start, this.end), this.text);
}
}
开发者ID:oliverkofoed,项目名称:vscode-go,代码行数:10,代码来源:util.ts
示例3: constructor
constructor(
public position: Position,
public document: TextDocument,
entry: CompletionEntry,
enableDotCompletions: boolean,
enableCallCompletions: boolean
) {
super(entry.name);
this.sortText = entry.sortText;
this.kind = MyCompletionItem.convertKind(entry.kind);
this.position = position;
this.commitCharacters = MyCompletionItem.getCommitCharacters(enableDotCompletions, enableCallCompletions, entry.kind);
if (entry.replacementSpan) {
let span: protocol.TextSpan = entry.replacementSpan;
// The indexing for the range returned by the server uses 1-based indexing.
// We convert to 0-based indexing.
this.textEdit = TextEdit.replace(new Range(span.start.line - 1, span.start.offset - 1, span.end.line - 1, span.end.offset - 1), entry.name);
} else {
// Try getting longer, prefix based range for completions that span words
const wordRange = document.getWordRangeAtPosition(position);
const text = document.getText(new Range(position.line, Math.max(0, position.character - entry.name.length), position.line, position.character)).toLowerCase();
const entryName = entry.name.toLowerCase();
for (let i = entryName.length; i >= 0; --i) {
if (text.endsWith(entryName.substr(0, i)) && (!wordRange || wordRange.start.character > position.character - i)) {
this.range = new Range(position.line, Math.max(0, position.character - i), position.line, position.character);
break;
}
}
}
}
开发者ID:hungys,项目名称:vscode,代码行数:30,代码来源:completionItemProvider.ts
示例4: initCompletionProvider
function initCompletionProvider(): Disposable {
const regionCompletionRegExpr = /^(\s*)(\/(\*\s*(#\w*)?)?)?$/;
return languages.registerCompletionItemProvider(documentSelector, {
provideCompletionItems(doc, pos) {
let lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos));
let match = lineUntilPos.match(regionCompletionRegExpr);
if (match) {
let range = new Range(new Position(pos.line, match[1].length), pos);
let beginProposal = new CompletionItem('#region', CompletionItemKind.Snippet);
beginProposal.range = range; TextEdit.replace(range, '/* #region */');
beginProposal.insertText = new SnippetString('/* #region $1*/');
beginProposal.documentation = localize('folding.start', 'Folding Region Start');
beginProposal.filterText = match[2];
beginProposal.sortText = 'za';
let endProposal = new CompletionItem('#endregion', CompletionItemKind.Snippet);
endProposal.range = range;
endProposal.insertText = '/* #endregion */';
endProposal.documentation = localize('folding.end', 'Folding Region End');
endProposal.sortText = 'zb';
endProposal.filterText = match[2];
return [beginProposal, endProposal];
}
return null;
}
});
}
开发者ID:PKRoma,项目名称:vscode,代码行数:27,代码来源:cssMain.ts
示例5:
.then((result) => {
if (!result) {
return;
}
return [vscode.TextEdit.replace(result.range, result.css)];
});
开发者ID:mrmlnc,项目名称:vscode-postcss-sorting,代码行数:7,代码来源:extension.ts
示例6:
add: (suggestion: CompletionItem) => {
if (!proposed[suggestion.label]) {
proposed[suggestion.label] = true;
suggestion.textEdit = TextEdit.replace(overwriteRange, suggestion.insertText);
items.push(suggestion);
}
},
开发者ID:1Hgm,项目名称:vscode,代码行数:7,代码来源:jsonContributions.ts
示例7: getEditsForDeletingTralingSpaces
/**
* Returns the edits required to delete the trailings spaces from a document
*
* @param {vscode.TextDocument} document The document in which the trailing spaces should be found
* @returns {vscode.TextEdit[]} An array of edits required to delete the trailings spaces from the document
*/
public getEditsForDeletingTralingSpaces(document: vscode.TextDocument): vscode.TextEdit[] {
let ranges: vscode.Range[] = this.getRangesToDelete(document);
let edits: vscode.TextEdit[] = new Array<vscode.TextEdit>(ranges.length);
for (let i: number = ranges.length - 1; i >= 0; i--) {
edits[ranges.length - 1 - i] = vscode.TextEdit.delete(ranges[i]);
}
this.showStatusBarMessage(document, ranges.length);
return edits;
}
开发者ID:shardulm94,项目名称:vscode-trailingspaces,代码行数:15,代码来源:trailing-spaces.ts
示例8:
add: (suggestion: vscode.CompletionItem) => {
if (!proposed[suggestion.label]) {
proposed[suggestion.label] = true;
if (overwriteRange) {
suggestion.textEdit = vscode.TextEdit.replace(overwriteRange, suggestion.insertText);
}
items.push(suggestion);
}
},
开发者ID:claudiug,项目名称:code-d,代码行数:10,代码来源:json-contributions.ts
示例9: activate
export function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "sql Formatter" is now active!');
let sqlFormatter = new sqlFormatterClass();
vscode.languages.registerDocumentFormattingEditProvider('sql', {
provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
let data = sqlFormatter.formatter();
return [vscode.TextEdit.replace(new Range(data.start, data.end), data.text)];
}
});
}
开发者ID:donyang,项目名称:SqlFormatter-VSCode,代码行数:12,代码来源:extension.ts
示例10:
newIndents.forEach((indent, line) => {
let oldIndent = oldIndents[line];
let newIndent = ' '.repeat(indent);
if (oldIndent !== newIndent) {
edits.push(vscode.TextEdit.replace(
new vscode.Range(
new vscode.Position(line, 0),
new vscode.Position(line, oldIndent.length)
),
newIndent)
);
}
});
开发者ID:let-def,项目名称:vscode-ocaml,代码行数:13,代码来源:extension.ts
注:本文中的vscode.TextEdit类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论