mirror of https://github.com/helix-editor/helix
use stable sort instead of allocating new vectors
parent
c70d762a7b
commit
8d8b5d6624
|
@ -467,38 +467,28 @@ pub fn code_action(cx: &mut Context) {
|
||||||
// while more situational commands (like refactors) show up later
|
// while more situational commands (like refactors) show up later
|
||||||
// this behaviour is modeled after the behaviour of vscode (editor/contrib/codeAction/browser/codeActionWidget.ts)
|
// this behaviour is modeled after the behaviour of vscode (editor/contrib/codeAction/browser/codeActionWidget.ts)
|
||||||
|
|
||||||
let mut categories = vec![Vec::new(); 8];
|
actions.sort_by_key(|action| match &action {
|
||||||
for action in actions.drain(..) {
|
lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
|
||||||
let category = match &action {
|
kind: Some(kind), ..
|
||||||
lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
|
}) => {
|
||||||
kind: Some(kind),
|
let mut components = kind.as_str().split('.');
|
||||||
..
|
|
||||||
}) => {
|
|
||||||
let mut components = kind.as_str().split('.');
|
|
||||||
|
|
||||||
match components.next() {
|
match components.next() {
|
||||||
Some("quickfix") => 0,
|
Some("quickfix") => 0,
|
||||||
Some("refactor") => match components.next() {
|
Some("refactor") => match components.next() {
|
||||||
Some("extract") => 1,
|
Some("extract") => 1,
|
||||||
Some("inline") => 2,
|
Some("inline") => 2,
|
||||||
Some("rewrite") => 3,
|
Some("rewrite") => 3,
|
||||||
Some("move") => 4,
|
Some("move") => 4,
|
||||||
Some("surround") => 5,
|
Some("surround") => 5,
|
||||||
_ => 7,
|
|
||||||
},
|
|
||||||
Some("source") => 6,
|
|
||||||
_ => 7,
|
_ => 7,
|
||||||
}
|
},
|
||||||
|
Some("source") => 6,
|
||||||
|
_ => 7,
|
||||||
}
|
}
|
||||||
_ => 7,
|
}
|
||||||
};
|
_ => 7,
|
||||||
|
});
|
||||||
categories[category].push(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
for category in categories {
|
|
||||||
actions.extend(category.into_iter())
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut picker =
|
let mut picker =
|
||||||
ui::Menu::new(actions, false, (), move |editor, code_action, event| {
|
ui::Menu::new(actions, false, (), move |editor, code_action, event| {
|
||||||
|
|
Loading…
Reference in New Issue