on master help sign in
Allow LSP server to be stopped (#5964)
f976c00Davide Galassi
book/src/generated/typable-cmd.md+1
@@ -49,6 +49,7 @@
49| `:update` | Write changes only if the file has been modified. |
49| `:update` | Write changes only if the file has been modified. |
50| `:lsp-workspace-command` | Open workspace command picker |
50| `:lsp-workspace-command` | Open workspace command picker |
51| `:lsp-restart` | Restarts the Language Server that is in use by the current doc |
51| `:lsp-restart` | Restarts the Language Server that is in use by the current doc |
52+| `:lsp-stop` | Stops the Language Server that is in use by the current doc |
52| `:tree-sitter-scopes` | Display tree sitter scopes, primarily for theming and development. |
53| `:tree-sitter-scopes` | Display tree sitter scopes, primarily for theming and development. |
53| `:debug-start`, `:dbg` | Start a debug session from a given template with given parameters. |
54| `:debug-start`, `:dbg` | Start a debug session from a given template with given parameters. |
54| `:debug-remote`, `:dbg-tcp` | Connect to a debug adapter by TCP address and start a debugging session from a given template with given parameters. |
55| `:debug-remote`, `:dbg-tcp` | Connect to a debug adapter by TCP address and start a debugging session from a given template with given parameters. |
helix-lsp/src/lib.rs+10
@@ -476,6 +476,16 @@ impl Registry {
476 }
476 }
477 }
477 }
478
478
479+ pub fn stop(&mut self, language_config: &LanguageConfiguration) {
480+ let scope = language_config.scope.clone();
481+
482+ if let Some((_, client)) = self.inner.remove(&scope) {
483+ tokio::spawn(async move {
484+ let _ = client.force_shutdown().await;
485+ });
486+ }
487+ }
488+
479 pub fn get(
489 pub fn get(
480 &mut self,
490 &mut self,
481 language_config: &LanguageConfiguration,
491 language_config: &LanguageConfiguration,
helix-term/src/commands/typed.rs+38
@@ -1354,6 +1354,37 @@ fn lsp_restart(
1354 Ok(())
1354 Ok(())
1355}
1355}
1356
1356
1357+fn lsp_stop(
1358+ cx: &mut compositor::Context,
1359+ _args: &[Cow<str>],
1360+ event: PromptEvent,
1361+) -> anyhow::Result<()> {
1362+ if event != PromptEvent::Validate {
1363+ return Ok(());
1364+ }
1365+
1366+ let doc = doc!(cx.editor);
1367+
1368+ let ls_id = doc
1369+ .language_server()
1370+ .map(|ls| ls.id())
1371+ .context("LSP not running for the current document")?;
1372+
1373+ let config = doc
1374+ .language_config()
1375+ .context("LSP not defined for the current document")?;
1376+ cx.editor.language_servers.stop(config);
1377+
1378+ for doc in cx.editor.documents_mut() {
1379+ if doc.language_server().map_or(false, |ls| ls.id() == ls_id) {
1380+ doc.set_language_server(None);
1381+ doc.set_diagnostics(Default::default());
1382+ }
1383+ }
1384+
1385+ Ok(())
1386+}
1387+
1357fn tree_sitter_scopes(
1388fn tree_sitter_scopes(
1358 cx: &mut compositor::Context,
1389 cx: &mut compositor::Context,
1359 _args: &[Cow<str>],
1390 _args: &[Cow<str>],
@@ -2349,6 +2380,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2349 fun: lsp_restart,
2380 fun: lsp_restart,
2350 completer: None,
2381 completer: None,
2351 },
2382 },
2383+ TypableCommand {
2384+ name: "lsp-stop",
2385+ aliases: &[],
2386+ doc: "Stops the Language Server that is in use by the current doc",
2387+ fun: lsp_stop,
2388+ completer: None,
2389+ },
2352 TypableCommand {
2390 TypableCommand {
2353 name: "tree-sitter-scopes",
2391 name: "tree-sitter-scopes",
2354 aliases: &[],
2392 aliases: &[],