1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';
import { Config } from './config';
import { Decoration, Highlighter } from './highlighting';
export class Server {
public static highlighter = new Highlighter();
public static config = new Config();
public static client: lc.LanguageClient;
public static start() {
const run: lc.Executable = {
command: 'ra_lsp_server',
options: { cwd: '.' },
};
const serverOptions: lc.ServerOptions = {
run,
debug: run,
};
const clientOptions: lc.LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'rust' }],
};
Server.client = new lc.LanguageClient(
'ra-lsp',
'rust-analyzer languge server',
serverOptions,
clientOptions,
);
Server.client.onReady().then(() => {
Server.client.onNotification(
'm/publishDecorations',
(params: PublishDecorationsParams) => {
const targetEditor = vscode.window.visibleTextEditors.find(
(editor) => editor.document.uri.toString() === params.uri,
);
if (!Server.config.highlightingOn || !targetEditor) { return; }
Server.highlighter.setHighlights(
targetEditor,
params.decorations,
);
},
);
});
Server.client.start();
}
}
interface PublishDecorationsParams {
uri: string;
decorations: Decoration[];
}
|