aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/gen_lsp_server/src/stdio.rs10
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/extension.ts15
-rwxr-xr-x[-rw-r--r--]editors/code/src/utils/terminateProcess.sh0
4 files changed, 29 insertions, 1 deletions
diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs
index dab2d8da8..5edfbc39c 100644
--- a/crates/gen_lsp_server/src/stdio.rs
+++ b/crates/gen_lsp_server/src/stdio.rs
@@ -5,6 +5,7 @@ use std::{
5 5
6use crossbeam_channel::{bounded, Receiver, Sender}; 6use crossbeam_channel::{bounded, Receiver, Sender};
7use failure::bail; 7use failure::bail;
8use lsp_types::notification::Exit;
8 9
9use crate::{RawMessage, Result}; 10use crate::{RawMessage, Result};
10 11
@@ -21,9 +22,18 @@ pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads)
21 let stdin = stdin(); 22 let stdin = stdin();
22 let mut stdin = stdin.lock(); 23 let mut stdin = stdin.lock();
23 while let Some(msg) = RawMessage::read(&mut stdin)? { 24 while let Some(msg) = RawMessage::read(&mut stdin)? {
25 let is_exit = match &msg {
26 RawMessage::Notification(n) => n.is::<Exit>(),
27 _ => false,
28 };
29
24 if let Err(_) = reader_sender.send(msg) { 30 if let Err(_) = reader_sender.send(msg) {
25 break; 31 break;
26 } 32 }
33
34 if is_exit {
35 break;
36 }
27 } 37 }
28 Ok(()) 38 Ok(())
29 }); 39 });
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..1073a36a0 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
130export function deactivate(): Thenable<void> { 135export function deactivate(): Thenable<void> {
@@ -133,3 +138,11 @@ export function deactivate(): Thenable<void> {
133 } 138 }
134 return Server.client.stop(); 139 return Server.client.stop();
135} 140}
141
142async function reloadServer(startServer: () => void) {
143 if (Server.client != null) {
144 vscode.window.showInformationMessage('Reloading rust-analyzer...');
145 await Server.client.stop();
146 startServer();
147 }
148}
diff --git a/editors/code/src/utils/terminateProcess.sh b/editors/code/src/utils/terminateProcess.sh
index 2ec9e1c2e..2ec9e1c2e 100644..100755
--- a/editors/code/src/utils/terminateProcess.sh
+++ b/editors/code/src/utils/terminateProcess.sh