aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/client.ts
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-31 17:38:55 +0000
committerGitHub <[email protected]>2019-12-31 17:38:55 +0000
commit6d23140ba03c77b28d94e042c94155899baba9da (patch)
tree3efa5daf54fe08cd1b310fa42c2ef469503fcedd /editors/code/src/client.ts
parent1327aed7f6289043091aa9179282030c6f13ddbe (diff)
parent6368b40dd98b208da3758d4d1eed34cf276e3b09 (diff)
Merge #2709
2709: Work around synchrnonisation issue r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code/src/client.ts')
-rw-r--r--editors/code/src/client.ts90
1 files changed, 90 insertions, 0 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
new file mode 100644
index 000000000..94948b10f
--- /dev/null
+++ b/editors/code/src/client.ts
@@ -0,0 +1,90 @@
1import { homedir } from 'os';
2import * as lc from 'vscode-languageclient';
3
4import { window, workspace } from 'vscode';
5import { Config } from './config';
6
7export function createClient(config: Config): lc.LanguageClient {
8 // '.' Is the fallback if no folder is open
9 // TODO?: Workspace folders support Uri's (eg: file://test.txt). It might be a good idea to test if the uri points to a file.
10 let folder: string = '.';
11 if (workspace.workspaceFolders !== undefined) {
12 folder = workspace.workspaceFolders[0].uri.fsPath.toString();
13 }
14
15 const command = expandPathResolving(config.raLspServerPath);
16 const run: lc.Executable = {
17 command,
18 options: { cwd: folder },
19 };
20 const serverOptions: lc.ServerOptions = {
21 run,
22 debug: run,
23 };
24 const traceOutputChannel = window.createOutputChannel(
25 'Rust Analyzer Language Server Trace',
26 );
27 const clientOptions: lc.LanguageClientOptions = {
28 documentSelector: [{ scheme: 'file', language: 'rust' }],
29 initializationOptions: {
30 publishDecorations: true,
31 lruCapacity: config.lruCapacity,
32 maxInlayHintLength: config.maxInlayHintLength,
33 cargoWatchEnable: config.cargoWatchOptions.enable,
34 cargoWatchArgs: config.cargoWatchOptions.arguments,
35 cargoWatchCommand: config.cargoWatchOptions.command,
36 cargoWatchAllTargets:
37 config.cargoWatchOptions.allTargets,
38 excludeGlobs: config.excludeGlobs,
39 useClientWatching: config.useClientWatching,
40 featureFlags: config.featureFlags,
41 withSysroot: config.withSysroot,
42 cargoFeatures: config.cargoFeatures,
43 },
44 traceOutputChannel,
45 };
46
47 const res = new lc.LanguageClient(
48 'rust-analyzer',
49 'Rust Analyzer Language Server',
50 serverOptions,
51 clientOptions,
52 );
53
54 // HACK: This is an awful way of filtering out the decorations notifications
55 // However, pending proper support, this is the most effecitve approach
56 // Proper support for this would entail a change to vscode-languageclient to allow not notifying on certain messages
57 // Or the ability to disable the serverside component of highlighting (but this means that to do tracing we need to disable hihlighting)
58 // This also requires considering our settings strategy, which is work which needs doing
59 // @ts-ignore The tracer is private to vscode-languageclient, but we need access to it to not log publishDecorations requests
60 res._tracer = {
61 log: (messageOrDataObject: string | any, data?: string) => {
62 if (typeof messageOrDataObject === 'string') {
63 if (
64 messageOrDataObject.includes(
65 'rust-analyzer/publishDecorations',
66 ) ||
67 messageOrDataObject.includes(
68 'rust-analyzer/decorationsRequest',
69 )
70 ) {
71 // Don't log publish decorations requests
72 } else {
73 // @ts-ignore This is just a utility function
74 res.logTrace(messageOrDataObject, data);
75 }
76 } else {
77 // @ts-ignore
78 res.logObjectTrace(messageOrDataObject);
79 }
80 },
81 };
82 res.registerProposedFeatures()
83 return res;
84}
85function expandPathResolving(path: string) {
86 if (path.startsWith('~/')) {
87 return path.replace('~', homedir());
88 }
89 return path;
90}