1 import * as lc from 'vscode-languageclient';
2 import * as vscode from 'vscode';
4 import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
5 import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed';
7 export function createClient(serverPath: string, cwd: string): lc.LanguageClient {
8 // '.' Is the fallback if no folder is open
9 // TODO?: Workspace folders support Uri's (eg: file://test.txt).
10 // It might be a good idea to test if the uri points to a file.
12 const run: lc.Executable = {
16 const serverOptions: lc.ServerOptions = {
20 const traceOutputChannel = vscode.window.createOutputChannel(
21 'Rust Analyzer Language Server Trace',
24 const clientOptions: lc.LanguageClientOptions = {
25 documentSelector: [{ scheme: 'file', language: 'rust' }],
26 initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
29 // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576
30 async provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken, next: DocumentSemanticsTokensSignature) {
31 const res = await next(document, token);
32 if (res === undefined) throw new Error('busy');
38 const res = new lc.LanguageClient(
40 'Rust Analyzer Language Server',
45 // To turn on all proposed features use: res.registerProposedFeatures();
46 // Here we want to enable CallHierarchyFeature and SemanticTokensFeature
47 // since they are available on stable.
48 // Note that while these features are stable in vscode their LSP protocol
49 // implementations are still in the "proposed" category for 3.16.
50 res.registerFeature(new CallHierarchyFeature(res));
51 res.registerFeature(new SemanticTokensFeature(res));