diff options
author | Roberto Vidal <[email protected]> | 2019-04-15 20:41:27 +0100 |
---|---|---|
committer | Roberto Vidal <[email protected]> | 2019-04-16 21:07:33 +0100 |
commit | 12f28f6276bbf1d1a19a553c7352bcb974361247 (patch) | |
tree | a3d72ba73e95c80ff24c59d5f546bf8baa0378f5 | |
parent | 546d9be2a7bf7b3942c125f922a01321aea6ad26 (diff) |
Adds "restart server" command
-rw-r--r-- | crates/gen_lsp_server/src/stdio.rs | 8 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main.rs | 2 | ||||
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/extension.ts | 16 |
4 files changed, 24 insertions, 7 deletions
diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs index dab2d8da8..c5fe5b83a 100644 --- a/crates/gen_lsp_server/src/stdio.rs +++ b/crates/gen_lsp_server/src/stdio.rs | |||
@@ -37,11 +37,9 @@ pub struct Threads { | |||
37 | } | 37 | } |
38 | 38 | ||
39 | impl Threads { | 39 | impl Threads { |
40 | pub fn join(self) -> Result<()> { | 40 | pub fn exit(self) -> Result<()> { |
41 | match self.reader.join() { | 41 | // We can't rely on stdin being closed |
42 | Ok(r) => r?, | 42 | drop(self.reader); |
43 | Err(_) => bail!("reader panicked"), | ||
44 | } | ||
45 | match self.writer.join() { | 43 | match self.writer.join() { |
46 | Ok(r) => r, | 44 | Ok(r) => r, |
47 | Err(_) => bail!("writer panicked"), | 45 | Err(_) => bail!("writer panicked"), |
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index b0b70df5c..6b1274a3b 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -54,7 +54,7 @@ fn main_inner() -> Result<()> { | |||
54 | ra_lsp_server::main_loop(workspace_roots, opts, r, s) | 54 | ra_lsp_server::main_loop(workspace_roots, opts, r, s) |
55 | })?; | 55 | })?; |
56 | log::info!("shutting down IO..."); | 56 | log::info!("shutting down IO..."); |
57 | threads.join()?; | 57 | threads.exit()?; |
58 | log::info!("... IO is down"); | 58 | log::info!("... IO is down"); |
59 | Ok(()) | 59 | Ok(()) |
60 | } | 60 | } |
diff --git a/editors/code/package.json b/editors/code/package.json index 1c8caaa60..a0454191a 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -114,6 +114,11 @@ | |||
114 | "command": "rust-analyzer.collectGarbage", | 114 | "command": "rust-analyzer.collectGarbage", |
115 | "title": "Run garbage collection", | 115 | "title": "Run garbage collection", |
116 | "category": "Rust Analyzer" | 116 | "category": "Rust Analyzer" |
117 | }, | ||
118 | { | ||
119 | "command": "rust-analyzer.reload", | ||
120 | "title": "Restart server", | ||
121 | "category": "Rust Analyzer" | ||
117 | } | 122 | } |
118 | ], | 123 | ], |
119 | "keybindings": [ | 124 | "keybindings": [ |
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index ef83c0b8b..db67bc7e3 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts | |||
@@ -120,11 +120,16 @@ export function activate(context: vscode.ExtensionContext) { | |||
120 | context.subscriptions | 120 | context.subscriptions |
121 | ); | 121 | ); |
122 | 122 | ||
123 | const startServer = () => Server.start(allNotifications); | ||
124 | const reloadCommand = () => reloadServer(startServer); | ||
125 | |||
126 | vscode.commands.registerCommand('rust-analyzer.reload', reloadCommand); | ||
127 | |||
123 | // Executing `cargo watch` provides us with inline diagnostics on save | 128 | // Executing `cargo watch` provides us with inline diagnostics on save |
124 | interactivelyStartCargoWatch(context); | 129 | interactivelyStartCargoWatch(context); |
125 | 130 | ||
126 | // Start the language server, finally! | 131 | // Start the language server, finally! |
127 | Server.start(allNotifications); | 132 | startServer(); |
128 | } | 133 | } |
129 | 134 | ||
130 | export function deactivate(): Thenable<void> { | 135 | export function deactivate(): Thenable<void> { |
@@ -133,3 +138,12 @@ export function deactivate(): Thenable<void> { | |||
133 | } | 138 | } |
134 | return Server.client.stop(); | 139 | return Server.client.stop(); |
135 | } | 140 | } |
141 | |||
142 | |||
143 | async function reloadServer(startServer: () => void) { | ||
144 | if (Server.client != null) { | ||
145 | vscode.window.showInformationMessage('Reloading rust-analyzer...'); | ||
146 | await Server.client.stop(); | ||
147 | startServer(); | ||
148 | } | ||
149 | } \ No newline at end of file | ||