aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel McNab <[email protected]>2018-10-08 22:38:33 +0100
committerDaniel McNab <[email protected]>2018-10-08 22:38:33 +0100
commite26071d96e1ff56289213dbe78415f836de8a70e (patch)
tree0d6d49b2eb40ad161a72adbfbf9874b64540bf74
parent3a405b65d61a5ad3176c223e4b7226a43fcd186e (diff)
Run prettier on all files
-rw-r--r--editors/code/.vscode/launch.json14
-rw-r--r--editors/code/.vscode/settings.json2
-rw-r--r--editors/code/.vscode/tasks.json2
-rw-r--r--editors/code/package.json3
-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
-rw-r--r--editors/code/src/config.ts28
-rw-r--r--editors/code/src/events/change_active_text_editor.ts15
-rw-r--r--editors/code/src/events/change_text_document.ts13
-rw-r--r--editors/code/src/events/index.ts5
-rw-r--r--editors/code/src/extension.ts28
-rw-r--r--editors/code/src/highlighting.ts45
-rw-r--r--editors/code/src/notifications/index.ts4
-rw-r--r--editors/code/src/notifications/publish_decorations.ts11
-rw-r--r--editors/code/src/server.ts12
-rw-r--r--editors/code/tsconfig.json9
-rw-r--r--editors/code/tslint.json14
23 files changed, 220 insertions, 129 deletions
diff --git a/editors/code/.vscode/launch.json b/editors/code/.vscode/launch.json
index c174db304..b9d14dddd 100644
--- a/editors/code/.vscode/launch.json
+++ b/editors/code/.vscode/launch.json
@@ -3,19 +3,15 @@
3// Hover to view descriptions of existing attributes. 3// Hover to view descriptions of existing attributes.
4// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 4// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5{ 5{
6 "version": "0.2.0", 6 "version": "0.2.0",
7 "configurations": [ 7 "configurations": [
8 { 8 {
9 "name": "Extension", 9 "name": "Extension",
10 "type": "extensionHost", 10 "type": "extensionHost",
11 "request": "launch", 11 "request": "launch",
12 "runtimeExecutable": "${execPath}", 12 "runtimeExecutable": "${execPath}",
13 "args": [ 13 "args": ["--extensionDevelopmentPath=${workspaceFolder}"],
14 "--extensionDevelopmentPath=${workspaceFolder}" 14 "outFiles": ["${workspaceFolder}/out/**/*.js"],
15 ],
16 "outFiles": [
17 "${workspaceFolder}/out/**/*.js"
18 ],
19 "preLaunchTask": "npm: watch" 15 "preLaunchTask": "npm: watch"
20 }, 16 },
21 { 17 {
@@ -27,9 +23,7 @@
27 "--extensionDevelopmentPath=${workspaceFolder}", 23 "--extensionDevelopmentPath=${workspaceFolder}",
28 "--extensionTestsPath=${workspaceFolder}/out/test" 24 "--extensionTestsPath=${workspaceFolder}/out/test"
29 ], 25 ],
30 "outFiles": [ 26 "outFiles": ["${workspaceFolder}/out/test/**/*.js"],
31 "${workspaceFolder}/out/test/**/*.js"
32 ],
33 "preLaunchTask": "npm: watch" 27 "preLaunchTask": "npm: watch"
34 } 28 }
35 ] 29 ]
diff --git a/editors/code/.vscode/settings.json b/editors/code/.vscode/settings.json
index 30bf8c2d3..fa0a10487 100644
--- a/editors/code/.vscode/settings.json
+++ b/editors/code/.vscode/settings.json
@@ -8,4 +8,4 @@
8 }, 8 },
9 // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 9 // Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10 "typescript.tsc.autoDetect": "off" 10 "typescript.tsc.autoDetect": "off"
11} \ No newline at end of file 11}
diff --git a/editors/code/.vscode/tasks.json b/editors/code/.vscode/tasks.json
index 604e38f5a..5deb2bccd 100644
--- a/editors/code/.vscode/tasks.json
+++ b/editors/code/.vscode/tasks.json
@@ -17,4 +17,4 @@
17 } 17 }
18 } 18 }
19 ] 19 ]
20} \ No newline at end of file 20}
diff --git a/editors/code/package.json b/editors/code/package.json
index 8328a46c5..cd07e3be9 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -23,7 +23,8 @@
23 "travis": "npm run compile && npm run lint && npm run prettier --list-different" 23 "travis": "npm run compile && npm run lint && npm run prettier --list-different"
24 }, 24 },
25 "prettier": { 25 "prettier": {
26 "tabWidth": 4 26 "tabWidth": 4,
27 "singleQuote": true
27 }, 28 },
28 "dependencies": { 29 "dependencies": {
29 "vscode-languageclient": "^4.4.0" 30 "vscode-languageclient": "^4.4.0"
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}
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index b9ff3b810..7d05ea078 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -3,21 +3,23 @@ import * as vscode from 'vscode';
3import { Server } from './server'; 3import { Server } from './server';
4 4
5export class Config { 5export class Config {
6 public highlightingOn = true; 6 public highlightingOn = true;
7 7
8 constructor() { 8 constructor() {
9 vscode.workspace.onDidChangeConfiguration((_) => this.userConfigChanged()); 9 vscode.workspace.onDidChangeConfiguration(_ =>
10 this.userConfigChanged(); 10 this.userConfigChanged()
11 } 11 );
12 12 this.userConfigChanged();
13 public userConfigChanged() {
14 const config = vscode.workspace.getConfiguration('ra-lsp');
15 if (config.has('highlightingOn')) {
16 this.highlightingOn = config.get('highlightingOn') as boolean;
17 } 13 }
18 14
19 if (!this.highlightingOn && Server) { 15 public userConfigChanged() {
20 Server.highlighter.removeHighlights(); 16 const config = vscode.workspace.getConfiguration('ra-lsp');
17 if (config.has('highlightingOn')) {
18 this.highlightingOn = config.get('highlightingOn') as boolean;
19 }
20
21 if (!this.highlightingOn && Server) {
22 Server.highlighter.removeHighlights();
23 }
21 } 24 }
22 }
23} 25}
diff --git a/editors/code/src/events/change_active_text_editor.ts b/editors/code/src/events/change_active_text_editor.ts
index 3440aa0c3..0b7ceb65d 100644
--- a/editors/code/src/events/change_active_text_editor.ts
+++ b/editors/code/src/events/change_active_text_editor.ts
@@ -5,10 +5,19 @@ import { Decoration } from '../highlighting';
5import { Server } from '../server'; 5import { Server } from '../server';
6 6
7export async function handle(editor: TextEditor | undefined) { 7export async function handle(editor: TextEditor | undefined) {
8 if (!Server.config.highlightingOn || !editor || editor.document.languageId !== 'rust') { return; } 8 if (
9 !Server.config.highlightingOn ||
10 !editor ||
11 editor.document.languageId !== 'rust'
12 ) {
13 return;
14 }
9 const params: TextDocumentIdentifier = { 15 const params: TextDocumentIdentifier = {
10 uri: editor.document.uri.toString(), 16 uri: editor.document.uri.toString()
11 }; 17 };
12 const decorations = await Server.client.sendRequest<Decoration[]>('m/decorationsRequest', params); 18 const decorations = await Server.client.sendRequest<Decoration[]>(
19 'm/decorationsRequest',
20 params
21 );
13 Server.highlighter.setHighlights(editor, decorations); 22 Server.highlighter.setHighlights(editor, decorations);
14} 23}
diff --git a/editors/code/src/events/change_text_document.ts b/editors/code/src/events/change_text_document.ts
index b3000e026..6be057245 100644
--- a/editors/code/src/events/change_text_document.ts
+++ b/editors/code/src/events/change_text_document.ts
@@ -1,11 +1,18 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2 2
3import { syntaxTreeUri, TextDocumentContentProvider } from '../commands/syntaxTree'; 3import {
4 syntaxTreeUri,
5 TextDocumentContentProvider
6} from '../commands/syntaxTree';
4 7
5export function createHandler(textDocumentContentProvider: TextDocumentContentProvider) { 8export function createHandler(
9 textDocumentContentProvider: TextDocumentContentProvider
10) {
6 return (event: vscode.TextDocumentChangeEvent) => { 11 return (event: vscode.TextDocumentChangeEvent) => {
7 const doc = event.document; 12 const doc = event.document;
8 if (doc.languageId !== 'rust') { return; } 13 if (doc.languageId !== 'rust') {
14 return;
15 }
9 afterLs(() => { 16 afterLs(() => {
10 textDocumentContentProvider.eventEmitter.fire(syntaxTreeUri); 17 textDocumentContentProvider.eventEmitter.fire(syntaxTreeUri);
11 }); 18 });
diff --git a/editors/code/src/events/index.ts b/editors/code/src/events/index.ts
index b570a7a92..4c154563f 100644
--- a/editors/code/src/events/index.ts
+++ b/editors/code/src/events/index.ts
@@ -1,7 +1,4 @@
1import * as changeActiveTextEditor from './change_active_text_editor'; 1import * as changeActiveTextEditor from './change_active_text_editor';
2import * as changeTextDocument from './change_text_document'; 2import * as changeTextDocument from './change_text_document';
3 3
4export { 4export { changeActiveTextEditor, changeTextDocument };
5 changeActiveTextEditor,
6 changeTextDocument,
7};
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts
index 44e74f4cc..81e1107a0 100644
--- a/editors/code/src/extension.ts
+++ b/editors/code/src/extension.ts
@@ -23,26 +23,34 @@ export function activate(context: vscode.ExtensionContext) {
23 registerCommand('ra-lsp.joinLines', commands.joinLines.handle); 23 registerCommand('ra-lsp.joinLines', commands.joinLines.handle);
24 registerCommand('ra-lsp.parentModule', commands.parentModule.handle); 24 registerCommand('ra-lsp.parentModule', commands.parentModule.handle);
25 registerCommand('ra-lsp.run', commands.runnables.handle); 25 registerCommand('ra-lsp.run', commands.runnables.handle);
26 registerCommand('ra-lsp.applySourceChange', commands.applySourceChange.handle); 26 registerCommand(
27 'ra-lsp.applySourceChange',
28 commands.applySourceChange.handle
29 );
27 30
28 // Notifications are events triggered by the language server 31 // Notifications are events triggered by the language server
29 const allNotifications: Iterable<[string, lc.GenericNotificationHandler]> = [ 32 const allNotifications: Iterable<
30 ['m/publishDecorations', notifications.publishDecorations.handle], 33 [string, lc.GenericNotificationHandler]
31 ]; 34 > = [['m/publishDecorations', notifications.publishDecorations.handle]];
32 35
33 // The events below are plain old javascript events, triggered and handled by vscode 36 // The events below are plain old javascript events, triggered and handled by vscode
34 vscode.window.onDidChangeActiveTextEditor(events.changeActiveTextEditor.handle); 37 vscode.window.onDidChangeActiveTextEditor(
38 events.changeActiveTextEditor.handle
39 );
35 40
36 const textDocumentContentProvider = new TextDocumentContentProvider(); 41 const textDocumentContentProvider = new TextDocumentContentProvider();
37 disposeOnDeactivation(vscode.workspace.registerTextDocumentContentProvider( 42 disposeOnDeactivation(
38 'ra-lsp', 43 vscode.workspace.registerTextDocumentContentProvider(
39 textDocumentContentProvider, 44 'ra-lsp',
40 )); 45 textDocumentContentProvider
46 )
47 );
41 48
42 vscode.workspace.onDidChangeTextDocument( 49 vscode.workspace.onDidChangeTextDocument(
43 events.changeTextDocument.createHandler(textDocumentContentProvider), 50 events.changeTextDocument.createHandler(textDocumentContentProvider),
44 null, 51 null,
45 context.subscriptions); 52 context.subscriptions
53 );
46 54
47 // Start the language server, finally! 55 // Start the language server, finally!
48 Server.start(allNotifications); 56 Server.start(allNotifications);
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index e2ac4d629..ceddffe0e 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -9,15 +9,24 @@ export interface Decoration {
9} 9}
10 10
11export class Highlighter { 11export class Highlighter {
12 private static initDecorations(): Map<string, vscode.TextEditorDecorationType> { 12 private static initDecorations(): Map<
13 const decor = (color: string) => vscode.window.createTextEditorDecorationType({ color }); 13 string,
14 vscode.TextEditorDecorationType
15 > {
16 const decor = (color: string) =>
17 vscode.window.createTextEditorDecorationType({ color });
14 18
15 const decorations: Iterable<[string, vscode.TextEditorDecorationType]> = [ 19 const decorations: Iterable<
20 [string, vscode.TextEditorDecorationType]
21 > = [
16 ['background', decor('#3F3F3F')], 22 ['background', decor('#3F3F3F')],
17 ['error', vscode.window.createTextEditorDecorationType({ 23 [
18 borderColor: 'red', 24 'error',
19 borderStyle: 'none none dashed none', 25 vscode.window.createTextEditorDecorationType({
20 })], 26 borderColor: 'red',
27 borderStyle: 'none none dashed none'
28 })
29 ],
21 ['comment', decor('#7F9F7F')], 30 ['comment', decor('#7F9F7F')],
22 ['string', decor('#CC9393')], 31 ['string', decor('#CC9393')],
23 ['keyword', decor('#F0DFAF')], 32 ['keyword', decor('#F0DFAF')],
@@ -26,13 +35,16 @@ export class Highlighter {
26 ['builtin', decor('#DD6718')], 35 ['builtin', decor('#DD6718')],
27 ['text', decor('#DCDCCC')], 36 ['text', decor('#DCDCCC')],
28 ['attribute', decor('#BFEBBF')], 37 ['attribute', decor('#BFEBBF')],
29 ['literal', decor('#DFAF8F')], 38 ['literal', decor('#DFAF8F')]
30 ]; 39 ];
31 40
32 return new Map<string, vscode.TextEditorDecorationType>(decorations); 41 return new Map<string, vscode.TextEditorDecorationType>(decorations);
33 } 42 }
34 43
35 private decorations: (Map<string, vscode.TextEditorDecorationType> | null) = null; 44 private decorations: Map<
45 string,
46 vscode.TextEditorDecorationType
47 > | null = null;
36 48
37 public removeHighlights() { 49 public removeHighlights() {
38 if (this.decorations == null) { 50 if (this.decorations == null) {
@@ -47,10 +59,7 @@ export class Highlighter {
47 this.decorations = null; 59 this.decorations = null;
48 } 60 }
49 61
50 public setHighlights( 62 public setHighlights(editor: vscode.TextEditor, highlights: Decoration[]) {
51 editor: vscode.TextEditor,
52 highlights: Decoration[],
53 ) {
54 // Initialize decorations if necessary 63 // Initialize decorations if necessary
55 // 64 //
56 // Note: decoration objects need to be kept around so we can dispose them 65 // Note: decoration objects need to be kept around so we can dispose them
@@ -68,13 +77,15 @@ export class Highlighter {
68 if (!byTag.get(d.tag)) { 77 if (!byTag.get(d.tag)) {
69 continue; 78 continue;
70 } 79 }
71 byTag.get(d.tag)!.push( 80 byTag
72 Server.client.protocol2CodeConverter.asRange(d.range), 81 .get(d.tag)!
73 ); 82 .push(Server.client.protocol2CodeConverter.asRange(d.range));
74 } 83 }
75 84
76 for (const tag of byTag.keys()) { 85 for (const tag of byTag.keys()) {
77 const dec = this.decorations.get(tag) as vscode.TextEditorDecorationType; 86 const dec = this.decorations.get(
87 tag
88 ) as vscode.TextEditorDecorationType;
78 const ranges = byTag.get(tag)!; 89 const ranges = byTag.get(tag)!;
79 editor.setDecorations(dec, ranges); 90 editor.setDecorations(dec, ranges);
80 } 91 }
diff --git a/editors/code/src/notifications/index.ts b/editors/code/src/notifications/index.ts
index c56576865..74c4c3563 100644
--- a/editors/code/src/notifications/index.ts
+++ b/editors/code/src/notifications/index.ts
@@ -1,5 +1,3 @@
1import * as publishDecorations from './publish_decorations'; 1import * as publishDecorations from './publish_decorations';
2 2
3export { 3export { publishDecorations };
4 publishDecorations,
5};
diff --git a/editors/code/src/notifications/publish_decorations.ts b/editors/code/src/notifications/publish_decorations.ts
index d8790386b..3180019b7 100644
--- a/editors/code/src/notifications/publish_decorations.ts
+++ b/editors/code/src/notifications/publish_decorations.ts
@@ -10,11 +10,10 @@ export interface PublishDecorationsParams {
10 10
11export function handle(params: PublishDecorationsParams) { 11export function handle(params: PublishDecorationsParams) {
12 const targetEditor = vscode.window.visibleTextEditors.find( 12 const targetEditor = vscode.window.visibleTextEditors.find(
13 (editor) => editor.document.uri.toString() === params.uri, 13 editor => editor.document.uri.toString() === params.uri
14 );
15 if (!Server.config.highlightingOn || !targetEditor) { return; }
16 Server.highlighter.setHighlights(
17 targetEditor,
18 params.decorations,
19 ); 14 );
15 if (!Server.config.highlightingOn || !targetEditor) {
16 return;
17 }
18 Server.highlighter.setHighlights(targetEditor, params.decorations);
20} 19}
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts
index 01fd80756..196fc3ebc 100644
--- a/editors/code/src/server.ts
+++ b/editors/code/src/server.ts
@@ -8,24 +8,26 @@ export class Server {
8 public static config = new Config(); 8 public static config = new Config();
9 public static client: lc.LanguageClient; 9 public static client: lc.LanguageClient;
10 10
11 public static start(notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>) { 11 public static start(
12 notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>
13 ) {
12 const run: lc.Executable = { 14 const run: lc.Executable = {
13 command: 'ra_lsp_server', 15 command: 'ra_lsp_server',
14 options: { cwd: '.' }, 16 options: { cwd: '.' }
15 }; 17 };
16 const serverOptions: lc.ServerOptions = { 18 const serverOptions: lc.ServerOptions = {
17 run, 19 run,
18 debug: run, 20 debug: run
19 }; 21 };
20 const clientOptions: lc.LanguageClientOptions = { 22 const clientOptions: lc.LanguageClientOptions = {
21 documentSelector: [{ scheme: 'file', language: 'rust' }], 23 documentSelector: [{ scheme: 'file', language: 'rust' }]
22 }; 24 };
23 25
24 Server.client = new lc.LanguageClient( 26 Server.client = new lc.LanguageClient(
25 'ra-lsp', 27 'ra-lsp',
26 'rust-analyzer languge server', 28 'rust-analyzer languge server',
27 serverOptions, 29 serverOptions,
28 clientOptions, 30 clientOptions
29 ); 31 );
30 Server.client.onReady().then(() => { 32 Server.client.onReady().then(() => {
31 for (const [type, handler] of notificationHandlers) { 33 for (const [type, handler] of notificationHandlers) {
diff --git a/editors/code/tsconfig.json b/editors/code/tsconfig.json
index ebec01624..ef93c52b7 100644
--- a/editors/code/tsconfig.json
+++ b/editors/code/tsconfig.json
@@ -3,15 +3,10 @@
3 "module": "commonjs", 3 "module": "commonjs",
4 "target": "es6", 4 "target": "es6",
5 "outDir": "out", 5 "outDir": "out",
6 "lib": [ 6 "lib": ["es6"],
7 "es6"
8 ],
9 "sourceMap": true, 7 "sourceMap": true,
10 "rootDir": "src", 8 "rootDir": "src",
11 "strict": true 9 "strict": true
12 }, 10 },
13 "exclude": [ 11 "exclude": ["node_modules", ".vscode-test"]
14 "node_modules",
15 ".vscode-test"
16 ]
17} 12}
diff --git a/editors/code/tslint.json b/editors/code/tslint.json
index c2525a9db..bdeb4895e 100644
--- a/editors/code/tslint.json
+++ b/editors/code/tslint.json
@@ -1,9 +1,9 @@
1{ 1{
2 "defaultSeverity": "error", 2 "defaultSeverity": "error",
3 "extends": ["tslint:recommended", "tslint-config-prettier"], 3 "extends": ["tslint:recommended", "tslint-config-prettier"],
4 "rules": { 4 "rules": {
5 "quotemark": [true, "single"], 5 "quotemark": [true, "single"],
6 "interface-name": false, 6 "interface-name": false,
7 "object-literal-sort-keys": false 7 "object-literal-sort-keys": false
8 } 8 }
9} 9}