Adopt LS service/client that has common & node

This commit is contained in:
Martin Aeschlimann
2020-05-27 09:34:02 +02:00
parent d1a3e6ede6
commit 2d47826dac
9 changed files with 67 additions and 43 deletions

View File

@@ -4,10 +4,35 @@
*--------------------------------------------------------------------------------------------*/
import { getNodeFSRequestService } from './nodeFs';
import { ExtensionContext } from 'vscode';
import { startClient } from '../cssClient';
import { ExtensionContext, extensions } from 'vscode';
import { startClient, LanguageClientConstructor } from '../cssClient';
import { ServerOptions, TransportKind, LanguageClientOptions, LanguageClient } from 'vscode-languageclient/node';
// this method is called when vs code is activated
export function activate(context: ExtensionContext) {
startClient(context, { fs: getNodeFSRequestService() });
const clientMain = extensions.getExtension('vscode.css-language-features')?.packageJSON?.main;
const serverMain = clientMain?.replace('client', 'server').replace('cssClientMain', 'cssServerMain');
if (!serverMain) {
throw new Error('Unable to compute CSS server module path. Client: ' + clientMain);
}
const serverModule = context.asAbsolutePath(serverMain);
// The debug options for the server
const debugOptions = { execArgv: ['--nolazy', '--inspect=6044'] };
// If the extension is launch in debug mode the debug server options are use
// Otherwise the run options are used
const serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
};
const newLanguageClient: LanguageClientConstructor = (id: string, name: string, clientOptions: LanguageClientOptions) => {
return new LanguageClient(id, name, serverOptions, clientOptions);
};
startClient(context, newLanguageClient, { fs: getNodeFSRequestService() });
}