Skip to content

Commit

Permalink
Fix error message shown for goto references (helix-editor#9382)
Browse files Browse the repository at this point in the history
  • Loading branch information
theteachr authored and Schuyler Mortimer committed Jul 10, 2024
1 parent 7b8fa2d commit e30f195
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ pub fn apply_workspace_edit(
Ok(())
}

/// Precondition: `locations` should be non-empty.
fn goto_impl(
editor: &mut Editor,
compositor: &mut Compositor,
Expand All @@ -1022,9 +1023,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| {
let Some(l) = location else { return };
Expand Down Expand Up @@ -1067,7 +1066,11 @@ where
future,
move |editor, compositor, response: Option<lsp::GotoDefinitionResponse>| {
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);
}
},
);
}
Expand Down Expand Up @@ -1127,7 +1130,11 @@ pub fn goto_reference(cx: &mut Context) {
future,
move |editor, compositor, response: Option<Vec<lsp::Location>>| {
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);
}
},
);
}
Expand Down

0 comments on commit e30f195

Please sign in to comment.