Merge #1153
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:
commit
d3afb1b378
4 changed files with 29 additions and 1 deletions
|
@ -5,6 +5,7 @@ use std::{
|
||||||
|
|
||||||
use crossbeam_channel::{bounded, Receiver, Sender};
|
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||||
use failure::bail;
|
use failure::bail;
|
||||||
|
use lsp_types::notification::Exit;
|
||||||
|
|
||||||
use crate::{RawMessage, Result};
|
use crate::{RawMessage, Result};
|
||||||
|
|
||||||
|
@ -21,9 +22,18 @@ pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads)
|
||||||
let stdin = stdin();
|
let stdin = stdin();
|
||||||
let mut stdin = stdin.lock();
|
let mut stdin = stdin.lock();
|
||||||
while let Some(msg) = RawMessage::read(&mut stdin)? {
|
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) {
|
if let Err(_) = reader_sender.send(msg) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_exit {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
|
@ -114,6 +114,11 @@
|
||||||
"command": "rust-analyzer.collectGarbage",
|
"command": "rust-analyzer.collectGarbage",
|
||||||
"title": "Run garbage collection",
|
"title": "Run garbage collection",
|
||||||
"category": "Rust Analyzer"
|
"category": "Rust Analyzer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "rust-analyzer.reload",
|
||||||
|
"title": "Restart server",
|
||||||
|
"category": "Rust Analyzer"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"keybindings": [
|
"keybindings": [
|
||||||
|
|
|
@ -120,11 +120,16 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
context.subscriptions
|
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
|
// Executing `cargo watch` provides us with inline diagnostics on save
|
||||||
interactivelyStartCargoWatch(context);
|
interactivelyStartCargoWatch(context);
|
||||||
|
|
||||||
// Start the language server, finally!
|
// Start the language server, finally!
|
||||||
Server.start(allNotifications);
|
startServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deactivate(): Thenable<void> {
|
export function deactivate(): Thenable<void> {
|
||||||
|
@ -133,3 +138,11 @@ export function deactivate(): Thenable<void> {
|
||||||
}
|
}
|
||||||
return Server.client.stop();
|
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
0
editors/code/src/utils/terminateProcess.sh
Normal file → Executable file
Loading…
Add table
Reference in a new issue