diff options
author | Filipe Azevedo | 2022-09-20 07:44:36 +0000 |
---|---|---|
committer | GitHub | 2022-09-20 07:44:36 +0000 |
commit | 385ccdfc9c4f04cbe33c7cfdd668a1f694b6d870 (patch) | |
tree | 9a0b6ed9c9ae0c7406ce16f38207c5ac3ca4aab1 /helix-term/src/commands | |
parent | aa00a470f31514b792e219513ffb3806a5e5b53e (diff) |
add :lsp-restart command (#3435)
Diffstat (limited to 'helix-term/src/commands')
-rw-r--r-- | helix-term/src/commands/typed.rs | 41 |
1 files changed, 41 insertions, 0 deletions
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<str>], + 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<DocumentId> = 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<str>], @@ -1838,6 +1872,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ 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: &[], doc: "Display tree sitter scopes, primarily for theming and development.", |