diff options
author | Pascal Kuthe | 2022-10-08 12:18:53 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-10-21 01:03:00 +0000 |
commit | 8d8b5d6624901f34e99407e18fea0b8abbb058aa (patch) | |
tree | d383efade3e41fd3d0706d289fe6c26832ee67c7 /helix-term/src | |
parent | c70d762a7b6285684dd7c5f39a53f05394369981 (diff) |
use stable sort instead of allocating new vectors
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands/lsp.rs | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 5fec38d4..add6183f 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -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| { |