aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/server.ts
blob: 01fd80756fd394da9a3bf5715c2256bd8abcd6a8 (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
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' }],
        };

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