Skip to content

Commit

Permalink
Simplify by only storing code actions
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Sep 23, 2024
1 parent 8798bea commit 893aa0b
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions tooling/lsp/src/requests/code_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct CodeActionFinder<'a> {
auto_import_line: usize,
/// Text edits for the "Remove all unused imports" code action
unused_imports_text_edits: Vec<TextEdit>,
code_actions: Vec<CodeActionOrCommand>,
code_actions: Vec<CodeAction>,
}

impl<'a> CodeActionFinder<'a> {
Expand Down Expand Up @@ -145,25 +145,16 @@ impl<'a> CodeActionFinder<'a> {
}

let mut code_actions = std::mem::take(&mut self.code_actions);
code_actions.sort_by_key(|code_action| {
let CodeActionOrCommand::CodeAction(code_action) = code_action else {
panic!("We only gather code actions, never commands");
};
code_action.title.clone()
});

Some(code_actions)
code_actions.sort_by_key(|code_action| code_action.title.clone());

Some(code_actions.into_iter().map(CodeActionOrCommand::CodeAction).collect())
}

fn new_quick_fix(&self, title: String, text_edit: TextEdit) -> CodeActionOrCommand {
fn new_quick_fix(&self, title: String, text_edit: TextEdit) -> CodeAction {
self.new_quick_fix_multiple_edits(title, vec![text_edit])
}

fn new_quick_fix_multiple_edits(
&self,
title: String,
text_edits: Vec<TextEdit>,
) -> CodeActionOrCommand {
fn new_quick_fix_multiple_edits(&self, title: String, text_edits: Vec<TextEdit>) -> CodeAction {
let mut changes = HashMap::new();
changes.insert(self.uri.clone(), text_edits);

Expand All @@ -173,7 +164,7 @@ impl<'a> CodeActionFinder<'a> {
change_annotations: None,
};

CodeActionOrCommand::CodeAction(CodeAction {
CodeAction {
title,
kind: Some(CodeActionKind::QUICKFIX),

Check warning on line 169 in tooling/lsp/src/requests/code_action.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (QUICKFIX)
diagnostics: None,
Expand All @@ -182,7 +173,7 @@ impl<'a> CodeActionFinder<'a> {
is_preferred: None,
disabled: None,
data: None,
})
}
}

fn includes_span(&self, span: Span) -> bool {
Expand Down

0 comments on commit 893aa0b

Please sign in to comment.