reuse p2c converter from language client library (#564)
Signed-off-by: Yan Zhang <yanzh@microsoft.com>
This commit is contained in:
Родитель
4cf30a21ae
Коммит
1769b9a9b4
|
@ -740,8 +740,7 @@
|
|||
},
|
||||
"kind-of": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
|
||||
"resolved": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -4821,8 +4820,7 @@
|
|||
},
|
||||
"kind-of": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
|
||||
"resolved": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -6039,6 +6037,22 @@
|
|||
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-5.0.1.tgz",
|
||||
"integrity": "sha512-JvONPptw3GAQGXlVV2utDcHx0BiY34FupW/kI6mZ5x06ER5DdPG/tXWMVHjTNULF5uKPOUUD0SaXg5QaubJL0A=="
|
||||
},
|
||||
"vscode-languageclient": {
|
||||
"version": "6.1.3",
|
||||
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-6.1.3.tgz",
|
||||
"integrity": "sha512-YciJxk08iU5LmWu7j5dUt9/1OLjokKET6rME3cI4BRpiF6HZlusm2ZwPt0MYJ0lV5y43sZsQHhyon2xBg4ZJVA==",
|
||||
"requires": {
|
||||
"semver": "^6.3.0",
|
||||
"vscode-languageserver-protocol": "^3.15.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"semver": {
|
||||
"version": "6.3.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
||||
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"vscode-languageserver-protocol": {
|
||||
"version": "3.15.3",
|
||||
"resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.3.tgz",
|
||||
|
|
|
@ -594,6 +594,7 @@
|
|||
"md5": "^2.2.1",
|
||||
"minimatch": "^3.0.4",
|
||||
"vscode-extension-telemetry-wrapper": "^0.8.0",
|
||||
"vscode-languageclient": "^6.1.3",
|
||||
"vscode-languageserver-protocol": "^3.15.3",
|
||||
"which": "^1.3.1",
|
||||
"xml-zero-lexer": "^2.1.0",
|
||||
|
|
Двоичные данные
resources/IndexData/index/_r.cfe
Двоичные данные
resources/IndexData/index/_r.cfe
Двоичный файл не отображается.
Двоичные данные
resources/IndexData/index/_r.cfs
Двоичные данные
resources/IndexData/index/_r.cfs
Двоичный файл не отображается.
Двоичные данные
resources/IndexData/index/_r.si
Двоичные данные
resources/IndexData/index/_r.si
Двоичный файл не отображается.
Двоичные данные
resources/IndexData/index/segments_d
Двоичные данные
resources/IndexData/index/segments_d
Двоичный файл не отображается.
|
@ -1,9 +1,12 @@
|
|||
import { commands, Position, Range, Selection, TextEdit, TextEditor, Uri, window, workspace, WorkspaceEdit } from "vscode";
|
||||
import { commands, Position, Selection, TextEdit, TextEditor, window, workspace, WorkspaceEdit } from "vscode";
|
||||
import * as protocolConverter from "vscode-languageclient/lib/protocolConverter";
|
||||
import * as ls from "vscode-languageserver-protocol";
|
||||
|
||||
const p2c: protocolConverter.Converter = protocolConverter.createConverter();
|
||||
|
||||
// tslint:disable-next-line: export-name
|
||||
export async function applyWorkspaceEdit(edit: ls.WorkspaceEdit): Promise<void> {
|
||||
const workspaceEdit: WorkspaceEdit = asWorkspaceEdit(edit);
|
||||
const workspaceEdit: WorkspaceEdit = p2c.asWorkspaceEdit(edit);
|
||||
if (workspaceEdit) {
|
||||
await workspace.applyEdit(workspaceEdit);
|
||||
// By executing the range formatting command to correct the indention according to the VS Code editor settings.
|
||||
|
@ -43,73 +46,3 @@ async function executeRangeFormat(editor: TextEditor, startPosition: Position, l
|
|||
editor.selection = new Selection(startPosition, endPosition);
|
||||
await commands.executeCommand("editor.action.formatSelection");
|
||||
}
|
||||
|
||||
function asPosition(value: undefined | null): undefined;
|
||||
function asPosition(value: ls.Position): Position;
|
||||
function asPosition(value: ls.Position | undefined | null): Position | undefined;
|
||||
function asPosition(value: ls.Position | undefined | null): Position | undefined {
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
return new Position(value.line, value.character);
|
||||
}
|
||||
|
||||
function asRange(value: undefined | null): undefined;
|
||||
function asRange(value: ls.Range): Range;
|
||||
function asRange(value: ls.Range | undefined | null): Range | undefined;
|
||||
function asRange(value: ls.Range | undefined | null): Range | undefined {
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
return new Range(asPosition(value.start), asPosition(value.end));
|
||||
}
|
||||
|
||||
function asTextEdit(edit: undefined | null): undefined;
|
||||
function asTextEdit(edit: ls.TextEdit): TextEdit;
|
||||
function asTextEdit(edit: ls.TextEdit | undefined | null): TextEdit | undefined {
|
||||
if (!edit) {
|
||||
return undefined;
|
||||
}
|
||||
return new TextEdit(asRange(edit.range), edit.newText);
|
||||
}
|
||||
|
||||
function asTextEdits(items: ls.TextEdit[]): TextEdit[];
|
||||
function asTextEdits(items: undefined | null): undefined;
|
||||
function asTextEdits(items: ls.TextEdit[] | undefined | null): TextEdit[] | undefined;
|
||||
function asTextEdits(items: ls.TextEdit[] | undefined | null): TextEdit[] | undefined {
|
||||
if (!items) {
|
||||
return undefined;
|
||||
}
|
||||
return items.map(asTextEdit);
|
||||
}
|
||||
|
||||
function asWorkspaceEdit(item: ls.WorkspaceEdit): WorkspaceEdit;
|
||||
function asWorkspaceEdit(item: undefined | null): undefined;
|
||||
function asWorkspaceEdit(item: ls.WorkspaceEdit | undefined | null): WorkspaceEdit | undefined;
|
||||
function asWorkspaceEdit(item: ls.WorkspaceEdit | undefined | null): WorkspaceEdit | undefined {
|
||||
if (!item) {
|
||||
return undefined;
|
||||
}
|
||||
const result: WorkspaceEdit = new WorkspaceEdit();
|
||||
if (item.documentChanges) {
|
||||
item.documentChanges.forEach((change: ls.TextDocumentEdit | ls.CreateFile | ls.RenameFile | ls.DeleteFile) => {
|
||||
if (ls.CreateFile.is(change)) {
|
||||
result.createFile(Uri.parse(change.uri), change.options);
|
||||
} else if (ls.RenameFile.is(change)) {
|
||||
result.renameFile(Uri.parse(change.oldUri), Uri.parse(change.newUri), change.options);
|
||||
} else if (ls.DeleteFile.is(change)) {
|
||||
result.deleteFile(Uri.parse(change.uri), change.options);
|
||||
} else if (ls.TextDocumentEdit.is(change)) {
|
||||
result.set(Uri.parse(change.textDocument.uri), asTextEdits(change.edits));
|
||||
} else {
|
||||
// to handle Unknown workspace edit change error
|
||||
}
|
||||
});
|
||||
} else if (item.changes) {
|
||||
Object.keys(item.changes).forEach((key: string) => {
|
||||
// tslint:disable-next-line: no-non-null-assertion
|
||||
result.set(Uri.parse(key), asTextEdits(item.changes![key]));
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче