aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-10-09 07:16:36 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-10-09 07:16:36 +0100
commitc9798c0e6da53c132021f03ac7a50ccd8714b371 (patch)
tree0d6d49b2eb40ad161a72adbfbf9874b64540bf74 /editors/code/src/commands
parentf4ad36e972989c3feed8671d6d6fca0aed37cd8f (diff)
parente26071d96e1ff56289213dbe78415f836de8a70e (diff)
Merge #104
104: Add vscode extension to CI r=aochagavia a=DJMcNab Note that this testing is only done on travis - we are only running formatting and linting, so feature parity on appveyor is not required. CC @aochagavia. Fixes? #100 Co-authored-by: Daniel McNab <[email protected]>
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r--editors/code/src/commands/apply_source_change.ts24
-rw-r--r--editors/code/src/commands/extend_selection.ts13
-rw-r--r--editors/code/src/commands/index.ts2
-rw-r--r--editors/code/src/commands/join_lines.ts16
-rw-r--r--editors/code/src/commands/matching_brace.ts17
-rw-r--r--editors/code/src/commands/parent_module.ts15
-rw-r--r--editors/code/src/commands/runnables.ts33
-rw-r--r--editors/code/src/commands/syntaxTree.ts24
8 files changed, 106 insertions, 38 deletions
diff --git a/editors/code/src/commands/apply_source_change.ts b/editors/code/src/commands/apply_source_change.ts
index 67765e5a3..cf921e3ac 100644
--- a/editors/code/src/commands/apply_source_change.ts
+++ b/editors/code/src/commands/apply_source_change.ts
@@ -20,8 +20,12 @@ export interface SourceChange {
20export async function handle(change: SourceChange) { 20export async function handle(change: SourceChange) {
21 const wsEdit = new vscode.WorkspaceEdit(); 21 const wsEdit = new vscode.WorkspaceEdit();
22 for (const sourceEdit of change.sourceFileEdits) { 22 for (const sourceEdit of change.sourceFileEdits) {
23 const uri = Server.client.protocol2CodeConverter.asUri(sourceEdit.textDocument.uri); 23 const uri = Server.client.protocol2CodeConverter.asUri(
24 const edits = Server.client.protocol2CodeConverter.asTextEdits(sourceEdit.edits); 24 sourceEdit.textDocument.uri
25 );
26 const edits = Server.client.protocol2CodeConverter.asTextEdits(
27 sourceEdit.edits
28 );
25 wsEdit.set(uri, edits); 29 wsEdit.set(uri, edits);
26 } 30 }
27 let created; 31 let created;
@@ -48,11 +52,19 @@ export async function handle(change: SourceChange) {
48 const doc = await vscode.workspace.openTextDocument(toOpen); 52 const doc = await vscode.workspace.openTextDocument(toOpen);
49 await vscode.window.showTextDocument(doc); 53 await vscode.window.showTextDocument(doc);
50 } else if (toReveal) { 54 } else if (toReveal) {
51 const uri = Server.client.protocol2CodeConverter.asUri(toReveal.textDocument.uri); 55 const uri = Server.client.protocol2CodeConverter.asUri(
52 const position = Server.client.protocol2CodeConverter.asPosition(toReveal.position); 56 toReveal.textDocument.uri
57 );
58 const position = Server.client.protocol2CodeConverter.asPosition(
59 toReveal.position
60 );
53 const editor = vscode.window.activeTextEditor; 61 const editor = vscode.window.activeTextEditor;
54 if (!editor || editor.document.uri.toString() !== uri.toString()) { return; } 62 if (!editor || editor.document.uri.toString() !== uri.toString()) {
55 if (!editor.selection.isEmpty) { return; } 63 return;
64 }
65 if (!editor.selection.isEmpty) {
66 return;
67 }
56 editor!.selection = new vscode.Selection(position, position); 68 editor!.selection = new vscode.Selection(position, position);
57 } 69 }
58} 70}
diff --git a/editors/code/src/commands/extend_selection.ts b/editors/code/src/commands/extend_selection.ts
index cdc3d10fb..0ee6bd11d 100644
--- a/editors/code/src/commands/extend_selection.ts
+++ b/editors/code/src/commands/extend_selection.ts
@@ -14,14 +14,19 @@ interface ExtendSelectionResult {
14 14
15export async function handle() { 15export async function handle() {
16 const 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') {
18 return;
19 }
18 const request: ExtendSelectionParams = { 20 const request: ExtendSelectionParams = {
19 selections: editor.selections.map((s) => { 21 selections: editor.selections.map(s => {
20 return Server.client.code2ProtocolConverter.asRange(s); 22 return Server.client.code2ProtocolConverter.asRange(s);
21 }), 23 }),
22 textDocument: { uri: editor.document.uri.toString() }, 24 textDocument: { uri: editor.document.uri.toString() }
23 }; 25 };
24 const response = await Server.client.sendRequest<ExtendSelectionResult>('m/extendSelection', request); 26 const response = await Server.client.sendRequest<ExtendSelectionResult>(
27 'm/extendSelection',
28 request
29 );
25 editor.selections = response.selections.map((range: Range) => { 30 editor.selections = response.selections.map((range: Range) => {
26 const r = Server.client.protocol2CodeConverter.asRange(range); 31 const r = Server.client.protocol2CodeConverter.asRange(range);
27 return new vscode.Selection(r.start, r.end); 32 return new vscode.Selection(r.start, r.end);
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
index dfdcd6454..2496c7ff8 100644
--- a/editors/code/src/commands/index.ts
+++ b/editors/code/src/commands/index.ts
@@ -13,5 +13,5 @@ export {
13 matchingBrace, 13 matchingBrace,
14 parentModule, 14 parentModule,
15 runnables, 15 runnables,
16 syntaxTree, 16 syntaxTree
17}; 17};
diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts
index 526b698cc..27d263b8a 100644
--- a/editors/code/src/commands/join_lines.ts
+++ b/editors/code/src/commands/join_lines.ts
@@ -2,7 +2,10 @@ import * as vscode from 'vscode';
2 2
3import { Range, TextDocumentIdentifier } 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 {
6 handle as applySourceChange,
7 SourceChange
8} from './apply_source_change';
6 9
7interface JoinLinesParams { 10interface JoinLinesParams {
8 textDocument: TextDocumentIdentifier; 11 textDocument: TextDocumentIdentifier;
@@ -11,11 +14,16 @@ interface JoinLinesParams {
11 14
12export async function handle() { 15export async function handle() {
13 const editor = vscode.window.activeTextEditor; 16 const editor = vscode.window.activeTextEditor;
14 if (editor == null || editor.document.languageId !== 'rust') { return; } 17 if (editor == null || editor.document.languageId !== 'rust') {
18 return;
19 }
15 const request: JoinLinesParams = { 20 const request: JoinLinesParams = {
16 range: Server.client.code2ProtocolConverter.asRange(editor.selection), 21 range: Server.client.code2ProtocolConverter.asRange(editor.selection),
17 textDocument: { uri: editor.document.uri.toString() }, 22 textDocument: { uri: editor.document.uri.toString() }
18 }; 23 };
19 const change = await Server.client.sendRequest<SourceChange>('m/joinLines', request); 24 const change = await Server.client.sendRequest<SourceChange>(
25 'm/joinLines',
26 request
27 );
20 await applySourceChange(change); 28 await applySourceChange(change);
21} 29}
diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts
index a80446a8f..5e6638e82 100644
--- a/editors/code/src/commands/matching_brace.ts
+++ b/editors/code/src/commands/matching_brace.ts
@@ -10,16 +10,23 @@ interface FindMatchingBraceParams {
10 10
11export async function handle() { 11export async function handle() {
12 const 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') {
14 return;
15 }
14 const request: FindMatchingBraceParams = { 16 const request: FindMatchingBraceParams = {
15 textDocument: { uri: editor.document.uri.toString() }, 17 textDocument: { uri: editor.document.uri.toString() },
16 offsets: editor.selections.map((s) => { 18 offsets: editor.selections.map(s => {
17 return Server.client.code2ProtocolConverter.asPosition(s.active); 19 return Server.client.code2ProtocolConverter.asPosition(s.active);
18 }), 20 })
19 }; 21 };
20 const response = await Server.client.sendRequest<Position[]>('m/findMatchingBrace', request); 22 const response = await Server.client.sendRequest<Position[]>(
23 'm/findMatchingBrace',
24 request
25 );
21 editor.selections = editor.selections.map((sel, idx) => { 26 editor.selections = editor.selections.map((sel, idx) => {
22 const active = Server.client.protocol2CodeConverter.asPosition(response[idx]); 27 const active = Server.client.protocol2CodeConverter.asPosition(
28 response[idx]
29 );
23 const anchor = sel.isEmpty ? active : sel.anchor; 30 const anchor = sel.isEmpty ? active : sel.anchor;
24 return new vscode.Selection(anchor, active); 31 return new vscode.Selection(anchor, active);
25 }); 32 });
diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts
index d66fb3026..4bb92eb96 100644
--- a/editors/code/src/commands/parent_module.ts
+++ b/editors/code/src/commands/parent_module.ts
@@ -5,13 +5,20 @@ import { Server } from '../server';
5 5
6export async function handle() { 6export async function handle() {
7 const 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') {
9 return;
10 }
9 const request: TextDocumentIdentifier = { 11 const request: TextDocumentIdentifier = {
10 uri: editor.document.uri.toString(), 12 uri: editor.document.uri.toString()
11 }; 13 };
12 const response = await Server.client.sendRequest<Location[]>('m/parentModule', request); 14 const response = await Server.client.sendRequest<Location[]>(
15 'm/parentModule',
16 request
17 );
13 const loc = response[0]; 18 const loc = response[0];
14 if (loc == null) { return; } 19 if (loc == null) {
20 return;
21 }
15 const uri = Server.client.protocol2CodeConverter.asUri(loc.uri); 22 const uri = Server.client.protocol2CodeConverter.asUri(loc.uri);
16 const range = Server.client.protocol2CodeConverter.asRange(loc.range); 23 const range = Server.client.protocol2CodeConverter.asRange(loc.range);
17 24
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index 40f590dce..c234bfaec 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -41,39 +41,56 @@ function createTask(spec: Runnable): vscode.Task {
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 const execCmd = `${definition.command} ${definition.args.join(' ')}`; 47 const execCmd = `${definition.command} ${definition.args.join(' ')}`;
48 const execOption: vscode.ShellExecutionOptions = { 48 const execOption: vscode.ShellExecutionOptions = {
49 cwd: '.', 49 cwd: '.',
50 env: definition.env, 50 env: definition.env
51 }; 51 };
52 const exec = new vscode.ShellExecution(`clear; ${execCmd}`, execOption); 52 const exec = new vscode.ShellExecution(`clear; ${execCmd}`, execOption);
53 53
54 const f = vscode.workspace.workspaceFolders![0]; 54 const f = vscode.workspace.workspaceFolders![0];
55 const t = new vscode.Task(definition, f, definition.label, TASK_SOURCE, exec, ['$rustc']); 55 const t = new vscode.Task(
56 definition,
57 f,
58 definition.label,
59 TASK_SOURCE,
60 exec,
61 ['$rustc']
62 );
56 return t; 63 return t;
57} 64}
58 65
59let prevRunnable: RunnableQuickPick | undefined; 66let prevRunnable: RunnableQuickPick | undefined;
60export async function handle() { 67export async function handle() {
61 const editor = vscode.window.activeTextEditor; 68 const editor = vscode.window.activeTextEditor;
62 if (editor == null || editor.document.languageId !== 'rust') { return; } 69 if (editor == null || editor.document.languageId !== 'rust') {
70 return;
71 }
63 const textDocument: lc.TextDocumentIdentifier = { 72 const textDocument: lc.TextDocumentIdentifier = {
64 uri: editor.document.uri.toString(), 73 uri: editor.document.uri.toString()
65 }; 74 };
66 const params: RunnablesParams = { 75 const params: RunnablesParams = {
67 textDocument, 76 textDocument,
68 position: Server.client.code2ProtocolConverter.asPosition(editor.selection.active), 77 position: Server.client.code2ProtocolConverter.asPosition(
78 editor.selection.active
79 )
69 }; 80 };
70 const runnables = await Server.client.sendRequest<Runnable[]>('m/runnables', params); 81 const runnables = await Server.client.sendRequest<Runnable[]>(
82 'm/runnables',
83 params
84 );
71 const items: RunnableQuickPick[] = []; 85 const items: RunnableQuickPick[] = [];
72 if (prevRunnable) { 86 if (prevRunnable) {
73 items.push(prevRunnable); 87 items.push(prevRunnable);
74 } 88 }
75 for (const r of runnables) { 89 for (const r of runnables) {
76 if (prevRunnable && JSON.stringify(prevRunnable.runnable) === JSON.stringify(r)) { 90 if (
91 prevRunnable &&
92 JSON.stringify(prevRunnable.runnable) === JSON.stringify(r)
93 ) {
77 continue; 94 continue;
78 } 95 }
79 items.push(new RunnableQuickPick(r)); 96 items.push(new RunnableQuickPick(r));
diff --git a/editors/code/src/commands/syntaxTree.ts b/editors/code/src/commands/syntaxTree.ts
index dcb721eee..5d5cdd7a0 100644
--- a/editors/code/src/commands/syntaxTree.ts
+++ b/editors/code/src/commands/syntaxTree.ts
@@ -5,17 +5,25 @@ import { Server } from '../server';
5 5
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
9 implements vscode.TextDocumentContentProvider {
9 public eventEmitter = new vscode.EventEmitter<vscode.Uri>(); 10 public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
10 public syntaxTree: string = 'Not available'; 11 public syntaxTree: string = 'Not available';
11 12
12 public provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> { 13 public provideTextDocumentContent(
14 uri: vscode.Uri
15 ): vscode.ProviderResult<string> {
13 const editor = vscode.window.activeTextEditor; 16 const editor = vscode.window.activeTextEditor;
14 if (editor == null) { return ''; } 17 if (editor == null) {
18 return '';
19 }
15 const request: SyntaxTreeParams = { 20 const request: SyntaxTreeParams = {
16 textDocument: { uri: editor.document.uri.toString() }, 21 textDocument: { uri: editor.document.uri.toString() }
17 }; 22 };
18 return Server.client.sendRequest<SyntaxTreeResult>('m/syntaxTree', request); 23 return Server.client.sendRequest<SyntaxTreeResult>(
24 'm/syntaxTree',
25 request
26 );
19 } 27 }
20 28
21 get onDidChange(): vscode.Event<vscode.Uri> { 29 get onDidChange(): vscode.Event<vscode.Uri> {
@@ -34,5 +42,9 @@ type SyntaxTreeResult = string;
34// The contents of the file come from the `TextDocumentContentProvider` 42// The contents of the file come from the `TextDocumentContentProvider`
35export async function handle() { 43export async function handle() {
36 const document = await vscode.workspace.openTextDocument(syntaxTreeUri); 44 const document = await vscode.workspace.openTextDocument(syntaxTreeUri);
37 return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true); 45 return vscode.window.showTextDocument(
46 document,
47 vscode.ViewColumn.Two,
48 true
49 );
38} 50}