aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r--editors/code/src/commands/apply_source_change.ts66
-rw-r--r--editors/code/src/commands/extend_selection.ts24
-rw-r--r--editors/code/src/commands/join_lines.ts16
-rw-r--r--editors/code/src/commands/matching_brace.ts28
-rw-r--r--editors/code/src/commands/parent_module.ts30
-rw-r--r--editors/code/src/commands/runnables.ts76
-rw-r--r--editors/code/src/commands/syntaxTree.ts20
7 files changed, 130 insertions, 130 deletions
diff --git a/editors/code/src/commands/apply_source_change.ts b/editors/code/src/commands/apply_source_change.ts
index dcbbb2b09..f011cbe12 100644
--- a/editors/code/src/commands/apply_source_change.ts
+++ b/editors/code/src/commands/apply_source_change.ts
@@ -1,5 +1,5 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient' 2import * as lc from 'vscode-languageclient';
3 3
4import { Server } from '../server'; 4import { Server } from '../server';
5 5
@@ -11,48 +11,48 @@ interface FileSystemEdit {
11} 11}
12 12
13export interface SourceChange { 13export interface SourceChange {
14 label: string, 14 label: string;
15 sourceFileEdits: lc.TextDocumentEdit[], 15 sourceFileEdits: lc.TextDocumentEdit[];
16 fileSystemEdits: FileSystemEdit[], 16 fileSystemEdits: FileSystemEdit[];
17 cursorPosition?: lc.TextDocumentPositionParams, 17 cursorPosition?: lc.TextDocumentPositionParams;
18} 18}
19 19
20export async function handle(change: SourceChange) { 20export async function handle(change: SourceChange) {
21 console.log(`applySOurceChange ${JSON.stringify(change)}`) 21 console.log(`applySOurceChange ${JSON.stringify(change)}`);
22 let wsEdit = new vscode.WorkspaceEdit() 22 const wsEdit = new vscode.WorkspaceEdit();
23 for (let sourceEdit of change.sourceFileEdits) { 23 for (const sourceEdit of change.sourceFileEdits) {
24 let uri = Server.client.protocol2CodeConverter.asUri(sourceEdit.textDocument.uri) 24 const uri = Server.client.protocol2CodeConverter.asUri(sourceEdit.textDocument.uri);
25 let edits = Server.client.protocol2CodeConverter.asTextEdits(sourceEdit.edits) 25 const edits = Server.client.protocol2CodeConverter.asTextEdits(sourceEdit.edits);
26 wsEdit.set(uri, edits) 26 wsEdit.set(uri, edits);
27 } 27 }
28 let created; 28 let created;
29 let moved; 29 let moved;
30 for (let fsEdit of change.fileSystemEdits) { 30 for (const fsEdit of change.fileSystemEdits) {
31 if (fsEdit.type == "createFile") { 31 if (fsEdit.type == 'createFile') {
32 let uri = vscode.Uri.parse(fsEdit.uri!) 32 const uri = vscode.Uri.parse(fsEdit.uri!);
33 wsEdit.createFile(uri) 33 wsEdit.createFile(uri);
34 created = uri 34 created = uri;
35 } else if (fsEdit.type == "moveFile") { 35 } else if (fsEdit.type == 'moveFile') {
36 let src = vscode.Uri.parse(fsEdit.src!) 36 const src = vscode.Uri.parse(fsEdit.src!);
37 let dst = vscode.Uri.parse(fsEdit.dst!) 37 const dst = vscode.Uri.parse(fsEdit.dst!);
38 wsEdit.renameFile(src, dst) 38 wsEdit.renameFile(src, dst);
39 moved = dst 39 moved = dst;
40 } else { 40 } else {
41 console.error(`unknown op: ${JSON.stringify(fsEdit)}`) 41 console.error(`unknown op: ${JSON.stringify(fsEdit)}`);
42 } 42 }
43 } 43 }
44 let toOpen = created || moved 44 const toOpen = created || moved;
45 let toReveal = change.cursorPosition 45 const toReveal = change.cursorPosition;
46 await vscode.workspace.applyEdit(wsEdit) 46 await vscode.workspace.applyEdit(wsEdit);
47 if (toOpen) { 47 if (toOpen) {
48 let doc = await vscode.workspace.openTextDocument(toOpen) 48 const doc = await vscode.workspace.openTextDocument(toOpen);
49 await vscode.window.showTextDocument(doc) 49 await vscode.window.showTextDocument(doc);
50 } else if (toReveal) { 50 } else if (toReveal) {
51 let uri = Server.client.protocol2CodeConverter.asUri(toReveal.textDocument.uri) 51 const uri = Server.client.protocol2CodeConverter.asUri(toReveal.textDocument.uri);
52 let position = Server.client.protocol2CodeConverter.asPosition(toReveal.position) 52 const position = Server.client.protocol2CodeConverter.asPosition(toReveal.position);
53 let editor = vscode.window.activeTextEditor; 53 const editor = vscode.window.activeTextEditor;
54 if (!editor || editor.document.uri.toString() != uri.toString()) return 54 if (!editor || editor.document.uri.toString() != uri.toString()) { return; }
55 if (!editor.selection.isEmpty) return 55 if (!editor.selection.isEmpty) { return; }
56 editor!.selection = new vscode.Selection(position, position) 56 editor!.selection = new vscode.Selection(position, position);
57 } 57 }
58} 58}
diff --git a/editors/code/src/commands/extend_selection.ts b/editors/code/src/commands/extend_selection.ts
index b90828ba9..b722ac172 100644
--- a/editors/code/src/commands/extend_selection.ts
+++ b/editors/code/src/commands/extend_selection.ts
@@ -1,6 +1,6 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2 2
3import { TextDocumentIdentifier, Range } from "vscode-languageclient"; 3import { Range, TextDocumentIdentifier } from 'vscode-languageclient';
4import { Server } from '../server'; 4import { Server } from '../server';
5 5
6interface ExtendSelectionParams { 6interface ExtendSelectionParams {
@@ -13,17 +13,17 @@ interface ExtendSelectionResult {
13} 13}
14 14
15export async function handle() { 15export async function handle() {
16 let editor = vscode.window.activeTextEditor 16 const editor = vscode.window.activeTextEditor;
17 if (editor == null || editor.document.languageId != "rust") return 17 if (editor == null || editor.document.languageId != 'rust') { return; }
18 let request: ExtendSelectionParams = { 18 const request: ExtendSelectionParams = {
19 textDocument: { uri: editor.document.uri.toString() },
20 selections: editor.selections.map((s) => { 19 selections: editor.selections.map((s) => {
21 return Server.client.code2ProtocolConverter.asRange(s) 20 return Server.client.code2ProtocolConverter.asRange(s);
22 }) 21 }),
23 } 22 textDocument: { uri: editor.document.uri.toString() },
24 let response = await Server.client.sendRequest<ExtendSelectionResult>("m/extendSelection", request) 23 };
24 const response = await Server.client.sendRequest<ExtendSelectionResult>('m/extendSelection', request);
25 editor.selections = response.selections.map((range: Range) => { 25 editor.selections = response.selections.map((range: Range) => {
26 let r = Server.client.protocol2CodeConverter.asRange(range) 26 const r = Server.client.protocol2CodeConverter.asRange(range);
27 return new vscode.Selection(r.start, r.end) 27 return new vscode.Selection(r.start, r.end);
28 }) 28 });
29} 29}
diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts
index 7ae7b9d76..80ad4460b 100644
--- a/editors/code/src/commands/join_lines.ts
+++ b/editors/code/src/commands/join_lines.ts
@@ -1,6 +1,6 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2 2
3import { TextDocumentIdentifier, Range } from "vscode-languageclient"; 3import { Range, TextDocumentIdentifier } from 'vscode-languageclient';
4import { Server } from '../server'; 4import { Server } from '../server';
5import { handle as applySourceChange, SourceChange } from './apply_source_change'; 5import { handle as applySourceChange, SourceChange } from './apply_source_change';
6 6
@@ -10,12 +10,12 @@ interface JoinLinesParams {
10} 10}
11 11
12export async function handle() { 12export async function handle() {
13 let editor = vscode.window.activeTextEditor 13 const editor = vscode.window.activeTextEditor;
14 if (editor == null || editor.document.languageId != "rust") return 14 if (editor == null || editor.document.languageId != 'rust') { return; }
15 let request: JoinLinesParams = { 15 const request: JoinLinesParams = {
16 textDocument: { uri: editor.document.uri.toString() },
17 range: Server.client.code2ProtocolConverter.asRange(editor.selection), 16 range: Server.client.code2ProtocolConverter.asRange(editor.selection),
18 } 17 textDocument: { uri: editor.document.uri.toString() },
19 let change = await Server.client.sendRequest<SourceChange>("m/joinLines", request) 18 };
20 await applySourceChange(change) 19 const change = await Server.client.sendRequest<SourceChange>('m/joinLines', request);
20 await applySourceChange(change);
21} 21}
diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts
index 572c15ce8..cf7f6bf8f 100644
--- a/editors/code/src/commands/matching_brace.ts
+++ b/editors/code/src/commands/matching_brace.ts
@@ -1,6 +1,6 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2 2
3import { TextDocumentIdentifier, Position } from "vscode-languageclient"; 3import { Position, TextDocumentIdentifier } from 'vscode-languageclient';
4import { Server } from '../server'; 4import { Server } from '../server';
5 5
6interface FindMatchingBraceParams { 6interface FindMatchingBraceParams {
@@ -9,19 +9,19 @@ interface FindMatchingBraceParams {
9} 9}
10 10
11export async function handle() { 11export async function handle() {
12 let editor = vscode.window.activeTextEditor 12 const editor = vscode.window.activeTextEditor;
13 if (editor == null || editor.document.languageId != "rust") return 13 if (editor == null || editor.document.languageId != 'rust') { return; }
14 let request: FindMatchingBraceParams = { 14 const request: FindMatchingBraceParams = {
15 textDocument: { uri: editor.document.uri.toString() }, 15 textDocument: { uri: editor.document.uri.toString() },
16 offsets: editor.selections.map((s) => { 16 offsets: editor.selections.map((s) => {
17 return Server.client.code2ProtocolConverter.asPosition(s.active) 17 return Server.client.code2ProtocolConverter.asPosition(s.active);
18 }) 18 }),
19 } 19 };
20 let response = await Server.client.sendRequest<Position[]>("m/findMatchingBrace", request) 20 const response = await Server.client.sendRequest<Position[]>('m/findMatchingBrace', request);
21 editor.selections = editor.selections.map((sel, idx) => { 21 editor.selections = editor.selections.map((sel, idx) => {
22 let active = Server.client.protocol2CodeConverter.asPosition(response[idx]) 22 const active = Server.client.protocol2CodeConverter.asPosition(response[idx]);
23 let anchor = sel.isEmpty ? active : sel.anchor 23 const anchor = sel.isEmpty ? active : sel.anchor;
24 return new vscode.Selection(anchor, active) 24 return new vscode.Selection(anchor, active);
25 }) 25 });
26 editor.revealRange(editor.selection) 26 editor.revealRange(editor.selection);
27}; 27}
diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts
index dae60bfb4..7d413c27a 100644
--- a/editors/code/src/commands/parent_module.ts
+++ b/editors/code/src/commands/parent_module.ts
@@ -1,22 +1,22 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2 2
3import { TextDocumentIdentifier, Location } from "vscode-languageclient"; 3import { Location, TextDocumentIdentifier } from 'vscode-languageclient';
4import { Server } from '../server'; 4import { Server } from '../server';
5 5
6export async function handle() { 6export async function handle() {
7 let editor = vscode.window.activeTextEditor 7 const editor = vscode.window.activeTextEditor;
8 if (editor == null || editor.document.languageId != "rust") return 8 if (editor == null || editor.document.languageId != 'rust') { return; }
9 let request: TextDocumentIdentifier = { 9 const request: TextDocumentIdentifier = {
10 uri: editor.document.uri.toString() 10 uri: editor.document.uri.toString(),
11 } 11 };
12 let response = await Server.client.sendRequest<Location[]>("m/parentModule", request) 12 const response = await Server.client.sendRequest<Location[]>('m/parentModule', request);
13 let loc = response[0] 13 const loc = response[0];
14 if (loc == null) return 14 if (loc == null) { return; }
15 let uri = Server.client.protocol2CodeConverter.asUri(loc.uri) 15 const uri = Server.client.protocol2CodeConverter.asUri(loc.uri);
16 let range = Server.client.protocol2CodeConverter.asRange(loc.range) 16 const range = Server.client.protocol2CodeConverter.asRange(loc.range);
17 17
18 let doc = await vscode.workspace.openTextDocument(uri) 18 const doc = await vscode.workspace.openTextDocument(uri);
19 let e = await vscode.window.showTextDocument(doc) 19 const e = await vscode.window.showTextDocument(doc);
20 e.selection = new vscode.Selection(range.start, range.start) 20 e.selection = new vscode.Selection(range.start, range.start);
21 e.revealRange(range, vscode.TextEditorRevealType.InCenter) 21 e.revealRange(range, vscode.TextEditorRevealType.InCenter);
22} 22}
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index 45c16497d..37db6ea10 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -1,10 +1,10 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient' 2import * as lc from 'vscode-languageclient';
3import { Server } from '../server'; 3import { Server } from '../server';
4 4
5interface RunnablesParams { 5interface RunnablesParams {
6 textDocument: lc.TextDocumentIdentifier, 6 textDocument: lc.TextDocumentIdentifier;
7 position?: lc.Position, 7 position?: lc.Position;
8} 8}
9 9
10interface Runnable { 10interface Runnable {
@@ -12,17 +12,17 @@ interface Runnable {
12 label: string; 12 label: string;
13 bin: string; 13 bin: string;
14 args: string[]; 14 args: string[];
15 env: { [index: string]: string }, 15 env: { [index: string]: string };
16} 16}
17 17
18class RunnableQuickPick implements vscode.QuickPickItem { 18class RunnableQuickPick implements vscode.QuickPickItem {
19 label: string; 19 public label: string;
20 description?: string | undefined; 20 public description?: string | undefined;
21 detail?: string | undefined; 21 public detail?: string | undefined;
22 picked?: boolean | undefined; 22 public picked?: boolean | undefined;
23 23
24 constructor(public runnable: Runnable) { 24 constructor(public runnable: Runnable) {
25 this.label = runnable.label 25 this.label = runnable.label;
26 } 26 }
27} 27}
28 28
@@ -30,59 +30,59 @@ interface CargoTaskDefinition extends vscode.TaskDefinition {
30 type: 'cargo'; 30 type: 'cargo';
31 label: string; 31 label: string;
32 command: string; 32 command: string;
33 args: Array<string>; 33 args: string[];
34 env?: { [key: string]: string }; 34 env?: { [key: string]: string };
35} 35}
36 36
37function createTask(spec: Runnable): vscode.Task { 37function createTask(spec: Runnable): vscode.Task {
38 const TASK_SOURCE = 'Rust'; 38 const TASK_SOURCE = 'Rust';
39 let definition: CargoTaskDefinition = { 39 const definition: CargoTaskDefinition = {
40 type: 'cargo', 40 type: 'cargo',
41 label: 'cargo', 41 label: 'cargo',
42 command: spec.bin, 42 command: spec.bin,
43 args: spec.args, 43 args: spec.args,
44 env: spec.env 44 env: spec.env,
45 } 45 };
46 46
47 let execCmd = `${definition.command} ${definition.args.join(' ')}`; 47 const execCmd = `${definition.command} ${definition.args.join(' ')}`;
48 let execOption: vscode.ShellExecutionOptions = { 48 const execOption: vscode.ShellExecutionOptions = {
49 cwd: '.', 49 cwd: '.',
50 env: definition.env, 50 env: definition.env,
51 }; 51 };
52 let exec = new vscode.ShellExecution(`clear; ${execCmd}`, execOption); 52 const exec = new vscode.ShellExecution(`clear; ${execCmd}`, execOption);
53 53
54 let f = vscode.workspace.workspaceFolders![0] 54 const f = vscode.workspace.workspaceFolders![0];
55 let t = new vscode.Task(definition, f, definition.label, TASK_SOURCE, exec, ['$rustc']); 55 const t = new vscode.Task(definition, f, definition.label, TASK_SOURCE, exec, ['$rustc']);
56 return t; 56 return t;
57} 57}
58 58
59let prevRunnable: RunnableQuickPick | undefined = undefined 59let prevRunnable: RunnableQuickPick | undefined;
60export async function handle() { 60export async function handle() {
61 let editor = vscode.window.activeTextEditor 61 const editor = vscode.window.activeTextEditor;
62 if (editor == null || editor.document.languageId != "rust") return 62 if (editor == null || editor.document.languageId != 'rust') { return; }
63 let textDocument: lc.TextDocumentIdentifier = { 63 const textDocument: lc.TextDocumentIdentifier = {
64 uri: editor.document.uri.toString() 64 uri: editor.document.uri.toString(),
65 } 65 };
66 let params: RunnablesParams = { 66 const params: RunnablesParams = {
67 textDocument, 67 textDocument,
68 position: Server.client.code2ProtocolConverter.asPosition(editor.selection.active) 68 position: Server.client.code2ProtocolConverter.asPosition(editor.selection.active),
69 } 69 };
70 let runnables = await Server.client.sendRequest<Runnable[]>('m/runnables', params) 70 const runnables = await Server.client.sendRequest<Runnable[]>('m/runnables', params);
71 let items: RunnableQuickPick[] = [] 71 const items: RunnableQuickPick[] = [];
72 if (prevRunnable) { 72 if (prevRunnable) {
73 items.push(prevRunnable) 73 items.push(prevRunnable);
74 } 74 }
75 for (let r of runnables) { 75 for (const r of runnables) {
76 if (prevRunnable && JSON.stringify(prevRunnable.runnable) == JSON.stringify(r)) { 76 if (prevRunnable && JSON.stringify(prevRunnable.runnable) == JSON.stringify(r)) {
77 continue 77 continue;
78 } 78 }
79 items.push(new RunnableQuickPick(r)) 79 items.push(new RunnableQuickPick(r));
80 } 80 }
81 let item = await vscode.window.showQuickPick(items) 81 const item = await vscode.window.showQuickPick(items);
82 if (item) { 82 if (item) {
83 item.detail = "rerun" 83 item.detail = 'rerun';
84 prevRunnable = item 84 prevRunnable = item;
85 let task = createTask(item.runnable) 85 const task = createTask(item.runnable);
86 return await vscode.tasks.executeTask(task) 86 return await vscode.tasks.executeTask(task);
87 } 87 }
88} 88}
diff --git a/editors/code/src/commands/syntaxTree.ts b/editors/code/src/commands/syntaxTree.ts
index d5daa9302..dcb721eee 100644
--- a/editors/code/src/commands/syntaxTree.ts
+++ b/editors/code/src/commands/syntaxTree.ts
@@ -6,20 +6,20 @@ import { Server } from '../server';
6export const syntaxTreeUri = vscode.Uri.parse('ra-lsp://syntaxtree'); 6export const syntaxTreeUri = vscode.Uri.parse('ra-lsp://syntaxtree');
7 7
8export class TextDocumentContentProvider implements vscode.TextDocumentContentProvider { 8export class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
9 public eventEmitter = new vscode.EventEmitter<vscode.Uri>() 9 public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
10 public syntaxTree: string = "Not available" 10 public syntaxTree: string = 'Not available';
11 11
12 public provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> { 12 public provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> {
13 let editor = vscode.window.activeTextEditor; 13 const editor = vscode.window.activeTextEditor;
14 if (editor == null) return "" 14 if (editor == null) { return ''; }
15 let request: SyntaxTreeParams = { 15 const request: SyntaxTreeParams = {
16 textDocument: { uri: editor.document.uri.toString() } 16 textDocument: { uri: editor.document.uri.toString() },
17 }; 17 };
18 return Server.client.sendRequest<SyntaxTreeResult>("m/syntaxTree", request); 18 return Server.client.sendRequest<SyntaxTreeResult>('m/syntaxTree', request);
19 } 19 }
20 20
21 get onDidChange(): vscode.Event<vscode.Uri> { 21 get onDidChange(): vscode.Event<vscode.Uri> {
22 return this.eventEmitter.event 22 return this.eventEmitter.event;
23 } 23 }
24} 24}
25 25
@@ -33,6 +33,6 @@ type SyntaxTreeResult = string;
33// 33//
34// The contents of the file come from the `TextDocumentContentProvider` 34// The contents of the file come from the `TextDocumentContentProvider`
35export async function handle() { 35export async function handle() {
36 let document = await vscode.workspace.openTextDocument(syntaxTreeUri) 36 const document = await vscode.workspace.openTextDocument(syntaxTreeUri);
37 return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true) 37 return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true);
38} 38}