本文整理匯總了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 [];
}
示例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);
}
}
示例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;
}
}
}
}
示例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;
}
});
}
示例5:
.then((result) => {
if (!result) {
return;
}
return [vscode.TextEdit.replace(result.range, result.css)];
});
示例6:
add: (suggestion: CompletionItem) => {
if (!proposed[suggestion.label]) {
proposed[suggestion.label] = true;
suggestion.textEdit = TextEdit.replace(overwriteRange, suggestion.insertText);
items.push(suggestion);
}
},
示例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;
}
示例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);
}
},
示例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)];
}
});
}
示例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)
);
}
});