diff options
Diffstat (limited to 'editors/code/src/server.ts')
-rw-r--r-- | editors/code/src/server.ts | 74 |
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 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient' | 2 | import * as lc from 'vscode-languageclient'; |
3 | 3 | ||
4 | import { Highlighter, Decoration } from './highlighting'; | 4 | import { Config } from './config'; |
5 | 5 | import { Decoration, Highlighter } from './highlighting'; | |
6 | export 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 | ||
26 | export class Server { | 7 | export 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 | ||
71 | interface PublishDecorationsParams { | 51 | interface PublishDecorationsParams { |
72 | uri: string, | 52 | uri: string; |
73 | decorations: Decoration[], | 53 | decorations: Decoration[]; |
74 | } | 54 | } |