aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/commands.ts4
-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
-rw-r--r--editors/code/src/config.ts23
-rw-r--r--editors/code/src/events.ts6
-rw-r--r--editors/code/src/events/change_active_text_editor.ts22
-rw-r--r--editors/code/src/events/change_text_document.ts10
-rw-r--r--editors/code/src/extension.ts22
-rw-r--r--editors/code/src/highlighting.ts66
-rw-r--r--editors/code/src/server.ts74
-rw-r--r--editors/code/tslint.json13
16 files changed, 258 insertions, 242 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 99cac3379..c7e27781e 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.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/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}
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
new file mode 100644
index 000000000..740b5be20
--- /dev/null
+++ b/editors/code/src/config.ts
@@ -0,0 +1,23 @@
1import * as vscode from 'vscode';
2
3import { Server } from './server';
4
5export class Config {
6 public highlightingOn = true;
7
8 constructor() {
9 vscode.workspace.onDidChangeConfiguration((_) => this.userConfigChanged());
10 this.userConfigChanged();
11 }
12
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 }
18
19 if (!this.highlightingOn && Server) {
20 Server.highlighter.removeHighlights();
21 }
22 }
23}
diff --git a/editors/code/src/events.ts b/editors/code/src/events.ts
index b143bb256..8e2ac4a46 100644
--- a/editors/code/src/events.ts
+++ b/editors/code/src/events.ts
@@ -1,7 +1,7 @@
1import * as changeActiveTextEditor from './events/change_active_text_editor' 1import * as changeActiveTextEditor from './events/change_active_text_editor';
2import * as changeTextDocument from './events/change_text_document'; 2import * as changeTextDocument from './events/change_text_document';
3 3
4export { 4export {
5 changeActiveTextEditor, 5 changeActiveTextEditor,
6 changeTextDocument 6 changeTextDocument,
7} \ No newline at end of file 7};
diff --git a/editors/code/src/events/change_active_text_editor.ts b/editors/code/src/events/change_active_text_editor.ts
index bbdd53098..96d61126c 100644
--- a/editors/code/src/events/change_active_text_editor.ts
+++ b/editors/code/src/events/change_active_text_editor.ts
@@ -1,14 +1,14 @@
1import { TextEditor } from "vscode"; 1import { TextEditor } from 'vscode';
2import { TextDocumentIdentifier } from "vscode-languageclient"; 2import { TextDocumentIdentifier } from 'vscode-languageclient';
3 3
4import { Server } from "../server"; 4import { Decoration } from '../highlighting';
5import { Decoration } from "../highlighting"; 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 (!Server.config.highlightingOn || !editor || editor.document.languageId != 'rust') { return; }
9 let params: TextDocumentIdentifier = { 9 const params: TextDocumentIdentifier = {
10 uri: editor.document.uri.toString() 10 uri: editor.document.uri.toString(),
11 } 11 };
12 let decorations = await Server.client.sendRequest<Decoration[]>("m/decorationsRequest", params) 12 const decorations = await Server.client.sendRequest<Decoration[]>('m/decorationsRequest', params);
13 Server.highlighter.setHighlights(editor, decorations) 13 Server.highlighter.setHighlights(editor, decorations);
14} \ No newline at end of file 14}
diff --git a/editors/code/src/events/change_text_document.ts b/editors/code/src/events/change_text_document.ts
index 83ee6c9ee..192fb1e8a 100644
--- a/editors/code/src/events/change_text_document.ts
+++ b/editors/code/src/events/change_text_document.ts
@@ -4,16 +4,16 @@ import { syntaxTreeUri, TextDocumentContentProvider } from '../commands/syntaxTr
4 4
5export function createHandler(textDocumentContentProvider: TextDocumentContentProvider) { 5export function createHandler(textDocumentContentProvider: TextDocumentContentProvider) {
6 return (event: vscode.TextDocumentChangeEvent) => { 6 return (event: vscode.TextDocumentChangeEvent) => {
7 let doc = event.document 7 const doc = event.document;
8 if (doc.languageId != "rust") return 8 if (doc.languageId != 'rust') { return; }
9 afterLs(() => { 9 afterLs(() => {
10 textDocumentContentProvider.eventEmitter.fire(syntaxTreeUri); 10 textDocumentContentProvider.eventEmitter.fire(syntaxTreeUri);
11 }) 11 });
12 } 12 };
13} 13}
14 14
15// We need to order this after LS updates, but there's no API for that. 15// We need to order this after LS updates, but there's no API for that.
16// Hence, good old setTimeout. 16// Hence, good old setTimeout.
17function afterLs(f: () => any) { 17function afterLs(f: () => any) {
18 setTimeout(f, 10) 18 setTimeout(f, 10);
19} 19}
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts
index 595fb98fe..f1bc0b457 100644
--- a/editors/code/src/extension.ts
+++ b/editors/code/src/extension.ts
@@ -1,9 +1,9 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2 2
3import * as commands from './commands' 3import * as commands from './commands';
4import * as events from './events'
5import { Server } from './server';
6import { TextDocumentContentProvider } from './commands/syntaxTree'; 4import { TextDocumentContentProvider } from './commands/syntaxTree';
5import * as events from './events';
6import { Server } from './server';
7 7
8export function activate(context: vscode.ExtensionContext) { 8export function activate(context: vscode.ExtensionContext) {
9 function disposeOnDeactivation(disposable: vscode.Disposable) { 9 function disposeOnDeactivation(disposable: vscode.Disposable) {
@@ -11,10 +11,10 @@ export function activate(context: vscode.ExtensionContext) {
11 } 11 }
12 12
13 function registerCommand(name: string, f: any) { 13 function registerCommand(name: string, f: any) {
14 disposeOnDeactivation(vscode.commands.registerCommand(name, f)) 14 disposeOnDeactivation(vscode.commands.registerCommand(name, f));
15 } 15 }
16 16
17 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle) 17 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle);
18 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle); 18 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle);
19 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle); 19 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);
20 registerCommand('ra-lsp.joinLines', commands.joinLines.handle); 20 registerCommand('ra-lsp.joinLines', commands.joinLines.handle);
@@ -22,19 +22,19 @@ export function activate(context: vscode.ExtensionContext) {
22 registerCommand('ra-lsp.run', commands.runnables.handle); 22 registerCommand('ra-lsp.run', commands.runnables.handle);
23 registerCommand('ra-lsp.applySourceChange', commands.applySourceChange.handle); 23 registerCommand('ra-lsp.applySourceChange', commands.applySourceChange.handle);
24 24
25 let textDocumentContentProvider = new TextDocumentContentProvider() 25 const textDocumentContentProvider = new TextDocumentContentProvider();
26 disposeOnDeactivation(vscode.workspace.registerTextDocumentContentProvider( 26 disposeOnDeactivation(vscode.workspace.registerTextDocumentContentProvider(
27 'ra-lsp', 27 'ra-lsp',
28 textDocumentContentProvider 28 textDocumentContentProvider,
29 )) 29 ));
30 30
31 Server.start() 31 Server.start();
32 32
33 vscode.workspace.onDidChangeTextDocument( 33 vscode.workspace.onDidChangeTextDocument(
34 events.changeTextDocument.createHandler(textDocumentContentProvider), 34 events.changeTextDocument.createHandler(textDocumentContentProvider),
35 null, 35 null,
36 context.subscriptions) 36 context.subscriptions);
37 vscode.window.onDidChangeActiveTextEditor(events.changeActiveTextEditor.handle) 37 vscode.window.onDidChangeActiveTextEditor(events.changeActiveTextEditor.handle);
38} 38}
39 39
40export function deactivate(): Thenable<void> { 40export function deactivate(): Thenable<void> {
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index 169ddb0df..71f8e5baa 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -1,11 +1,11 @@
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
6export interface Decoration { 6export interface Decoration {
7 range: lc.Range, 7 range: lc.Range;
8 tag: string, 8 tag: string;
9} 9}
10 10
11export class Highlighter { 11export class Highlighter {
@@ -14,17 +14,17 @@ export class Highlighter {
14 this.decorations = {}; 14 this.decorations = {};
15 } 15 }
16 16
17 removeHighlights() { 17 public removeHighlights() {
18 for (let tag in this.decorations) { 18 for (const tag in this.decorations) {
19 this.decorations[tag].dispose(); 19 this.decorations[tag].dispose();
20 } 20 }
21 21
22 this.decorations = {}; 22 this.decorations = {};
23 } 23 }
24 24
25 setHighlights( 25 public setHighlights(
26 editor: vscode.TextEditor, 26 editor: vscode.TextEditor,
27 highlights: Array<Decoration> 27 highlights: Decoration[],
28 ) { 28 ) {
29 // Initialize decorations if necessary 29 // Initialize decorations if necessary
30 // 30 //
@@ -34,45 +34,45 @@ export class Highlighter {
34 this.initDecorations(); 34 this.initDecorations();
35 } 35 }
36 36
37 let byTag: Map<string, vscode.Range[]> = new Map() 37 const byTag: Map<string, vscode.Range[]> = new Map();
38 for (let tag in this.decorations) { 38 for (const tag in this.decorations) {
39 byTag.set(tag, []) 39 byTag.set(tag, []);
40 } 40 }
41 41
42 for (let d of highlights) { 42 for (const d of highlights) {
43 if (!byTag.get(d.tag)) { 43 if (!byTag.get(d.tag)) {
44 console.log(`unknown tag ${d.tag}`) 44 console.log(`unknown tag ${d.tag}`);
45 continue 45 continue;
46 } 46 }
47 byTag.get(d.tag)!.push( 47 byTag.get(d.tag)!.push(
48 Server.client.protocol2CodeConverter.asRange(d.range) 48 Server.client.protocol2CodeConverter.asRange(d.range),
49 ) 49 );
50 } 50 }
51 51
52 for (let tag of byTag.keys()) { 52 for (const tag of byTag.keys()) {
53 let dec: vscode.TextEditorDecorationType = this.decorations[tag] 53 const dec: vscode.TextEditorDecorationType = this.decorations[tag];
54 let ranges = byTag.get(tag)! 54 const ranges = byTag.get(tag)!;
55 editor.setDecorations(dec, ranges) 55 editor.setDecorations(dec, ranges);
56 } 56 }
57 } 57 }
58 58
59 private initDecorations() { 59 private initDecorations() {
60 const decor = (obj: any) => vscode.window.createTextEditorDecorationType({ color: obj }) 60 const decor = (obj: any) => vscode.window.createTextEditorDecorationType({ color: obj });
61 this.decorations = { 61 this.decorations = {
62 background: decor("#3F3F3F"), 62 background: decor('#3F3F3F'),
63 error: vscode.window.createTextEditorDecorationType({ 63 error: vscode.window.createTextEditorDecorationType({
64 borderColor: "red", 64 borderColor: 'red',
65 borderStyle: "none none dashed none", 65 borderStyle: 'none none dashed none',
66 }), 66 }),
67 comment: decor("#7F9F7F"), 67 comment: decor('#7F9F7F'),
68 string: decor("#CC9393"), 68 string: decor('#CC9393'),
69 keyword: decor("#F0DFAF"), 69 keyword: decor('#F0DFAF'),
70 function: decor("#93E0E3"), 70 function: decor('#93E0E3'),
71 parameter: decor("#94BFF3"), 71 parameter: decor('#94BFF3'),
72 builtin: decor("#DD6718"), 72 builtin: decor('#DD6718'),
73 text: decor("#DCDCCC"), 73 text: decor('#DCDCCC'),
74 attribute: decor("#BFEBBF"), 74 attribute: decor('#BFEBBF'),
75 literal: decor("#DFAF8F"), 75 literal: decor('#DFAF8F'),
76 } 76 };
77 } 77 }
78} 78}
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts
index c1c95e008..3857b00a5 100644
--- a/editors/code/src/server.ts
+++ b/editors/code/src/server.ts
@@ -1,45 +1,25 @@
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 { Highlighter, Decoration } from './highlighting'; 4import { Config } from './config';
5 5import { Decoration, Highlighter } from './highlighting';
6export class Config {
7 highlightingOn = true;
8
9 constructor() {
10 vscode.workspace.onDidChangeConfiguration(_ => this.userConfigChanged());
11 this.userConfigChanged();
12 }
13
14 userConfigChanged() {
15 let config = vscode.workspace.getConfiguration('ra-lsp');
16 if (config.has('highlightingOn')) {
17 this.highlightingOn = config.get('highlightingOn') as boolean;
18 };
19
20 if (!this.highlightingOn) {
21 Server.highlighter.removeHighlights();
22 }
23 }
24}
25 6
26export class Server { 7export class Server {
27 static highlighter = new Highlighter(); 8 public static highlighter = new Highlighter();
28 static config = new Config(); 9 public static config = new Config();
29 static client: lc.LanguageClient; 10 public static client: lc.LanguageClient;
30 11
31 12 public static start() {
32 static start() { 13 const run: lc.Executable = {
33 let run: lc.Executable = { 14 command: 'ra_lsp_server',
34 command: "ra_lsp_server", 15 options: { cwd: '.' },
35 options: { cwd: "." } 16 };
36 } 17 const serverOptions: lc.ServerOptions = {
37 let serverOptions: lc.ServerOptions = {
38 run, 18 run,
39 debug: run 19 debug: run,
40 }; 20 };
41 21
42 let clientOptions: lc.LanguageClientOptions = { 22 const clientOptions: lc.LanguageClientOptions = {
43 documentSelector: [{ scheme: 'file', language: 'rust' }], 23 documentSelector: [{ scheme: 'file', language: 'rust' }],
44 }; 24 };
45 25
@@ -51,24 +31,24 @@ export class Server {
51 ); 31 );
52 Server.client.onReady().then(() => { 32 Server.client.onReady().then(() => {
53 Server.client.onNotification( 33 Server.client.onNotification(
54 "m/publishDecorations", 34 'm/publishDecorations',
55 (params: PublishDecorationsParams) => { 35 (params: PublishDecorationsParams) => {
56 let editor = vscode.window.visibleTextEditors.find( 36 const targetEditor = vscode.window.visibleTextEditors.find(
57 (editor) => editor.document.uri.toString() == params.uri 37 (editor) => editor.document.uri.toString() == params.uri,
58 ) 38 );
59 if (!Server.config.highlightingOn || !editor) return; 39 if (!Server.config.highlightingOn || !targetEditor) { return; }
60 Server.highlighter.setHighlights( 40 Server.highlighter.setHighlights(
61 editor, 41 targetEditor,
62 params.decorations, 42 params.decorations,
63 ) 43 );
64 } 44 },
65 ) 45 );
66 }) 46 });
67 Server.client.start(); 47 Server.client.start();
68 } 48 }
69} 49}
70 50
71interface PublishDecorationsParams { 51interface PublishDecorationsParams {
72 uri: string, 52 uri: string;
73 decorations: Decoration[], 53 decorations: Decoration[];
74} 54}
diff --git a/editors/code/tslint.json b/editors/code/tslint.json
new file mode 100644
index 000000000..466e1fa20
--- /dev/null
+++ b/editors/code/tslint.json
@@ -0,0 +1,13 @@
1{
2 "defaultSeverity": "warning",
3 "extends": [
4 "tslint:recommended"
5 ],
6 "jsRules": {},
7 "rules": {
8 "quotemark": [true, "single"],
9 "interface-name": false,
10 "object-literal-sort-keys": false
11 },
12 "rulesDirectory": []
13}