diff options
author | Laurențiu Nicola <[email protected]> | 2019-12-08 12:41:44 +0000 |
---|---|---|
committer | Laurențiu Nicola <[email protected]> | 2019-12-08 13:04:37 +0000 |
commit | 78e8934976fa3135c151d2b6b395ce57e832f90e (patch) | |
tree | 90fc53ceb5c911a9d1cb00c9a62d908695a8afed | |
parent | b236f6aa499f98985acd07a34eb0c0d147bf8d5f (diff) |
Code: check whether the LSP binary is in PATH
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | docs/user/README.md | 17 | ||||
-rw-r--r-- | editors/code/package-lock.json | 5 | ||||
-rw-r--r-- | editors/code/package.json | 1 | ||||
-rw-r--r-- | editors/code/src/extension.ts | 12 | ||||
-rw-r--r-- | editors/code/src/server.ts | 11 |
6 files changed, 41 insertions, 8 deletions
@@ -37,7 +37,8 @@ $ cargo xtask install | |||
37 | $ cargo xtask install --server | 37 | $ cargo xtask install --server |
38 | ``` | 38 | ``` |
39 | 39 | ||
40 | For non-standard setup of VS Code and other editors, see [./docs/user](./docs/user). | 40 | For non-standard setup of VS Code and other editors, or if the language server |
41 | cannot start, see [./docs/user](./docs/user). | ||
41 | 42 | ||
42 | ## Documentation | 43 | ## Documentation |
43 | 44 | ||
diff --git a/docs/user/README.md b/docs/user/README.md index 5ec8fb25d..04c349342 100644 --- a/docs/user/README.md +++ b/docs/user/README.md | |||
@@ -204,4 +204,19 @@ Installation: | |||
204 | 204 | ||
205 | * You can now invoke the command palette and type LSP enable to locally/globally enable the rust-analyzer LSP (type LSP enable, then choose either locally or globally, then select rust-analyzer) | 205 | * You can now invoke the command palette and type LSP enable to locally/globally enable the rust-analyzer LSP (type LSP enable, then choose either locally or globally, then select rust-analyzer) |
206 | 206 | ||
207 | * Note that `ra_lsp_server` binary must be in `$PATH` for this to work. If it's not the case, you can specify full path to the binary, which is typically `.cargo/bin/ra_lsp_server`. | 207 | ### Setting up the `PATH` variable |
208 | |||
209 | On Unix systems, `rustup` adds `~/.cargo/bin` to `PATH` by modifying the shell's | ||
210 | startup file. Depending on your configuration, your Desktop Environment might not | ||
211 | actually load it. If you find that `rust-analyzer` only runs when starting the | ||
212 | editor from the terminal, you will have to set up your `PATH` variable manually. | ||
213 | |||
214 | There are a couple of ways to do that: | ||
215 | |||
216 | - for Code, set `rust-analyzer.raLspServerPath` to `~/.cargo/bin` (the `~` is | ||
217 | automatically resolved by the extension) | ||
218 | - copy the binary to a location that is already in `PATH`, e.g. `/usr/local/bin` | ||
219 | - on Linux, use PAM to configure the `PATH` variable, by e.g. putting | ||
220 | `PATH DEFAULT=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:@{HOME}/.cargo/bin:@{HOME}/.local/bin` | ||
221 | in your `~/.pam_environment` file; note that this might interfere with other | ||
222 | defaults set by the system administrator via `/etc/environment`. | ||
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json index 2ceac60a0..099aaaaa2 100644 --- a/editors/code/package-lock.json +++ b/editors/code/package-lock.json | |||
@@ -763,6 +763,11 @@ | |||
763 | "chalk": "^2.0.1" | 763 | "chalk": "^2.0.1" |
764 | } | 764 | } |
765 | }, | 765 | }, |
766 | "lookpath": { | ||
767 | "version": "1.0.3", | ||
768 | "resolved": "https://registry.npmjs.org/lookpath/-/lookpath-1.0.3.tgz", | ||
769 | "integrity": "sha512-XIdgzlX26g10XnzyZdO/4obybEmfGnZyWQZ2DgmmEfVB79X+n3lhUoIzMe501C6s7RmCpAo66OPegWc+CsxYMg==" | ||
770 | }, | ||
766 | "magic-string": { | 771 | "magic-string": { |
767 | "version": "0.25.3", | 772 | "version": "0.25.3", |
768 | "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.3.tgz", | 773 | "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.3.tgz", |
diff --git a/editors/code/package.json b/editors/code/package.json index 94887674b..5dea8fac0 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -31,6 +31,7 @@ | |||
31 | "singleQuote": true | 31 | "singleQuote": true |
32 | }, | 32 | }, |
33 | "dependencies": { | 33 | "dependencies": { |
34 | "lookpath": "^1.0.3", | ||
34 | "seedrandom": "^3.0.1", | 35 | "seedrandom": "^3.0.1", |
35 | "vscode-languageclient": "^5.3.0-next.4" | 36 | "vscode-languageclient": "^5.3.0-next.4" |
36 | }, | 37 | }, |
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 683497dfd..6637c3bf0 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts | |||
@@ -14,7 +14,7 @@ import * as events from './events'; | |||
14 | import * as notifications from './notifications'; | 14 | import * as notifications from './notifications'; |
15 | import { Server } from './server'; | 15 | import { Server } from './server'; |
16 | 16 | ||
17 | export function activate(context: vscode.ExtensionContext) { | 17 | export async function activate(context: vscode.ExtensionContext) { |
18 | function disposeOnDeactivation(disposable: vscode.Disposable) { | 18 | function disposeOnDeactivation(disposable: vscode.Disposable) { |
19 | context.subscriptions.push(disposable); | 19 | context.subscriptions.push(disposable); |
20 | } | 20 | } |
@@ -159,7 +159,11 @@ export function activate(context: vscode.ExtensionContext) { | |||
159 | }); | 159 | }); |
160 | 160 | ||
161 | // Start the language server, finally! | 161 | // Start the language server, finally! |
162 | startServer(); | 162 | try { |
163 | await startServer(); | ||
164 | } catch (e) { | ||
165 | vscode.window.showErrorMessage(e.message); | ||
166 | } | ||
163 | 167 | ||
164 | if (Server.config.displayInlayHints) { | 168 | if (Server.config.displayInlayHints) { |
165 | const hintsUpdater = new HintsUpdater(); | 169 | const hintsUpdater = new HintsUpdater(); |
@@ -204,10 +208,10 @@ export function deactivate(): Thenable<void> { | |||
204 | return Server.client.stop(); | 208 | return Server.client.stop(); |
205 | } | 209 | } |
206 | 210 | ||
207 | async function reloadServer(startServer: () => void) { | 211 | async function reloadServer(startServer: () => Promise<void>) { |
208 | if (Server.client != null) { | 212 | if (Server.client != null) { |
209 | vscode.window.showInformationMessage('Reloading rust-analyzer...'); | 213 | vscode.window.showInformationMessage('Reloading rust-analyzer...'); |
210 | await Server.client.stop(); | 214 | await Server.client.stop(); |
211 | startServer(); | 215 | await startServer(); |
212 | } | 216 | } |
213 | } | 217 | } |
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index 7907b70bc..e717ab294 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import { lookpath } from 'lookpath'; | ||
1 | import { homedir } from 'os'; | 2 | import { homedir } from 'os'; |
2 | import * as lc from 'vscode-languageclient'; | 3 | import * as lc from 'vscode-languageclient'; |
3 | 4 | ||
@@ -17,7 +18,7 @@ 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 |
@@ -27,8 +28,14 @@ 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 | if (!(await lookpath(command))) { | ||
33 | throw new Error( | ||
34 | `Cannot find rust-analyzer server \`${command}\` in PATH.` | ||
35 | ); | ||
36 | } | ||
30 | const run: lc.Executable = { | 37 | const run: lc.Executable = { |
31 | command: expandPathResolving(this.config.raLspServerPath), | 38 | command, |
32 | options: { cwd: folder } | 39 | options: { cwd: folder } |
33 | }; | 40 | }; |
34 | const serverOptions: lc.ServerOptions = { | 41 | const serverOptions: lc.ServerOptions = { |