mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-30 23:27:24 +00:00
Adds "restart server" command
This commit is contained in:
parent
546d9be2a7
commit
12f28f6276
4 changed files with 24 additions and 7 deletions
|
@ -37,11 +37,9 @@ pub struct Threads {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Threads {
|
impl Threads {
|
||||||
pub fn join(self) -> Result<()> {
|
pub fn exit(self) -> Result<()> {
|
||||||
match self.reader.join() {
|
// We can't rely on stdin being closed
|
||||||
Ok(r) => r?,
|
drop(self.reader);
|
||||||
Err(_) => bail!("reader panicked"),
|
|
||||||
}
|
|
||||||
match self.writer.join() {
|
match self.writer.join() {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(_) => bail!("writer panicked"),
|
Err(_) => bail!("writer panicked"),
|
||||||
|
|
|
@ -54,7 +54,7 @@ fn main_inner() -> Result<()> {
|
||||||
ra_lsp_server::main_loop(workspace_roots, opts, r, s)
|
ra_lsp_server::main_loop(workspace_roots, opts, r, s)
|
||||||
})?;
|
})?;
|
||||||
log::info!("shutting down IO...");
|
log::info!("shutting down IO...");
|
||||||
threads.join()?;
|
threads.exit()?;
|
||||||
log::info!("... IO is down");
|
log::info!("... IO is down");
|
||||||
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,12 @@ 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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue