Skip to content

Commit

Permalink
never sort menu items when no fuzzy matching is possible
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe committed Oct 13, 2022
1 parent f813ccc commit 3f4296b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
45 changes: 22 additions & 23 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,35 +490,34 @@ pub fn code_action(cx: &mut Context) {
_ => 7,
});

let mut picker =
ui::Menu::new(actions, false, (), move |editor, code_action, event| {
if event != PromptEvent::Validate {
return;
}
let mut picker = ui::Menu::new(actions, (), move |editor, code_action, event| {
if event != PromptEvent::Validate {
return;
}

// always present here
let code_action = code_action.unwrap();
// always present here
let code_action = code_action.unwrap();

match code_action {
lsp::CodeActionOrCommand::Command(command) => {
log::debug!("code action command: {:?}", command);
execute_lsp_command(editor, command.clone());
match code_action {
lsp::CodeActionOrCommand::Command(command) => {
log::debug!("code action command: {:?}", command);
execute_lsp_command(editor, command.clone());
}
lsp::CodeActionOrCommand::CodeAction(code_action) => {
log::debug!("code action: {:?}", code_action);
if let Some(ref workspace_edit) = code_action.edit {
log::debug!("edit: {:?}", workspace_edit);
apply_workspace_edit(editor, offset_encoding, workspace_edit);
}
lsp::CodeActionOrCommand::CodeAction(code_action) => {
log::debug!("code action: {:?}", code_action);
if let Some(ref workspace_edit) = code_action.edit {
log::debug!("edit: {:?}", workspace_edit);
apply_workspace_edit(editor, offset_encoding, workspace_edit);
}

// if code action provides both edit and command first the edit
// should be applied and then the command
if let Some(command) = &code_action.command {
execute_lsp_command(editor, command.clone());
}
// if code action provides both edit and command first the edit
// should be applied and then the command
if let Some(command) = &code_action.command {
execute_lsp_command(editor, command.clone());
}
}
});
}
});
picker.move_down(); // pre-select the first item

let popup = Popup::new("code-action", picker);
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Completion {
start_offset: usize,
trigger_offset: usize,
) -> Self {
let menu = Menu::new(items, true, (), move |editor: &mut Editor, item, event| {
let menu = Menu::new(items, (), move |editor: &mut Editor, item, event| {
fn item_to_transaction(
doc: &Document,
item: &CompletionItem,
Expand Down
15 changes: 3 additions & 12 deletions helix-term/src/ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,23 @@ impl<T: Item> Menu<T> {
// rendering)
pub fn new(
options: Vec<T>,
sort: bool,
editor_data: <T as Item>::Data,
callback_fn: impl Fn(&mut Editor, Option<&T>, MenuEvent) + 'static,
) -> Self {
let mut menu = Self {
let matches = (0..options.len()).map(|i| (i, 0)).collect();
Self {
options,
editor_data,
matcher: Box::new(Matcher::default()),
matches: Vec::new(),
matches,
cursor: None,
widths: Vec::new(),
callback_fn: Box::new(callback_fn),
scroll: 0,
size: (0, 0),
viewport: (0, 0),
recalculate: true,
};

if sort {
// TODO: scoring on empty input should just use a fastpath
menu.score("");
} else {
menu.matches = (0..menu.options.len()).map(|i| (i, 0)).collect();
}

menu
}

pub fn score(&mut self, pattern: &str) {
Expand Down

0 comments on commit 3f4296b

Please sign in to comment.