diff options
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r-- | editors/code/src/commands/apply_source_change.ts | 43 |
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 | ||
4 | import { Server } from '../server'; | 4 | import { Server } from '../server'; |
5 | 5 | ||
6 | interface FileSystemEdit { | ||
7 | type: string; | ||
8 | uri?: string; | ||
9 | src?: string; | ||
10 | dst?: string; | ||
11 | } | ||
12 | |||
13 | export interface SourceChange { | 6 | export 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 | ||
20 | export async function handle(change: SourceChange) { | 12 | export 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 | } |