本文整理汇总了TypeScript中vscode.TextEdit.replace方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextEdit.replace方法的具体用法?TypeScript TextEdit.replace怎么用?TypeScript TextEdit.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode.TextEdit
的用法示例。
在下文中一共展示了TextEdit.replace方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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(tsTextSpanToVsRange(span), 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;
}
}
}
}
示例2: 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;
}
});
}
示例3:
add: (suggestion: CompletionItem) => {
if (!proposed[suggestion.label]) {
proposed[suggestion.label] = true;
suggestion.textEdit = TextEdit.replace(overwriteRange, suggestion.insertText);
suggestion.filterText = filterText;
items.push(suggestion);
}
},
示例4:
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);
}
},
示例5: 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);
}
}
示例6: 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)];
}
});
}
示例7:
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)
);
}
});
示例8: _provideFormattingEdits
private _provideFormattingEdits(document: vsc.TextDocument, range: vsc.Range, options: vsc.FormattingOptions): vsc.TextEdit[] {
let splitNamespaces: boolean = vsc.workspace.getConfiguration(CFG_SECTION).get<boolean>(CFG_SPLIT_NAMESPACES, true);
let formatterOptions: IXmlFormatterOptions = {
preferSpaces: options.insertSpaces,
tabSize: options.tabSize,
splitNamespaces: splitNamespaces
};
let formatter = new XmlFormatter(formatterOptions);
let xml = formatter.format(document.getText(range));
return [ vsc.TextEdit.replace(range, xml) ];
}
示例9: provideFormattingEdits
private provideFormattingEdits(document: vscode.TextDocument, range: vscode.Range, options: vscode.FormattingOptions): vscode.TextEdit[] {
this.formatterOptions = {
tabSize: options.tabSize,
insertSpaces: options.insertSpaces
};
// format as html
let doc = lst.TextDocument.create(document.uri.fsPath, 'html', 1, document.getText());
let htmlTextEdit = service.format(doc, range, options);
// format as blade
let formatter = new BladeFormatter(this.formatterOptions);
let bladeText = formatter.format(htmlTextEdit[0].newText);
return [vscode.TextEdit.replace(range, bladeText)];
}
示例10: onSave
public onSave(e: vscode.TextDocumentWillSaveEvent) {
var { document } = e;
var docType: Array<string> = ['css', 'scss', 'javascript', 'html', 'json']
var global = path.join(__dirname, 'formatter.json');
var local = path.join(getRootPath(), '.vscode', 'formatter.json');
var onSave;
try {
onSave = require(local).onSave;
} catch (error) {
try {
onSave = require(global).onSave;
} catch (error) {
onSave = true;
}
}
if (!onSave) {
return;
}
if (docType.indexOf(document.languageId) == -1) {
return;
}
var start = new vscode.Position(0, 0);
var end = new vscode.Position(document.lineCount - 1, document.lineAt(document.lineCount - 1).text.length);
var range = new vscode.Range(start, end);
var result: vscode.TextEdit[] = [];
var content = document.getText(range);
var formatted = beatify(content, document.languageId);
if (formatted) {
var start = new vscode.Position(0, 0);
var end = new vscode.Position(document.lineCount - 1, document.lineAt(document.lineCount - 1).text.length);
range = new vscode.Range(start, end);
var edit = vscode.TextEdit.replace(range, formatted);
e.waitUntil(Promise.resolve([edit]));
}
}