]> git.lizzy.rs Git - rust.git/blob - editors/code/src/client.ts
Remove dead code
[rust.git] / editors / code / src / client.ts
1 import * as lc from 'vscode-languageclient';
2 import * as vscode from 'vscode';
3
4 import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
5 import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed';
6
7 export async function createClient(serverPath: string, cwd: string): Promise<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.
11
12     const run: lc.Executable = {
13         command: serverPath,
14         options: { cwd },
15     };
16     const serverOptions: lc.ServerOptions = {
17         run,
18         debug: run,
19     };
20     const traceOutputChannel = vscode.window.createOutputChannel(
21         'Rust Analyzer Language Server Trace',
22     );
23
24     const clientOptions: lc.LanguageClientOptions = {
25         documentSelector: [{ scheme: 'file', language: 'rust' }],
26         initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
27         traceOutputChannel,
28         middleware: {
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');
33                 return res;
34             }
35         } as any
36     };
37
38     const res = new lc.LanguageClient(
39         'rust-analyzer',
40         'Rust Analyzer Language Server',
41         serverOptions,
42         clientOptions,
43     );
44
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));
52
53     return res;
54 }