diff options
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop/handlers.rs | 16 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/support.rs | 6 |
3 files changed, 27 insertions, 1 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 74a63e32a..177da94cc 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -70,6 +70,7 @@ pub struct ClientCapsConfig { | |||
70 | pub location_link: bool, | 70 | pub location_link: bool, |
71 | pub line_folding_only: bool, | 71 | pub line_folding_only: bool, |
72 | pub hierarchical_symbols: bool, | 72 | pub hierarchical_symbols: bool, |
73 | pub code_action_literals: bool, | ||
73 | } | 74 | } |
74 | 75 | ||
75 | impl Default for Config { | 76 | impl Default for Config { |
@@ -221,6 +222,11 @@ impl Config { | |||
221 | { | 222 | { |
222 | self.client_caps.hierarchical_symbols = value | 223 | self.client_caps.hierarchical_symbols = value |
223 | } | 224 | } |
225 | if let Some(value) = | ||
226 | caps.code_action.as_ref().and_then(|it| Some(it.code_action_literal_support.is_some())) | ||
227 | { | ||
228 | self.client_caps.code_action_literals = value; | ||
229 | } | ||
224 | self.completion.allow_snippets(false); | 230 | self.completion.allow_snippets(false); |
225 | if let Some(completion) = &caps.completion { | 231 | if let Some(completion) = &caps.completion { |
226 | if let Some(completion_item) = &completion.completion_item { | 232 | if let Some(completion_item) = &completion.completion_item { |
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index 8db2dfa0c..b4e539906 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs | |||
@@ -812,6 +812,22 @@ pub fn handle_code_action( | |||
812 | } | 812 | } |
813 | } | 813 | } |
814 | 814 | ||
815 | // If the client only supports commands then filter the list | ||
816 | // and remove and actions that depend on edits. | ||
817 | if !world.config.client_caps.code_action_literals { | ||
818 | res = res | ||
819 | .into_iter() | ||
820 | .filter_map(|it| match it { | ||
821 | cmd @ lsp_types::CodeActionOrCommand::Command(_) => Some(cmd), | ||
822 | lsp_types::CodeActionOrCommand::CodeAction(action) => match action.command { | ||
823 | Some(cmd) if action.edit.is_none() => { | ||
824 | Some(lsp_types::CodeActionOrCommand::Command(cmd)) | ||
825 | } | ||
826 | _ => None, | ||
827 | }, | ||
828 | }) | ||
829 | .collect(); | ||
830 | } | ||
815 | Ok(Some(res)) | 831 | Ok(Some(res)) |
816 | } | 832 | } |
817 | 833 | ||
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs index e4fe3411a..8d47ee4f6 100644 --- a/crates/rust-analyzer/tests/heavy_tests/support.rs +++ b/crates/rust-analyzer/tests/heavy_tests/support.rs | |||
@@ -77,7 +77,11 @@ impl<'a> Project<'a> { | |||
77 | let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect(); | 77 | let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect(); |
78 | 78 | ||
79 | let mut config = Config { | 79 | let mut config = Config { |
80 | client_caps: ClientCapsConfig { location_link: true, ..Default::default() }, | 80 | client_caps: ClientCapsConfig { |
81 | location_link: true, | ||
82 | code_action_literals: true, | ||
83 | ..Default::default() | ||
84 | }, | ||
81 | with_sysroot: self.with_sysroot, | 85 | with_sysroot: self.with_sysroot, |
82 | ..Config::default() | 86 | ..Config::default() |
83 | }; | 87 | }; |