Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advertise code action support #1038

Merged
merged 2 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions src/language_server_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,25 @@ impl LanguageClient {
}),
..CompletionCapability::default()
}),
code_action: Some(CodeActionCapability {
code_action_literal_support: Some(CodeActionLiteralSupport {
code_action_kind: CodeActionKindLiteralSupport {
value_set: [
code_action_kind::QUICKFIX,
code_action_kind::REFACTOR,
code_action_kind::REFACTOR_EXTRACT,
code_action_kind::REFACTOR_INLINE,
code_action_kind::REFACTOR_REWRITE,
code_action_kind::SOURCE,
code_action_kind::SOURCE_ORGANIZE_IMPORTS,
]
.iter()
.map(|x| x.to_string())
.collect(),
},
}),
..CodeActionCapability::default()
}),
signature_help: Some(SignatureHelpCapability {
signature_information: Some(SignatureInformationSettings {
documentation_format: preferred_markup_kind.clone(),
Expand Down Expand Up @@ -1632,13 +1651,7 @@ impl LanguageClient {

let source: Vec<_> = actions
.iter()
.map(|action| {
format!(
"{}: {}",
action.kind.as_ref().map_or("action", String::as_ref),
action.title
)
})
.map(|action| format!("{}: {}", code_action_kind_as_str(&action), action.title))
.collect();

self.update(|state| {
Expand Down Expand Up @@ -3400,10 +3413,7 @@ impl LanguageClient {

actions
.iter()
.find(|action| {
action.kind.as_ref().map_or(kind, String::as_ref) == kind
&& action.title == title
})
.find(|action| code_action_kind_as_str(&action) == kind && action.title == title)
.cloned()
.ok_or_else(|| {
format_err!("No stashed action found! stashed actions: {:?}", actions)
Expand Down
8 changes: 8 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,14 @@ pub fn convert_to_vim_str(s: &str) -> String {
vs
}

/// Converts the kind of a `CodeAction` to a `&str`.
pub fn code_action_kind_as_str(action: &CodeAction) -> &str {
match action.kind.as_ref().map(String::as_ref) {
None | Some("") => "action",
Some(kind) => kind,
}
}

#[test]
fn test_convert_to_vim_str() {
assert_eq!(convert_to_vim_str("abcdefg"), "'abcdefg'");
Expand Down