Skip to content

Commit e3ee61f

Browse files
committed
Filter out CodeActions if a server only support commands.
1 parent 4d33cdc commit e3ee61f

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub struct ClientCapsConfig {
7070
pub location_link: bool,
7171
pub line_folding_only: bool,
7272
pub hierarchical_symbols: bool,
73+
pub code_action_literals: bool,
7374
}
7475

7576
impl Default for Config {
@@ -221,6 +222,11 @@ impl Config {
221222
{
222223
self.client_caps.hierarchical_symbols = value
223224
}
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+
}
224230
self.completion.allow_snippets(false);
225231
if let Some(completion) = &caps.completion {
226232
if let Some(completion_item) = &completion.completion_item {

crates/rust-analyzer/src/main_loop/handlers.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,22 @@ pub fn handle_code_action(
812812
}
813813
}
814814

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+
}
815831
Ok(Some(res))
816832
}
817833

crates/rust-analyzer/tests/heavy_tests/support.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ impl<'a> Project<'a> {
7777
let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect();
7878

7979
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+
},
8185
with_sysroot: self.with_sysroot,
8286
..Config::default()
8387
};

0 commit comments

Comments
 (0)