2018-10-07 15:44:25 -05:00
|
|
|
import * as vscode from 'vscode';
|
2018-10-07 15:59:02 -05:00
|
|
|
import * as lc from 'vscode-languageclient';
|
2018-10-07 15:44:25 -05:00
|
|
|
|
2018-10-07 15:59:02 -05:00
|
|
|
import { Config } from './config';
|
|
|
|
import { Decoration, Highlighter } from './highlighting';
|
2018-10-07 15:44:25 -05:00
|
|
|
|
|
|
|
export class Server {
|
2018-10-07 15:59:02 -05:00
|
|
|
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 = {
|
2018-10-07 15:44:25 -05:00
|
|
|
run,
|
2018-10-07 15:59:02 -05:00
|
|
|
debug: run,
|
2018-10-07 15:44:25 -05:00
|
|
|
};
|
|
|
|
|
2018-10-07 15:59:02 -05:00
|
|
|
const clientOptions: lc.LanguageClientOptions = {
|
2018-10-07 15:44:25 -05:00
|
|
|
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(
|
2018-10-07 15:59:02 -05:00
|
|
|
'm/publishDecorations',
|
2018-10-07 15:44:25 -05:00
|
|
|
(params: PublishDecorationsParams) => {
|
2018-10-07 15:59:02 -05:00
|
|
|
const targetEditor = vscode.window.visibleTextEditors.find(
|
2018-10-08 13:18:55 -05:00
|
|
|
(editor) => editor.document.uri.toString() === params.uri,
|
2018-10-07 15:59:02 -05:00
|
|
|
);
|
|
|
|
if (!Server.config.highlightingOn || !targetEditor) { return; }
|
2018-10-07 15:44:25 -05:00
|
|
|
Server.highlighter.setHighlights(
|
2018-10-07 15:59:02 -05:00
|
|
|
targetEditor,
|
2018-10-07 15:44:25 -05:00
|
|
|
params.decorations,
|
2018-10-07 15:59:02 -05:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2018-10-07 15:44:25 -05:00
|
|
|
Server.client.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
interface PublishDecorationsParams {
|
2018-10-07 15:59:02 -05:00
|
|
|
uri: string;
|
|
|
|
decorations: Decoration[];
|
2018-10-07 15:44:25 -05:00
|
|
|
}
|