aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/server.ts
blob: 75e273f3739164cd34ab244db0f55b0de762aa14 (plain)
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
import * as lc from 'vscode-languageclient';

import { Config } from './config';
import { Highlighter } from './highlighting';

export class Server {
    public static highlighter = new Highlighter();
    public static config = new Config();
    public static client: lc.LanguageClient;

    public static start(
        notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>
    ) {
        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' }],
            initializationOptions: {
                publishDecorations: true,
            }
        };

        Server.client = new lc.LanguageClient(
            'ra-lsp',
            'rust-analyzer language server',
            serverOptions,
            clientOptions
        );
        Server.client.onReady().then(() => {
            for (const [type, handler] of notificationHandlers) {
                Server.client.onNotification(type, handler);
            }
        });
        Server.client.start();
    }
}