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