From 385ccdfc9c4f04cbe33c7cfdd668a1f694b6d870 Mon Sep 17 00:00:00 2001 From: Filipe Azevedo Date: Tue, 20 Sep 2022 08:44:36 +0100 Subject: add :lsp-restart command (#3435) --- helix-term/src/commands/typed.rs | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'helix-term') diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index f49fff30..6d0ced65 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -985,6 +985,40 @@ fn reload( }) } +fn lsp_restart( + cx: &mut compositor::Context, + _args: &[Cow], + event: PromptEvent, +) -> anyhow::Result<()> { + if event != PromptEvent::Validate { + return Ok(()); + } + + let (_view, doc) = current!(cx.editor); + let config = doc + .language_config() + .context("LSP not defined for the current document")?; + + let scope = config.scope.clone(); + cx.editor.language_servers.restart(config)?; + + // This collect is needed because refresh_language_server would need to re-borrow editor. + let document_ids_to_refresh: Vec = cx + .editor + .documents() + .filter_map(|doc| match doc.language_config() { + Some(config) if config.scope.eq(&scope) => Some(doc.id()), + _ => None, + }) + .collect(); + + for document_id in document_ids_to_refresh { + cx.editor.refresh_language_server(document_id); + } + + Ok(()) +} + fn tree_sitter_scopes( cx: &mut compositor::Context, _args: &[Cow], @@ -1837,6 +1871,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: reload, completer: None, }, + TypableCommand { + name: "lsp-restart", + aliases: &[], + doc: "Restarts the Language Server that is in use by the current doc", + fun: lsp_restart, + completer: None, + }, TypableCommand { name: "tree-sitter-scopes", aliases: &[], -- cgit v1.2.3-70-g09d2