From 4554ff8ffc993f9efa4b9dd25f67bd6296666a89 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 25 Jan 2024 10:41:12 +0530 Subject: [PATCH] Fix error message shown for goto references (#9382) --- helix-term/src/commands/lsp.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index de2f0e5ec289..c694ba25c329 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -1007,6 +1007,7 @@ pub fn apply_workspace_edit( Ok(()) } +/// Precondition: `locations` should be non-empty. fn goto_impl( editor: &mut Editor, compositor: &mut Compositor, @@ -1019,9 +1020,7 @@ fn goto_impl( [location] => { jump_to_location(editor, location, offset_encoding, Action::Replace); } - [] => { - editor.set_error("No definition found."); - } + [] => unreachable!("`locations` should be non-empty for `goto_impl`"), _locations => { let picker = Picker::new(locations, cwdir, move |cx, location, action| { jump_to_location(cx.editor, location, offset_encoding, action) @@ -1063,7 +1062,11 @@ where future, move |editor, compositor, response: Option| { let items = to_locations(response); - goto_impl(editor, compositor, items, offset_encoding); + if items.is_empty() { + editor.set_error("No definition found."); + } else { + goto_impl(editor, compositor, items, offset_encoding); + } }, ); } @@ -1123,7 +1126,11 @@ pub fn goto_reference(cx: &mut Context) { future, move |editor, compositor, response: Option>| { let items = response.unwrap_or_default(); - goto_impl(editor, compositor, items, offset_encoding); + if items.is_empty() { + editor.set_error("No references found."); + } else { + goto_impl(editor, compositor, items, offset_encoding); + } }, ); }