Skip to content

Commit 893b1f6

Browse files
committed
Filter LSP code actions based on the requested kinds
1 parent 889aac9 commit 893b1f6

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

crates/project/src/lsp_command.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,19 +2090,33 @@ impl LspCommand for GetCodeActions {
20902090
server_id: LanguageServerId,
20912091
_: AsyncAppContext,
20922092
) -> Result<Vec<CodeAction>> {
2093+
let requested_kinds_set = match self.kinds {
2094+
Some(kinds) => Some(kinds.into_iter().collect::<HashSet<_>>()),
2095+
None => None,
2096+
};
2097+
20932098
Ok(actions
20942099
.unwrap_or_default()
20952100
.into_iter()
20962101
.filter_map(|entry| {
2097-
if let lsp::CodeActionOrCommand::CodeAction(lsp_action) = entry {
2098-
Some(CodeAction {
2099-
server_id,
2100-
range: self.range.clone(),
2101-
lsp_action,
2102-
})
2103-
} else {
2104-
None
2102+
let lsp_action = match entry {
2103+
lsp::CodeActionOrCommand::CodeAction(lsp_action) => lsp_action,
2104+
_ => return None,
2105+
};
2106+
2107+
if let Some(requested_kinds) = &requested_kinds_set {
2108+
if let Some(kind) = &lsp_action.kind {
2109+
if !requested_kinds.contains(kind) {
2110+
return None;
2111+
}
2112+
}
21052113
}
2114+
2115+
Some(CodeAction {
2116+
server_id,
2117+
range: self.range.clone(),
2118+
lsp_action,
2119+
})
21062120
})
21072121
.collect())
21082122
}

0 commit comments

Comments
 (0)