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.ts39
1 files changed, 26 insertions, 13 deletions
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts
index 7907b70bc..5ace1d0fa 100644
--- a/editors/code/src/server.ts
+++ b/editors/code/src/server.ts
@@ -1,4 +1,5 @@
1import { homedir } from 'os'; 1import { lookpath } from 'lookpath';
2import { homedir, platform } from 'os';
2import * as lc from 'vscode-languageclient'; 3import * as lc from 'vscode-languageclient';
3 4
4import { window, workspace } from 'vscode'; 5import { window, workspace } from 'vscode';
@@ -17,8 +18,8 @@ export class Server {
17 public static config = new Config(); 18 public static config = new Config();
18 public static client: lc.LanguageClient; 19 public static client: lc.LanguageClient;
19 20
20 public static start( 21 public static async start(
21 notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]> 22 notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>,
22 ) { 23 ) {
23 // '.' Is the fallback if no folder is open 24 // '.' Is the fallback if no folder is open
24 // 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. 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.
@@ -27,16 +28,26 @@ export class Server {
27 folder = workspace.workspaceFolders[0].uri.fsPath.toString(); 28 folder = workspace.workspaceFolders[0].uri.fsPath.toString();
28 } 29 }
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 }
30 const run: lc.Executable = { 41 const run: lc.Executable = {
31 command: expandPathResolving(this.config.raLspServerPath), 42 command,
32 options: { cwd: folder } 43 options: { cwd: folder },
33 }; 44 };
34 const serverOptions: lc.ServerOptions = { 45 const serverOptions: lc.ServerOptions = {
35 run, 46 run,
36 debug: run 47 debug: run,
37 }; 48 };
38 const traceOutputChannel = window.createOutputChannel( 49 const traceOutputChannel = window.createOutputChannel(
39 'Rust Analyzer Language Server Trace' 50 'Rust Analyzer Language Server Trace',
40 ); 51 );
41 const clientOptions: lc.LanguageClientOptions = { 52 const clientOptions: lc.LanguageClientOptions = {
42 documentSelector: [{ scheme: 'file', language: 'rust' }], 53 documentSelector: [{ scheme: 'file', language: 'rust' }],
@@ -46,16 +57,18 @@ export class Server {
46 maxInlayHintLength: Server.config.maxInlayHintLength, 57 maxInlayHintLength: Server.config.maxInlayHintLength,
47 excludeGlobs: Server.config.excludeGlobs, 58 excludeGlobs: Server.config.excludeGlobs,
48 useClientWatching: Server.config.useClientWatching, 59 useClientWatching: Server.config.useClientWatching,
49 featureFlags: Server.config.featureFlags 60 featureFlags: Server.config.featureFlags,
61 withSysroot: Server.config.withSysroot,
62 cargoFeatures: Server.config.cargoFeatures,
50 }, 63 },
51 traceOutputChannel 64 traceOutputChannel,
52 }; 65 };
53 66
54 Server.client = new lc.LanguageClient( 67 Server.client = new lc.LanguageClient(
55 'rust-analyzer', 68 'rust-analyzer',
56 'Rust Analyzer Language Server', 69 'Rust Analyzer Language Server',
57 serverOptions, 70 serverOptions,
58 clientOptions 71 clientOptions,
59 ); 72 );
60 // HACK: This is an awful way of filtering out the decorations notifications 73 // HACK: This is an awful way of filtering out the decorations notifications
61 // However, pending proper support, this is the most effecitve approach 74 // However, pending proper support, this is the most effecitve approach
@@ -68,10 +81,10 @@ export class Server {
68 if (typeof messageOrDataObject === 'string') { 81 if (typeof messageOrDataObject === 'string') {
69 if ( 82 if (
70 messageOrDataObject.includes( 83 messageOrDataObject.includes(
71 'rust-analyzer/publishDecorations' 84 'rust-analyzer/publishDecorations',
72 ) || 85 ) ||
73 messageOrDataObject.includes( 86 messageOrDataObject.includes(
74 'rust-analyzer/decorationsRequest' 87 'rust-analyzer/decorationsRequest',
75 ) 88 )
76 ) { 89 ) {
77 // Don't log publish decorations requests 90 // Don't log publish decorations requests
@@ -83,7 +96,7 @@ export class Server {
83 // @ts-ignore 96 // @ts-ignore
84 Server.client.logObjectTrace(messageOrDataObject); 97 Server.client.logObjectTrace(messageOrDataObject);
85 } 98 }
86 } 99 },
87 }; 100 };
88 Server.client.registerProposedFeatures(); 101 Server.client.registerProposedFeatures();
89 Server.client.onReady().then(() => { 102 Server.client.onReady().then(() => {