aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/server.ts
diff options
context:
space:
mode:
authorAdolfo OchagavĂ­a <[email protected]>2018-10-07 21:59:02 +0100
committerAdolfo OchagavĂ­a <[email protected]>2018-10-07 22:12:40 +0100
commit4d62cfccbb8281f33b6f894df07e7316a9d45bfb (patch)
tree56ad69cb2f5c1096a2a74cfa078b92c40fe902e1 /editors/code/src/server.ts
parent69de7e2fd71c3a808f0ac856d7b105eeb210f169 (diff)
Apply tslint suggestions, round one
Diffstat (limited to 'editors/code/src/server.ts')
-rw-r--r--editors/code/src/server.ts74
1 files changed, 27 insertions, 47 deletions
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}