aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/apply_source_change.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/apply_source_change.ts')
-rw-r--r--editors/code/src/commands/apply_source_change.ts54
1 files changed, 0 insertions, 54 deletions
diff --git a/editors/code/src/commands/apply_source_change.ts b/editors/code/src/commands/apply_source_change.ts
deleted file mode 100644
index 8167398b1..000000000
--- a/editors/code/src/commands/apply_source_change.ts
+++ /dev/null
@@ -1,54 +0,0 @@
1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient';
3
4import { Server } from '../server';
5
6export interface SourceChange {
7 label: string;
8 workspaceEdit: lc.WorkspaceEdit;
9 cursorPosition?: lc.TextDocumentPositionParams;
10}
11
12export async function handle(change: SourceChange) {
13 const wsEdit = Server.client.protocol2CodeConverter.asWorkspaceEdit(
14 change.workspaceEdit,
15 );
16 let created;
17 let moved;
18 if (change.workspaceEdit.documentChanges) {
19 for (const docChange of change.workspaceEdit.documentChanges) {
20 if (lc.CreateFile.is(docChange)) {
21 created = docChange.uri;
22 } else if (lc.RenameFile.is(docChange)) {
23 moved = docChange.newUri;
24 }
25 }
26 }
27 const toOpen = created || moved;
28 const toReveal = change.cursorPosition;
29 await vscode.workspace.applyEdit(wsEdit);
30 if (toOpen) {
31 const toOpenUri = vscode.Uri.parse(toOpen);
32 const doc = await vscode.workspace.openTextDocument(toOpenUri);
33 await vscode.window.showTextDocument(doc);
34 } else if (toReveal) {
35 const uri = Server.client.protocol2CodeConverter.asUri(
36 toReveal.textDocument.uri,
37 );
38 const position = Server.client.protocol2CodeConverter.asPosition(
39 toReveal.position,
40 );
41 const editor = vscode.window.activeTextEditor;
42 if (!editor || editor.document.uri.toString() !== uri.toString()) {
43 return;
44 }
45 if (!editor.selection.isEmpty) {
46 return;
47 }
48 editor.selection = new vscode.Selection(position, position);
49 editor.revealRange(
50 new vscode.Range(position, position),
51 vscode.TextEditorRevealType.Default,
52 );
53 }
54}