diff options
Diffstat (limited to 'helix-term/src/commands/typed.rs')
-rw-r--r-- | helix-term/src/commands/typed.rs | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 81a24059..706442e4 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1329,26 +1329,22 @@ fn lsp_workspace_command( if event != PromptEvent::Validate { return Ok(()); } - - let (_, doc) = current!(cx.editor); - - let language_server = match doc.language_server() { - Some(language_server) => language_server, - None => { - cx.editor - .set_status("Language server not active for current buffer"); - return Ok(()); - } + let doc = doc!(cx.editor); + let Some((language_server_id, options)) = doc + .language_servers_with_feature(LanguageServerFeature::WorkspaceCommand) + .find_map(|ls| { + ls.capabilities() + .execute_command_provider + .as_ref() + .map(|options| (ls.id(), options)) + }) + else { + cx.editor.set_status( + "No active language servers for this document support workspace commands", + ); + return Ok(()); }; - let options = match &language_server.capabilities().execute_command_provider { - Some(options) => options, - None => { - cx.editor - .set_status("Workspace commands are not supported for this language server"); - return Ok(()); - } - }; if args.is_empty() { let commands = options .commands @@ -1362,8 +1358,8 @@ fn lsp_workspace_command( let callback = async move { let call: job::Callback = Callback::EditorCompositor(Box::new( move |_editor: &mut Editor, compositor: &mut Compositor| { - let picker = ui::Picker::new(commands, (), |cx, command, _action| { - execute_lsp_command(cx.editor, command.clone()); + let picker = ui::Picker::new(commands, (), move |cx, command, _action| { + execute_lsp_command(cx.editor, language_server_id, command.clone()); }); compositor.push(Box::new(overlaid(picker))) }, @@ -1376,6 +1372,7 @@ fn lsp_workspace_command( if options.commands.iter().any(|c| c == &command) { execute_lsp_command( cx.editor, + language_server_id, helix_lsp::lsp::Command { title: command.clone(), arguments: None, @@ -1407,7 +1404,6 @@ fn lsp_restart( .language_config() .context("LSP not defined for the current document")?; - let scope = config.scope.clone(); cx.editor.language_servers.restart( config, doc.path(), @@ -1420,13 +1416,22 @@ fn lsp_restart( .editor .documents() .filter_map(|doc| match doc.language_config() { - Some(config) if config.scope.eq(&scope) => Some(doc.id()), + Some(config) + if config.language_servers.iter().any(|ls| { + config + .language_servers + .iter() + .any(|restarted_ls| restarted_ls.name == ls.name) + }) => + { + Some(doc.id()) + } _ => None, }) .collect(); for document_id in document_ids_to_refresh { - cx.editor.refresh_language_server(document_id); + cx.editor.refresh_language_servers(document_id); } Ok(()) @@ -1441,22 +1446,18 @@ fn lsp_stop( return Ok(()); } - let doc = doc!(cx.editor); + let ls_shutdown_names = doc!(cx.editor) + .language_servers() + .map(|ls| ls.name().to_string()) + .collect::<Vec<_>>(); - let ls_id = doc - .language_server() - .map(|ls| ls.id()) - .context("LSP not running for the current document")?; + for ls_name in &ls_shutdown_names { + cx.editor.language_servers.stop(ls_name); - let config = doc - .language_config() - .context("LSP not defined for the current document")?; - cx.editor.language_servers.stop(config); - - for doc in cx.editor.documents_mut() { - if doc.language_server().map_or(false, |ls| ls.id() == ls_id) { - doc.set_language_server(None); - doc.set_diagnostics(Default::default()); + for doc in cx.editor.documents_mut() { + if let Some(client) = doc.remove_language_server_by_name(ls_name) { + doc.clear_diagnostics(client.id()); + } } } @@ -1850,7 +1851,7 @@ fn language( doc.detect_indent_and_line_ending(); let id = doc.id(); - cx.editor.refresh_language_server(id); + cx.editor.refresh_language_servers(id); Ok(()) } @@ -2588,14 +2589,14 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ TypableCommand { name: "lsp-restart", aliases: &[], - doc: "Restarts the Language Server that is in use by the current doc", + doc: "Restarts the language servers used by the current doc", fun: lsp_restart, signature: CommandSignature::none(), }, TypableCommand { name: "lsp-stop", aliases: &[], - doc: "Stops the Language Server that is in use by the current doc", + doc: "Stops the language servers that are used by the current doc", fun: lsp_stop, signature: CommandSignature::none(), }, |