1153: "Restart server" command r=jrvidal a=jrvidal

The only tricky aspect is that fact that once the `exit` command has been received, we no longer need to join on the reader thread. 

Also, I think `terminateProcesses.sh` was not working properly. In fact, the very same script from the vscode language server implementation is not working either! It's because of that I noticed the reader thread issue 😮 

Co-authored-by: Roberto Vidal <vidal.roberto.j@gmail.com>
This commit is contained in:
bors[bot] 2019-04-17 05:51:12 +00:00
commit d3afb1b378
4 changed files with 29 additions and 1 deletions

View file

@ -5,6 +5,7 @@ use std::{
use crossbeam_channel::{bounded, Receiver, Sender};
use failure::bail;
use lsp_types::notification::Exit;
use crate::{RawMessage, Result};
@ -21,9 +22,18 @@ pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads)
let stdin = stdin();
let mut stdin = stdin.lock();
while let Some(msg) = RawMessage::read(&mut stdin)? {
let is_exit = match &msg {
RawMessage::Notification(n) => n.is::<Exit>(),
_ => false,
};
if let Err(_) = reader_sender.send(msg) {
break;
}
if is_exit {
break;
}
}
Ok(())
});

View file

@ -114,6 +114,11 @@
"command": "rust-analyzer.collectGarbage",
"title": "Run garbage collection",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.reload",
"title": "Restart server",
"category": "Rust Analyzer"
}
],
"keybindings": [

View file

@ -120,11 +120,16 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions
);
const startServer = () => Server.start(allNotifications);
const reloadCommand = () => reloadServer(startServer);
vscode.commands.registerCommand('rust-analyzer.reload', reloadCommand);
// Executing `cargo watch` provides us with inline diagnostics on save
interactivelyStartCargoWatch(context);
// Start the language server, finally!
Server.start(allNotifications);
startServer();
}
export function deactivate(): Thenable<void> {
@ -133,3 +138,11 @@ export function deactivate(): Thenable<void> {
}
return Server.client.stop();
}
async function reloadServer(startServer: () => void) {
if (Server.client != null) {
vscode.window.showInformationMessage('Reloading rust-analyzer...');
await Server.client.stop();
startServer();
}
}

0
editors/code/src/utils/terminateProcess.sh Normal file → Executable file
View file