From 5622db6798f665cdb6c208970763a31902c3e37e Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 1 Apr 2024 11:45:49 -0400 Subject: [PATCH] Remove sym_picker helper fun The parent commit split out the workspace symbol picker to an inline definition so the `workspace` parameter is never passed as `true`. We should consolidate this picker definition into the symbol_picker function. --- helix-term/src/commands/lsp.rs | 86 ++++++++++++---------------------- 1 file changed, 31 insertions(+), 55 deletions(-) diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 3dfe46ad..23bcb977 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -173,60 +173,6 @@ fn display_symbol_kind(kind: lsp::SymbolKind) -> &'static str { } } -type SymbolPicker = Picker; - -fn sym_picker(symbols: Vec, workspace: bool) -> SymbolPicker { - let symbol_kind_column = ui::PickerColumn::new("kind", |item: &SymbolInformationItem, _| { - display_symbol_kind(item.symbol.kind).into() - }); - - let columns = if workspace { - vec![ - symbol_kind_column, - ui::PickerColumn::new("name", |item: &SymbolInformationItem, _| { - item.symbol.name.as_str().into() - }) - .without_filtering(), - ui::PickerColumn::new("path", |item: &SymbolInformationItem, _| { - match item.symbol.location.uri.to_file_path() { - Ok(path) => path::get_relative_path(path.as_path()) - .to_string_lossy() - .to_string() - .into(), - Err(_) => item.symbol.location.uri.to_string().into(), - } - }), - ] - } else { - vec![ - symbol_kind_column, - // Some symbols in the document symbol picker may have a URI that isn't - // the current file. It should be rare though, so we concatenate that - // URI in with the symbol name in this picker. - ui::PickerColumn::new("name", |item: &SymbolInformationItem, _| { - item.symbol.name.as_str().into() - }), - ] - }; - - Picker::new( - columns, - 1, // name column - symbols, - (), - move |cx, item, action| { - jump_to_location( - cx.editor, - &item.symbol.location, - item.offset_encoding, - action, - ); - }, - ) - .with_preview(move |_editor, item| Some(location_to_file_location(&item.symbol.location))) - .truncate_start(false) -} - #[derive(Copy, Clone, PartialEq)] enum DiagnosticsFormat { ShowSourcePath, @@ -404,7 +350,37 @@ pub fn symbol_picker(cx: &mut Context) { symbols.append(&mut lsp_items); } let call = move |_editor: &mut Editor, compositor: &mut Compositor| { - let picker = sym_picker(symbols, false); + let columns = vec![ + ui::PickerColumn::new("kind", |item: &SymbolInformationItem, _| { + display_symbol_kind(item.symbol.kind).into() + }), + // Some symbols in the document symbol picker may have a URI that isn't + // the current file. It should be rare though, so we concatenate that + // URI in with the symbol name in this picker. + ui::PickerColumn::new("name", |item: &SymbolInformationItem, _| { + item.symbol.name.as_str().into() + }), + ]; + + let picker = Picker::new( + columns, + 1, // name column + symbols, + (), + move |cx, item, action| { + jump_to_location( + cx.editor, + &item.symbol.location, + item.offset_encoding, + action, + ); + }, + ) + .with_preview(move |_editor, item| { + Some(location_to_file_location(&item.symbol.location)) + }) + .truncate_start(false); + compositor.push(Box::new(overlaid(picker))) };