aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorBernardo <[email protected]>2019-01-03 13:14:36 +0000
committerBernardo <[email protected]>2019-01-03 13:20:15 +0000
commit3ab328b49a5a4fc47d81ea390b1d42f67ca3c018 (patch)
tree41cc8ced298359bdfc834c991772237943ef2ddf /editors
parentaea2183799e7975d3d9000cec9bb9a3c001a3d4e (diff)
use lsp WorkspaceEdit instead of custom source_file_edits and file_system_edits
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/commands/apply_source_change.ts43
1 files changed, 10 insertions, 33 deletions
diff --git a/editors/code/src/commands/apply_source_change.ts b/editors/code/src/commands/apply_source_change.ts
index cf921e3ac..10dbf72c0 100644
--- a/editors/code/src/commands/apply_source_change.ts
+++ b/editors/code/src/commands/apply_source_change.ts
@@ -3,46 +3,23 @@ import * as lc from 'vscode-languageclient';
3 3
4import { Server } from '../server'; 4import { Server } from '../server';
5 5
6interface FileSystemEdit {
7 type: string;
8 uri?: string;
9 src?: string;
10 dst?: string;
11}
12
13export interface SourceChange { 6export interface SourceChange {
14 label: string; 7 label: string;
15 sourceFileEdits: lc.TextDocumentEdit[]; 8 workspaceEdit: lc.WorkspaceEdit;
16 fileSystemEdits: FileSystemEdit[];
17 cursorPosition?: lc.TextDocumentPositionParams; 9 cursorPosition?: lc.TextDocumentPositionParams;
18} 10}
19 11
20export async function handle(change: SourceChange) { 12export async function handle(change: SourceChange) {
21 const wsEdit = new vscode.WorkspaceEdit(); 13 const wsEdit = Server.client.protocol2CodeConverter.asWorkspaceEdit(change.workspaceEdit);
22 for (const sourceEdit of change.sourceFileEdits) {
23 const uri = Server.client.protocol2CodeConverter.asUri(
24 sourceEdit.textDocument.uri
25 );
26 const edits = Server.client.protocol2CodeConverter.asTextEdits(
27 sourceEdit.edits
28 );
29 wsEdit.set(uri, edits);
30 }
31 let created; 14 let created;
32 let moved; 15 let moved;
33 for (const fsEdit of change.fileSystemEdits) { 16 if (change.workspaceEdit.documentChanges) {
34 switch (fsEdit.type) { 17 for (const docChange of change.workspaceEdit.documentChanges) {
35 case 'createFile': 18 if (lc.CreateFile.is(docChange)) {
36 const uri = vscode.Uri.parse(fsEdit.uri!); 19 created = docChange.uri;
37 wsEdit.createFile(uri); 20 } else if (lc.RenameFile.is(docChange)) {
38 created = uri; 21 moved = docChange.newUri;
39 break; 22 }
40 case 'moveFile':
41 const src = vscode.Uri.parse(fsEdit.src!);
42 const dst = vscode.Uri.parse(fsEdit.dst!);
43 wsEdit.renameFile(src, dst);
44 moved = dst;
45 break;
46 } 23 }
47 } 24 }
48 const toOpen = created || moved; 25 const toOpen = created || moved;
@@ -65,6 +42,6 @@ export async function handle(change: SourceChange) {
65 if (!editor.selection.isEmpty) { 42 if (!editor.selection.isEmpty) {
66 return; 43 return;
67 } 44 }
68 editor!.selection = new vscode.Selection(position, position); 45 editor.selection = new vscode.Selection(position, position);
69 } 46 }
70} 47}