Add some comments

This commit is contained in:
Adolfo Ochagavía 2018-10-08 20:55:22 +02:00
parent 62b1b05a0d
commit bbf38b9e72
4 changed files with 44 additions and 25 deletions

View file

@ -1,15 +1,14 @@
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';
import { Config } from './config';
import { Decoration, Highlighter } from './highlighting';
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() {
public static start(notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>) {
const run: lc.Executable = {
command: 'ra_lsp_server',
options: { cwd: '.' },
@ -18,7 +17,6 @@ export class Server {
run,
debug: run,
};
const clientOptions: lc.LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'rust' }],
};
@ -30,25 +28,10 @@ export class Server {
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,
);
},
);
for (const [type, handler] of notificationHandlers) {
Server.client.onNotification(type, handler);
}
});
Server.client.start();
}
}
interface PublishDecorationsParams {
uri: string;
decorations: Decoration[];
}