on master help sign in
use stable sort instead of allocating new vectors
commit8d8b5d6624901f34e99407e18fea0b8abbb058aa authorPascal Kuthe <pascal.kuthe@semimod.de> dateSat 8 Oct 2022, 14:18 (4 years ago) parentc70d762
1 file changed+20−30
helix-term/src/commands/lsp.rs+20−30
helix-term/src/commands/lsp.rs+20−30
@@ -467,38 +467,28 @@ pub fn code_action(cx: &mut Context) {
467467 // while more situational commands (like refactors) show up later
468468 // this behaviour is modeled after the behaviour of vscode (editor/contrib/codeAction/browser/codeActionWidget.ts)
469469
470− let mut categories = vec![Vec::new(); 8];
471− for action in actions.drain(..) {
472− let category = match &action {
473− lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
474− kind: Some(kind),
475− ..
476− }) => {
477− let mut components = kind.as_str().split('.');
478−
479− match components.next() {
480− Some("quickfix") => 0,
481− Some("refactor") => match components.next() {
482− Some("extract") => 1,
483− Some("inline") => 2,
484− Some("rewrite") => 3,
485− Some("move") => 4,
486− Some("surround") => 5,
487− _ => 7,
488− },
489− Some("source") => 6,
470+ actions.sort_by_key(|action| match &action {
471+ lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
472+ kind: Some(kind), ..
473+ }) => {
474+ let mut components = kind.as_str().split('.');
475+
476+ match components.next() {
477+ Some("quickfix") => 0,
478+ Some("refactor") => match components.next() {
479+ Some("extract") => 1,
480+ Some("inline") => 2,
481+ Some("rewrite") => 3,
482+ Some("move") => 4,
483+ Some("surround") => 5,
490484 _ => 7,
491− }
485+ },
486+ Some("source") => 6,
487+ _ => 7,
492488 }
493− _ => 7,
494− };
495−
496− categories[category].push(action);
497− }
498−
499− for category in categories {
500− actions.extend(category.into_iter())
501− }
489+ }
490+ _ => 7,
491+ });
502492
503493 let mut picker =
504494 ui::Menu::new(actions, false, (), move |editor, code_action, event| {