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';
|
2018-10-08 13:55:22 -05:00
|
|
|
import { 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;
|
|
|
|
|
2018-10-08 16:38:33 -05:00
|
|
|
public static start(
|
|
|
|
notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>
|
|
|
|
) {
|
2018-10-07 15:59:02 -05:00
|
|
|
const run: lc.Executable = {
|
2019-01-05 09:28:41 -06:00
|
|
|
command: this.config.raLspServerPath,
|
2018-10-08 16:38:33 -05:00
|
|
|
options: { cwd: '.' }
|
2018-10-07 15:59:02 -05:00
|
|
|
};
|
|
|
|
const serverOptions: lc.ServerOptions = {
|
2018-10-07 15:44:25 -05:00
|
|
|
run,
|
2018-10-08 16:38:33 -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-11-08 09:43:02 -06:00
|
|
|
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
|
|
|
initializationOptions: {
|
2018-12-24 07:43:08 -06:00
|
|
|
publishDecorations: true
|
2018-11-08 09:43:02 -06:00
|
|
|
}
|
2018-10-07 15:44:25 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
Server.client = new lc.LanguageClient(
|
|
|
|
'ra-lsp',
|
2018-10-21 14:39:50 -05:00
|
|
|
'rust-analyzer language server',
|
2018-10-07 15:44:25 -05:00
|
|
|
serverOptions,
|
2018-10-08 16:38:33 -05:00
|
|
|
clientOptions
|
2018-10-07 15:44:25 -05:00
|
|
|
);
|
2018-12-24 07:43:08 -06:00
|
|
|
// HACK: This is an awful way of filtering out the decorations notifications
|
|
|
|
// However, pending proper support, this is the most effecitve approach
|
|
|
|
// Proper support for this would entail a change to vscode-languageclient to allow not notifying on certain messages
|
|
|
|
// Or the ability to disable the serverside component of highlighting (but this means that to do tracing we need to disable hihlighting)
|
|
|
|
// This also requires considering our settings strategy, which is work which needs doing
|
|
|
|
// @ts-ignore The tracer is private to vscode-languageclient, but we need access to it to not log publishDecorations requests
|
|
|
|
Server.client._tracer = {
|
|
|
|
log: (messageOrDataObject: string | any, data?: string) => {
|
|
|
|
if (typeof messageOrDataObject === 'string') {
|
|
|
|
if (
|
|
|
|
messageOrDataObject.includes('m/publishDecorations') ||
|
|
|
|
messageOrDataObject.includes('m/decorationsRequest')
|
|
|
|
) {
|
|
|
|
// Don't log publish decorations requests
|
|
|
|
} else {
|
|
|
|
// @ts-ignore This is just a utility function
|
|
|
|
Server.client.logTrace(messageOrDataObject, data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// @ts-ignore
|
|
|
|
Server.client.logObjectTrace(messageOrDataObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-10-07 15:44:25 -05:00
|
|
|
Server.client.onReady().then(() => {
|
2018-10-08 13:55:22 -05:00
|
|
|
for (const [type, handler] of notificationHandlers) {
|
|
|
|
Server.client.onNotification(type, handler);
|
|
|
|
}
|
2018-10-07 15:59:02 -05:00
|
|
|
});
|
2018-10-07 15:44:25 -05:00
|
|
|
Server.client.start();
|
|
|
|
}
|
|
|
|
}
|