diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-03 13:54:43 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-03 13:54:43 +0000 |
commit | 5443205fdd9f4886cc88ad15c3a6061ffa90ca19 (patch) | |
tree | 380084b87b5b6b9174f0a8eb6a7652942e862e23 /editors | |
parent | aea2183799e7975d3d9000cec9bb9a3c001a3d4e (diff) | |
parent | 7d9e02e5a201fe997f98b6908daadd820d4a6593 (diff) |
Merge #415
415: use LSP file system operations r=matklad a=vemoo
implements #131
I've replaced `source_file_edits` and `file_system_edits` with `workspace_edit` because [`WorkspacEdit`](https://docs.rs/languageserver-types/0.53.1/languageserver_types/struct.WorkspaceEdit.html) can represent both.
I only use `document_changes` because `changes` cannot represent file system operations.
But if the client doesn't have the `workspace.workspaceEdit.resourceOperations` capability `WorkspaceEdit` cannot replace the current `FileSystemEdit`. Can we assume that the client will support it?
I also adapted the extension code to make use of the new response type, but only for vscode, i don't know if changes have to be made for the emacs part.
Co-authored-by: Bernardo <[email protected]>
Diffstat (limited to 'editors')
-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 | } |