diff options
author | Aleksey Kladov <[email protected]> | 2019-12-31 17:14:00 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-31 17:32:17 +0000 |
commit | 087af54069d34eef5197e04d64ac322d9ee98085 (patch) | |
tree | 3a6e4b1884930c07bd800a771ffd777d7a866b11 /editors/code/src/server.ts | |
parent | 0849f7001cac6af93ce9e9356f8c21881bbe34c5 (diff) |
Refactor server lifecycle
Diffstat (limited to 'editors/code/src/server.ts')
-rw-r--r-- | editors/code/src/server.ts | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts deleted file mode 100644 index ab9f3bfa6..000000000 --- a/editors/code/src/server.ts +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | import { homedir } from 'os'; | ||
2 | import * as lc from 'vscode-languageclient'; | ||
3 | |||
4 | import { window, workspace } from 'vscode'; | ||
5 | import { Config } from './config'; | ||
6 | |||
7 | function expandPathResolving(path: string) { | ||
8 | if (path.startsWith('~/')) { | ||
9 | return path.replace('~', homedir()); | ||
10 | } | ||
11 | return path; | ||
12 | } | ||
13 | |||
14 | export class Server { | ||
15 | static config: Config; | ||
16 | public static client: lc.LanguageClient; | ||
17 | |||
18 | public static async start(config: Config) { | ||
19 | // '.' Is the fallback if no folder is open | ||
20 | // 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. | ||
21 | let folder: string = '.'; | ||
22 | if (workspace.workspaceFolders !== undefined) { | ||
23 | folder = workspace.workspaceFolders[0].uri.fsPath.toString(); | ||
24 | } | ||
25 | |||
26 | this.config = config; | ||
27 | const command = expandPathResolving(this.config.raLspServerPath); | ||
28 | const run: lc.Executable = { | ||
29 | command, | ||
30 | options: { cwd: folder }, | ||
31 | }; | ||
32 | const serverOptions: lc.ServerOptions = { | ||
33 | run, | ||
34 | debug: run, | ||
35 | }; | ||
36 | const traceOutputChannel = window.createOutputChannel( | ||
37 | 'Rust Analyzer Language Server Trace', | ||
38 | ); | ||
39 | const clientOptions: lc.LanguageClientOptions = { | ||
40 | documentSelector: [{ scheme: 'file', language: 'rust' }], | ||
41 | initializationOptions: { | ||
42 | publishDecorations: true, | ||
43 | lruCapacity: Server.config.lruCapacity, | ||
44 | maxInlayHintLength: Server.config.maxInlayHintLength, | ||
45 | cargoWatchEnable: Server.config.cargoWatchOptions.enable, | ||
46 | cargoWatchArgs: Server.config.cargoWatchOptions.arguments, | ||
47 | cargoWatchCommand: Server.config.cargoWatchOptions.command, | ||
48 | cargoWatchAllTargets: | ||
49 | Server.config.cargoWatchOptions.allTargets, | ||
50 | excludeGlobs: Server.config.excludeGlobs, | ||
51 | useClientWatching: Server.config.useClientWatching, | ||
52 | featureFlags: Server.config.featureFlags, | ||
53 | withSysroot: Server.config.withSysroot, | ||
54 | cargoFeatures: Server.config.cargoFeatures, | ||
55 | }, | ||
56 | traceOutputChannel, | ||
57 | }; | ||
58 | |||
59 | Server.client = new lc.LanguageClient( | ||
60 | 'rust-analyzer', | ||
61 | 'Rust Analyzer Language Server', | ||
62 | serverOptions, | ||
63 | clientOptions, | ||
64 | ); | ||
65 | // HACK: This is an awful way of filtering out the decorations notifications | ||
66 | // However, pending proper support, this is the most effecitve approach | ||
67 | // Proper support for this would entail a change to vscode-languageclient to allow not notifying on certain messages | ||
68 | // Or the ability to disable the serverside component of highlighting (but this means that to do tracing we need to disable hihlighting) | ||
69 | // This also requires considering our settings strategy, which is work which needs doing | ||
70 | // @ts-ignore The tracer is private to vscode-languageclient, but we need access to it to not log publishDecorations requests | ||
71 | Server.client._tracer = { | ||
72 | log: (messageOrDataObject: string | any, data?: string) => { | ||
73 | if (typeof messageOrDataObject === 'string') { | ||
74 | if ( | ||
75 | messageOrDataObject.includes( | ||
76 | 'rust-analyzer/publishDecorations', | ||
77 | ) || | ||
78 | messageOrDataObject.includes( | ||
79 | 'rust-analyzer/decorationsRequest', | ||
80 | ) | ||
81 | ) { | ||
82 | // Don't log publish decorations requests | ||
83 | } else { | ||
84 | // @ts-ignore This is just a utility function | ||
85 | Server.client.logTrace(messageOrDataObject, data); | ||
86 | } | ||
87 | } else { | ||
88 | // @ts-ignore | ||
89 | Server.client.logObjectTrace(messageOrDataObject); | ||
90 | } | ||
91 | }, | ||
92 | }; | ||
93 | Server.client.registerProposedFeatures(); | ||
94 | Server.client.start(); | ||
95 | } | ||
96 | } | ||