From 9206f0a876dff1316f2f77f8b026c90b55608281 Mon Sep 17 00:00:00 2001 From: Peter Retzlaff Date: Tue, 8 Jul 2025 09:38:31 +0200 Subject: [PATCH] Add filter_format field for Column in pickers Add the option to provide a formatting function for the filtering of picker columns that is separate from the formatting function for displaying it in the view. Use this new option for the "path" column of the workspace diagnostics picker, so that we are filtering on the full (relative) file path, instead of the truncated value. Fixes #13608 --- helix-term/src/commands/lsp.rs | 10 ++++++++++ helix-term/src/ui/picker.rs | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index ac9dd6e27..214629323 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -281,6 +281,16 @@ fn diag_picker( } else { Default::default() } + }) + .with_filter_format(|item: &PickerDiagnostic, _| { + if let Some(path) = item.location.uri.as_path() { + path::get_relative_path(path) + .to_string_lossy() + .to_string() + .into() + } else { + Default::default() + } }), ); primary_column += 1; diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 3f3aaba2b..ed968a1fa 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -137,7 +137,7 @@ fn inject_nucleo_item( ) { injector.push(item, |item, dst| { for (column, text) in columns.iter().filter(|column| column.filter).zip(dst) { - *text = column.format_text(item, editor_data).into() + *text = column.format_filter_text(item, editor_data).into() } }); } @@ -189,6 +189,7 @@ type ColumnFormatFn = for<'a> fn(&'a T, &'a D) -> Cell<'a>; pub struct Column { name: Arc, format: ColumnFormatFn, + filter_format: ColumnFormatFn, /// Whether the column should be passed to nucleo for matching and filtering. /// `DynamicPicker` uses this so that the dynamic column (for example regex in /// global search) is not used for filtering twice. @@ -201,6 +202,7 @@ impl Column { Self { name: name.into(), format, + filter_format: format, filter: true, hidden: false, } @@ -213,6 +215,7 @@ impl Column { Self { name: name.into(), format, + filter_format: format, filter: false, hidden: true, } @@ -223,12 +226,18 @@ impl Column { self } + pub fn with_filter_format(mut self, format_fn: ColumnFormatFn) -> Self { + self.filter_format = format_fn; + self + } + fn format<'a>(&self, item: &'a T, data: &'a D) -> Cell<'a> { (self.format)(item, data) } - fn format_text<'a>(&self, item: &'a T, data: &'a D) -> Cow<'a, str> { - let text: String = self.format(item, data).content.into(); + fn format_filter_text<'a>(&self, item: &'a T, data: &'a D) -> Cow<'a, str> { + let cell = (self.filter_format)(item, data); + let text: String = cell.content.into(); text.into() } }