on master help sign in
never sort menu items when no fuzzy matching is possible
commit189aa0bfcfb6841ced946289e112cc9cdd4919a5 authorPascal Kuthe <pascal.kuthe@semimod.de> dateThu 13 Oct 2022, 20:10 (4 years ago) parentdc3527f
3 files changed+26−36
helix-term/src/commands/lsp.rs+22−23 helix-term/src/ui/completion.rs+1−1 helix-term/src/ui/menu.rs+3−12
helix-term/src/commands/lsp.rs+22−23
@@ -490,35 +490,34 @@ pub fn code_action(cx: &mut Context) {
490490 _ => 7,
491491 });
492492
493− let mut picker =
494− ui::Menu::new(actions, false, (), move |editor, code_action, event| {
495− if event != PromptEvent::Validate {
496− return;
497− }
493+ let mut picker = ui::Menu::new(actions, (), move |editor, code_action, event| {
494+ if event != PromptEvent::Validate {
495+ return;
496+ }
498497
499− // always present here
500− let code_action = code_action.unwrap();
498+ // always present here
499+ let code_action = code_action.unwrap();
501500
502− match code_action {
503− lsp::CodeActionOrCommand::Command(command) => {
504− log::debug!("code action command: {:?}", command);
505− execute_lsp_command(editor, command.clone());
501+ match code_action {
502+ lsp::CodeActionOrCommand::Command(command) => {
503+ log::debug!("code action command: {:?}", command);
504+ execute_lsp_command(editor, command.clone());
505+ }
506+ lsp::CodeActionOrCommand::CodeAction(code_action) => {
507+ log::debug!("code action: {:?}", code_action);
508+ if let Some(ref workspace_edit) = code_action.edit {
509+ log::debug!("edit: {:?}", workspace_edit);
510+ apply_workspace_edit(editor, offset_encoding, workspace_edit);
506511 }
507− lsp::CodeActionOrCommand::CodeAction(code_action) => {
508− log::debug!("code action: {:?}", code_action);
509− if let Some(ref workspace_edit) = code_action.edit {
510− log::debug!("edit: {:?}", workspace_edit);
511− apply_workspace_edit(editor, offset_encoding, workspace_edit);
512− }
513512
514− // if code action provides both edit and command first the edit
515− // should be applied and then the command
516− if let Some(command) = &code_action.command {
517− execute_lsp_command(editor, command.clone());
518− }
513+ // if code action provides both edit and command first the edit
514+ // should be applied and then the command
515+ if let Some(command) = &code_action.command {
516+ execute_lsp_command(editor, command.clone());
519517 }
520518 }
521− });
519+ }
520+ });
522521 picker.move_down(); // pre-select the first item
523522
524523 let popup = Popup::new("code-action", picker);
helix-term/src/ui/completion.rs+1−1
@@ -97,7 +97,7 @@ impl Completion {
9797 start_offset: usize,
9898 trigger_offset: usize,
9999 ) -> Self {
100− let menu = Menu::new(items, true, (), move |editor: &mut Editor, item, event| {
100+ let menu = Menu::new(items, (), move |editor: &mut Editor, item, event| {
101101 fn item_to_transaction(
102102 doc: &Document,
103103 item: &CompletionItem,
helix-term/src/ui/menu.rs+3−12
@@ -74,15 +74,15 @@ impl<T: Item> Menu<T> {
7474 // rendering)
7575 pub fn new(
7676 options: Vec<T>,
77− sort: bool,
7877 editor_data: <T as Item>::Data,
7978 callback_fn: impl Fn(&mut Editor, Option<&T>, MenuEvent) + 'static,
8079 ) -> Self {
81− let mut menu = Self {
80+ let matches = (0..options.len()).map(|i| (i, 0)).collect();
81+ Self {
8282 options,
8383 editor_data,
8484 matcher: Box::new(Matcher::default()),
85− matches: Vec::new(),
85+ matches,
8686 cursor: None,
8787 widths: Vec::new(),
8888 callback_fn: Box::new(callback_fn),
@@ -90,16 +90,7 @@ impl<T: Item> Menu<T> {
9090 size: (0, 0),
9191 viewport: (0, 0),
9292 recalculate: true,
93− };
94−
95− if sort {
96− // TODO: scoring on empty input should just use a fastpath
97− menu.score("");
98− } else {
99− menu.matches = (0..menu.options.len()).map(|i| (i, 0)).collect();
10093 }
101−
102− menu
10394 }
10495
10596 pub fn score(&mut self, pattern: &str) {