Filter out CodeActions if a server only support commands.

This commit is contained in:
kjeremy 2020-04-26 18:54:05 -04:00
parent 4d33cdcfb2
commit e3ee61f5e8
3 changed files with 27 additions and 1 deletions

View file

@ -70,6 +70,7 @@ pub struct ClientCapsConfig {
pub location_link: bool,
pub line_folding_only: bool,
pub hierarchical_symbols: bool,
pub code_action_literals: bool,
}
impl Default for Config {
@ -221,6 +222,11 @@ impl Config {
{
self.client_caps.hierarchical_symbols = value
}
if let Some(value) =
caps.code_action.as_ref().and_then(|it| Some(it.code_action_literal_support.is_some()))
{
self.client_caps.code_action_literals = value;
}
self.completion.allow_snippets(false);
if let Some(completion) = &caps.completion {
if let Some(completion_item) = &completion.completion_item {

View file

@ -812,6 +812,22 @@ pub fn handle_code_action(
}
}
// If the client only supports commands then filter the list
// and remove and actions that depend on edits.
if !world.config.client_caps.code_action_literals {
res = res
.into_iter()
.filter_map(|it| match it {
cmd @ lsp_types::CodeActionOrCommand::Command(_) => Some(cmd),
lsp_types::CodeActionOrCommand::CodeAction(action) => match action.command {
Some(cmd) if action.edit.is_none() => {
Some(lsp_types::CodeActionOrCommand::Command(cmd))
}
_ => None,
},
})
.collect();
}
Ok(Some(res))
}

View file

@ -77,7 +77,11 @@ impl<'a> Project<'a> {
let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect();
let mut config = Config {
client_caps: ClientCapsConfig { location_link: true, ..Default::default() },
client_caps: ClientCapsConfig {
location_link: true,
code_action_literals: true,
..Default::default()
},
with_sysroot: self.with_sysroot,
..Config::default()
};