Skip to content

Commit

Permalink
use stable sort instead of allocating new vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe committed Oct 8, 2022
1 parent 63a54ee commit 8ed9cf7
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,38 +467,28 @@ pub fn code_action(cx: &mut Context) {
// while more situational commands (like refactors) show up later
// this behaviour is modeled after the behaviour of vscode (editor/contrib/codeAction/browser/codeActionWidget.ts)

let mut categories = vec![Vec::new(); 8];
for action in actions.drain(..) {
let category = match &action {
lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
kind: Some(kind),
..
}) => {
let mut components = kind.as_str().split('.');

match components.next() {
Some("quickfix") => 0,
Some("refactor") => match components.next() {
Some("extract") => 1,
Some("inline") => 2,
Some("rewrite") => 3,
Some("move") => 4,
Some("surround") => 5,
_ => 7,
},
Some("source") => 6,
actions.sort_by_key(|action| match &action {
lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
kind: Some(kind), ..
}) => {
let mut components = kind.as_str().split('.');

match components.next() {
Some("quickfix") => 0,
Some("refactor") => match components.next() {
Some("extract") => 1,
Some("inline") => 2,
Some("rewrite") => 3,
Some("move") => 4,
Some("surround") => 5,
_ => 7,
}
},
Some("source") => 6,
_ => 7,
}
_ => 7,
};

categories[category].push(action);
}

for category in categories {
actions.extend(category.into_iter())
}
}
_ => 7,
});

let mut picker =
ui::Menu::new(actions, false, (), move |editor, code_action, event| {
Expand Down

0 comments on commit 8ed9cf7

Please sign in to comment.