on master help sign in
never sort menu items when no fuzzy matching is possible
189aa0bPascal Kuthe
helix-term/src/commands/lsp.rs+22−23
@@ -490,35 +490,34 @@ pub fn code_action(cx: &mut Context) {
490 _ => 7,
490 _ => 7,
491 });
491 });
492
492
493− let mut picker =
494− ui::Menu::new(actions, false, (), move |editor, code_action, event| {
493+ let mut picker = ui::Menu::new(actions, (), move |editor, code_action, event| {
495− if event != PromptEvent::Validate {
494+ if event != PromptEvent::Validate {
496− return;
495+ return;
497− }
496+ }
498
497
499− // always present here
498+ // always present here
500− let code_action = code_action.unwrap();
499+ let code_action = code_action.unwrap();
501
500
502− match code_action {
501+ match code_action {
503− lsp::CodeActionOrCommand::Command(command) => {
502+ lsp::CodeActionOrCommand::Command(command) => {
504− log::debug!("code action command: {:?}", command);
503+ log::debug!("code action command: {:?}", command);
505− execute_lsp_command(editor, command.clone());
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);
506 }
511 }
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− }
513
512
514− // if code action provides both edit and command first the edit
513+ // if code action provides both edit and command first the edit
515− // should be applied and then the command
514+ // should be applied and then the command
516− if let Some(command) = &code_action.command {
515+ if let Some(command) = &code_action.command {
517− execute_lsp_command(editor, command.clone());
516+ execute_lsp_command(editor, command.clone());
518− }
519 }
517 }
520 }
518 }
519+ }
521− });
520+ });
522 picker.move_down(); // pre-select the first item
521 picker.move_down(); // pre-select the first item
523
522
524 let popup = Popup::new("code-action", picker);
523 let popup = Popup::new("code-action", picker);
helix-term/src/ui/completion.rs+1−1
@@ -97,7 +97,7 @@ impl Completion {
97 start_offset: usize,
97 start_offset: usize,
98 trigger_offset: usize,
98 trigger_offset: usize,
99 ) -> Self {
99 ) -> 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| {
101 fn item_to_transaction(
101 fn item_to_transaction(
102 doc: &Document,
102 doc: &Document,
103 item: &CompletionItem,
103 item: &CompletionItem,
helix-term/src/ui/menu.rs+3−12
@@ -74,15 +74,15 @@ impl<T: Item> Menu<T> {
74 // rendering)
74 // rendering)
75 pub fn new(
75 pub fn new(
76 options: Vec<T>,
76 options: Vec<T>,
77− sort: bool,
78 editor_data: <T as Item>::Data,
77 editor_data: <T as Item>::Data,
79 callback_fn: impl Fn(&mut Editor, Option<&T>, MenuEvent) + 'static,
78 callback_fn: impl Fn(&mut Editor, Option<&T>, MenuEvent) + 'static,
80 ) -> Self {
79 ) -> Self {
80+ let matches = (0..options.len()).map(|i| (i, 0)).collect();
81− let mut menu = Self {
81+ Self {
82 options,
82 options,
83 editor_data,
83 editor_data,
84 matcher: Box::new(Matcher::default()),
84 matcher: Box::new(Matcher::default()),
85− matches: Vec::new(),
85+ matches,
86 cursor: None,
86 cursor: None,
87 widths: Vec::new(),
87 widths: Vec::new(),
88 callback_fn: Box::new(callback_fn),
88 callback_fn: Box::new(callback_fn),
@@ -90,16 +90,7 @@ impl<T: Item> Menu<T> {
90 size: (0, 0),
90 size: (0, 0),
91 viewport: (0, 0),
91 viewport: (0, 0),
92 recalculate: true,
92 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();
100 }
93 }
101−
102− menu
103 }
94 }
104
95
105 pub fn score(&mut self, pattern: &str) {
96 pub fn score(&mut self, pattern: &str) {