本文整理匯總了TypeScript中vscode.WorkspaceEdit.set方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript WorkspaceEdit.set方法的具體用法?TypeScript WorkspaceEdit.set怎麽用?TypeScript WorkspaceEdit.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vscode.WorkspaceEdit
的用法示例。
在下文中一共展示了WorkspaceEdit.set方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: onCodeAction
private async onCodeAction(source: Source, workspaceEdit: WorkspaceEdit): Promise<boolean> {
const success = workspace.applyEdit(workspaceEdit);
if (!success) {
return false;
}
let firstEdit: TextEdit | undefined = undefined;
for (const [uri, edits] of workspaceEdit.entries()) {
if (uri.fsPath === source.uri.fsPath) {
firstEdit = edits[0];
break;
}
}
if (!firstEdit) {
return true;
}
const newLines = firstEdit.newText.match(/\n/g);
const editedRange = new Range(
firstEdit.range.start.line, 0,
firstEdit.range.end.line + 1 + (newLines ? newLines.length : 0), 0);
// TODO: Workaround for https://github.com/Microsoft/TypeScript/issues/12249
// apply formatting to the source range until TS returns formatted results
const edits = (await commands.executeCommand('vscode.executeFormatRangeProvider', source.uri, editedRange, source.formattingOptions || {})) as TextEdit[];
if (!edits || !edits.length) {
return false;
}
const formattingEdit = new WorkspaceEdit();
formattingEdit.set(source.uri, edits);
return workspace.applyEdit(formattingEdit);
}
示例2: setEditFactory
private setEditFactory(uri: Uri, coords, content): WorkspaceEdit {
var workspaceEdit = new WorkspaceEdit();
let edit = new TextEdit(coords, content);
workspaceEdit.set(uri, [edit]);
return workspaceEdit;
}
示例3: WorkspaceEdit
return commands.executeCommand('vscode.executeFormatRangeProvider', source.uri, editedRange, source.formattingOptions || {}).then((edits: TextEdit[]) => {
if (!edits || !edits.length) {
return false;
}
const workspaceEdit = new WorkspaceEdit();
workspaceEdit.set(source.uri, edits);
return workspace.applyEdit(workspaceEdit);
});
示例4: WorkspaceEdit
return this._server.makeRequest<V2.RunCodeActionResponse>(V2.RunCodeAction, req).then(response => {
if (response && Array.isArray(response.Changes)) {
let edit = new WorkspaceEdit();
for (let change of response.Changes) {
let uri = Uri.file(change.FileName);
let edits: TextEdit[] = [];
for (let textChange of change.Changes) {
edits.push(TextEdit.replace(toRange2(textChange), textChange.NewText));
}
edit.set(uri, edits);
}
return workspace.applyEdit(edit);
}
}, (error) => {
示例5: async
return serverUtils.runCodeAction(this._server, req).then(response => {
if (response && Array.isArray(response.Changes)) {
let edit = new vscode.WorkspaceEdit();
let fileToOpen: Uri = null;
let renamedFiles: Uri[] = [];
for (let change of response.Changes) {
if (change.ModificationType == FileModificationType.Renamed)
{
// The file was renamed. Omnisharp has already persisted
// the right changes to disk. We don't need to try to
// apply text changes (and will skip this file if we see an edit)
renamedFiles.push(Uri.file(change.FileName));
}
}
for (let change of response.Changes) {
if (change.ModificationType == FileModificationType.Opened)
{
// The CodeAction requested that we open a file.
// Record that file name and keep processing CodeActions.
// If a CodeAction requests that we open multiple files
// we only open the last one (what would it mean to open multiple files?)
fileToOpen = vscode.Uri.file(change.FileName);
}
if (change.ModificationType == FileModificationType.Modified)
{
let uri = vscode.Uri.file(change.FileName);
if (renamedFiles.some(r => r == uri))
{
// This file got renamed. Omnisharp has already
// persisted the new file with any applicable changes.
continue;
}
let edits: vscode.TextEdit[] = [];
for (let textChange of change.Changes) {
edits.push(vscode.TextEdit.replace(toRange2(textChange), textChange.NewText));
}
edit.set(uri, edits);
}
}
let applyEditPromise = vscode.workspace.applyEdit(edit);
// Unfortunately, the textEditor.Close() API has been deprecated
// and replaced with a command that can only close the active editor.
// If files were renamed that weren't the active editor, their tabs will
// be left open and marked as "deleted" by VS Code
let next = applyEditPromise;
if (renamedFiles.some(r => r.fsPath == vscode.window.activeTextEditor.document.uri.fsPath))
{
next = applyEditPromise.then(_ =>
{
return vscode.commands.executeCommand("workbench.action.closeActiveEditor");
});
}
return fileToOpen != null
? next.then(_ =>
{
return vscode.commands.executeCommand("vscode.open", fileToOpen);
})
: next;
}
}, async (error) => {
示例6:
}).then(edits => {
let workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.set(textDocument.uri, edits);
return vscode.workspace.applyEdit(workspaceEdit);
}).then(() => {
示例7: activate
export function activate(context: vscode.ExtensionContext) {
let session = new OCamlMerlinSession();
let toVsPos = (pos) => {
return new vscode.Position(pos.line - 1, pos.col);
};
let fromVsPos = (pos: vscode.Position) => {
return { line: pos.line + 1, col: pos.character };
};
let toVsRange = (start, end) => {
return new vscode.Range(toVsPos(start), toVsPos(end));
};
context.subscriptions.push(
vscode.languages.setLanguageConfiguration('ocaml', {
indentationRules: {
increaseIndentPattern: /^\s*(type|let)\s[^=]*=\s*$|\b(do|begin|struct|sig)\s*$/,
decreaseIndentPattern: /\b(done|end)\s*$/,
}
})
);
context.subscriptions.push(session);
context.subscriptions.push(
vscode.languages.registerDocumentFormattingEditProvider(ocamlLang, {
provideDocumentFormattingEdits(document, options, token) {
return doOcpIndent(document.getText(), token);
}
})
);
context.subscriptions.push(
vscode.languages.registerDocumentRangeFormattingEditProvider(ocamlLang, {
provideDocumentRangeFormattingEdits(document, range, options, token) {
return doOcpIndent(document.getText(), token, range);
}
})
);
context.subscriptions.push(
vscode.languages.registerOnTypeFormattingEditProvider(ocamlLang, {
async provideOnTypeFormattingEdits(document, position, ch, options, token) {
let isEndAt = (word) => {
let wordRange = document.getWordRangeAtPosition(position);
return wordRange.end.isEqual(position) && document.getText(wordRange) === word;
};
if ((ch === 'd' && !isEndAt('end')) || (ch === 'e' && !isEndAt('done'))) {
return [];
}
return doOcpIndent(document.getText(), token);
}
}, ';', '|', ')', ']', '}', 'd', 'e')
);
context.subscriptions.push(
vscode.languages.registerCompletionItemProvider(ocamlLang, {
async provideCompletionItems(document, position, token) {
return new vscode.CompletionList(ocamlKeywords.map((keyword) => {
let completionItem = new vscode.CompletionItem(keyword);
completionItem.kind = vscode.CompletionItemKind.Keyword;
return completionItem;
}));
}
})
);
context.subscriptions.push(
vscode.languages.registerCompletionItemProvider(ocamlLang, {
async provideCompletionItems(document, position, token) {
let line = document.getText(new vscode.Range(
new vscode.Position(position.line, 0),
position
));
let prefix = /[A-Za-z_][A-Za-z_'0-9]*(?:\.[A-Za-z_][A-Za-z_'0-9]*)*\.?$/.exec(line)[0];
await session.syncBuffer(document.fileName, document.getText(), token);
if (token.isCancellationRequested) return null;
let [status, result] = await session.request(['complete', 'prefix', prefix, 'at', fromVsPos(position), 'with', 'doc']);
if (token.isCancellationRequested) return null;
if (status !== 'return') return;
return new vscode.CompletionList(result.entries.map(({name, kind, desc, info}) => {
let completionItem = new vscode.CompletionItem(name);
let toVsKind = (kind) => {
switch (kind.toLowerCase()) {
case "value": return vscode.CompletionItemKind.Value;
case "variant": return vscode.CompletionItemKind.Enum;
case "constructor": return vscode.CompletionItemKind.Constructor;
case "label": return vscode.CompletionItemKind.Field;
case "module": return vscode.CompletionItemKind.Module;
case "signature": return vscode.CompletionItemKind.Interface;
case "type": return vscode.CompletionItemKind.Class;
case "method": return vscode.CompletionItemKind.Function;
case "#": return vscode.CompletionItemKind.Method;
case "exn": return vscode.CompletionItemKind.Constructor;
case "class": return vscode.CompletionItemKind.Class;
}
//.........這裏部分代碼省略.........