on master help sign in
feat: resolve code action (#7677)
8977123sigmaSd
helix-lsp/src/client.rs+27−2
@@ -7,8 +7,9 @@ use crate::{
7use helix_core::{find_workspace, path, syntax::LanguageServerFeature, ChangeSet, Rope};
7use helix_core::{find_workspace, path, syntax::LanguageServerFeature, ChangeSet, Rope};
8use helix_loader::{self, VERSION_AND_GIT_HASH};
8use helix_loader::{self, VERSION_AND_GIT_HASH};
9use lsp::{
9use lsp::{
10− notification::DidChangeWorkspaceFolders, DidChangeWorkspaceFoldersParams, OneOf,
10+ notification::DidChangeWorkspaceFolders, CodeActionCapabilityResolveSupport,
11+ DidChangeWorkspaceFoldersParams, OneOf, PositionEncodingKind, WorkspaceFolder,
11− PositionEncodingKind, WorkspaceFolder, WorkspaceFoldersChangeEvent,
12+ WorkspaceFoldersChangeEvent,
12};
13};
13use lsp_types as lsp;
14use lsp_types as lsp;
14use parking_lot::Mutex;
15use parking_lot::Mutex;
@@ -609,6 +610,12 @@ impl Client {
609 .collect(),
610 .collect(),
610 },
611 },
611 }),
612 }),
613+ is_preferred_support: Some(true),
614+ disabled_support: Some(true),
615+ data_support: Some(true),
616+ resolve_support: Some(CodeActionCapabilityResolveSupport {
617+ properties: vec!["edit".to_owned(), "command".to_owned()],
618+ }),
612 ..Default::default()
619 ..Default::default()
613 }),
620 }),
614 publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities {
621 publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities {
@@ -954,6 +961,24 @@ impl Client {
954 Some(self.call::<lsp::request::ResolveCompletionItem>(completion_item))
961 Some(self.call::<lsp::request::ResolveCompletionItem>(completion_item))
955 }
962 }
956
963
964+ pub fn resolve_code_action(
965+ &self,
966+ code_action: lsp::CodeAction,
967+ ) -> Option<impl Future<Output = Result<Value>>> {
968+ let capabilities = self.capabilities.get().unwrap();
969+
970+ // Return early if the server does not support resolving code action.
971+ match capabilities.completion_provider {
972+ Some(lsp::CompletionOptions {
973+ resolve_provider: Some(true),
974+ ..
975+ }) => (),
976+ _ => return None,
977+ }
978+
979+ Some(self.call::<lsp::request::CodeActionResolveRequest>(code_action))
980+ }
981+
957 pub fn text_document_signature_help(
982 pub fn text_document_signature_help(
958 &self,
983 &self,
959 text_document: lsp::TextDocumentIdentifier,
984 text_document: lsp::TextDocumentIdentifier,
helix-term/src/commands/lsp.rs+14−1
@@ -743,7 +743,20 @@ pub fn code_action(cx: &mut Context) {
743 }
743 }
744 lsp::CodeActionOrCommand::CodeAction(code_action) => {
744 lsp::CodeActionOrCommand::CodeAction(code_action) => {
745 log::debug!("code action: {:?}", code_action);
745 log::debug!("code action: {:?}", code_action);
746+ // we support lsp "codeAction/resolve" for `edit` and `command` fields
747+ let mut resolved_code_action = None;
748+ if code_action.edit.is_none() || code_action.command.is_none() {
749+ if let Some(future) = language_server.resolve_code_action(code_action.clone()) {
750+ if let Ok(response) = helix_lsp::block_on(future) {
751+ if let Ok(code_action) = serde_json::from_value::<CodeAction>(response) {
752+ resolved_code_action = Some(code_action);
753+ }
754+ }
755+ }
756+ }
757+ let resolved_code_action = resolved_code_action.as_ref().unwrap_or(code_action);
758+
746− if let Some(ref workspace_edit) = code_action.edit {
759+ if let Some(ref workspace_edit) = resolved_code_action.edit {
747 log::debug!("edit: {:?}", workspace_edit);
760 log::debug!("edit: {:?}", workspace_edit);
748 let _ = apply_workspace_edit(editor, offset_encoding, workspace_edit);
761 let _ = apply_workspace_edit(editor, offset_encoding, workspace_edit);
749 }
762 }