diff options
Diffstat (limited to 'editors/code/src/server.ts')
-rw-r--r-- | editors/code/src/server.ts | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts deleted file mode 100644 index 5ace1d0fa..000000000 --- a/editors/code/src/server.ts +++ /dev/null | |||
@@ -1,109 +0,0 @@ | |||
1 | import { lookpath } from 'lookpath'; | ||
2 | import { homedir, platform } from 'os'; | ||
3 | import * as lc from 'vscode-languageclient'; | ||
4 | |||
5 | import { window, workspace } from 'vscode'; | ||
6 | import { Config } from './config'; | ||
7 | import { Highlighter } from './highlighting'; | ||
8 | |||
9 | function expandPathResolving(path: string) { | ||
10 | if (path.startsWith('~/')) { | ||
11 | return path.replace('~', homedir()); | ||
12 | } | ||
13 | return path; | ||
14 | } | ||
15 | |||
16 | export class Server { | ||
17 | public static highlighter = new Highlighter(); | ||
18 | public static config = new Config(); | ||
19 | public static client: lc.LanguageClient; | ||
20 | |||
21 | public static async start( | ||
22 | notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>, | ||
23 | ) { | ||
24 | // '.' Is the fallback if no folder is open | ||
25 | // 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. | ||
26 | let folder: string = '.'; | ||
27 | if (workspace.workspaceFolders !== undefined) { | ||
28 | folder = workspace.workspaceFolders[0].uri.fsPath.toString(); | ||
29 | } | ||
30 | |||
31 | const command = expandPathResolving(this.config.raLspServerPath); | ||
32 | // FIXME: remove check when the following issue is fixed: | ||
33 | // https://github.com/otiai10/lookpath/issues/4 | ||
34 | if (platform() !== 'win32') { | ||
35 | if (!(await lookpath(command))) { | ||
36 | throw new Error( | ||
37 | `Cannot find rust-analyzer server \`${command}\` in PATH.`, | ||
38 | ); | ||
39 | } | ||
40 | } | ||
41 | const run: lc.Executable = { | ||
42 | command, | ||
43 | options: { cwd: folder }, | ||
44 | }; | ||
45 | const serverOptions: lc.ServerOptions = { | ||
46 | run, | ||
47 | debug: run, | ||
48 | }; | ||
49 | const traceOutputChannel = window.createOutputChannel( | ||
50 | 'Rust Analyzer Language Server Trace', | ||
51 | ); | ||
52 | const clientOptions: lc.LanguageClientOptions = { | ||
53 | documentSelector: [{ scheme: 'file', language: 'rust' }], | ||
54 | initializationOptions: { | ||
55 | publishDecorations: true, | ||
56 | lruCapacity: Server.config.lruCapacity, | ||
57 | maxInlayHintLength: Server.config.maxInlayHintLength, | ||
58 | excludeGlobs: Server.config.excludeGlobs, | ||
59 | useClientWatching: Server.config.useClientWatching, | ||
60 | featureFlags: Server.config.featureFlags, | ||
61 | withSysroot: Server.config.withSysroot, | ||
62 | cargoFeatures: Server.config.cargoFeatures, | ||
63 | }, | ||
64 | traceOutputChannel, | ||
65 | }; | ||
66 | |||
67 | Server.client = new lc.LanguageClient( | ||
68 | 'rust-analyzer', | ||
69 | 'Rust Analyzer Language Server', | ||
70 | serverOptions, | ||
71 | clientOptions, | ||
72 | ); | ||
73 | // HACK: This is an awful way of filtering out the decorations notifications | ||
74 | // However, pending proper support, this is the most effecitve approach | ||
75 | // Proper support for this would entail a change to vscode-languageclient to allow not notifying on certain messages | ||
76 | // Or the ability to disable the serverside component of highlighting (but this means that to do tracing we need to disable hihlighting) | ||
77 | // This also requires considering our settings strategy, which is work which needs doing | ||
78 | // @ts-ignore The tracer is private to vscode-languageclient, but we need access to it to not log publishDecorations requests | ||
79 | Server.client._tracer = { | ||
80 | log: (messageOrDataObject: string | any, data?: string) => { | ||
81 | if (typeof messageOrDataObject === 'string') { | ||
82 | if ( | ||
83 | messageOrDataObject.includes( | ||
84 | 'rust-analyzer/publishDecorations', | ||
85 | ) || | ||
86 | messageOrDataObject.includes( | ||
87 | 'rust-analyzer/decorationsRequest', | ||
88 | ) | ||
89 | ) { | ||
90 | // Don't log publish decorations requests | ||
91 | } else { | ||
92 | // @ts-ignore This is just a utility function | ||
93 | Server.client.logTrace(messageOrDataObject, data); | ||
94 | } | ||
95 | } else { | ||
96 | // @ts-ignore | ||
97 | Server.client.logObjectTrace(messageOrDataObject); | ||
98 | } | ||
99 | }, | ||
100 | }; | ||
101 | Server.client.registerProposedFeatures(); | ||
102 | Server.client.onReady().then(() => { | ||
103 | for (const [type, handler] of notificationHandlers) { | ||
104 | Server.client.onNotification(type, handler); | ||
105 | } | ||
106 | }); | ||
107 | Server.client.start(); | ||
108 | } | ||
109 | } | ||