diff --git a/crates/editor/src/hover_links.rs b/crates/editor/src/hover_links.rs index fa530f4434..00d02a11bd 100644 --- a/crates/editor/src/hover_links.rs +++ b/crates/editor/src/hover_links.rs @@ -1,11 +1,10 @@ use crate::{ - Anchor, Editor, EditorSettings, EditorSnapshot, FindAllReferences, GoToDefinition, - GoToDefinitionSplit, GoToTypeDefinition, GoToTypeDefinitionSplit, GotoDefinitionKind, - HighlightKey, Navigated, PointForPosition, SelectPhase, - editor_settings::GoToDefinitionFallback, scroll::ScrollAmount, + Anchor, Editor, EditorSettings, EditorSnapshot, FindAllReferences, GoToDefinitionSplit, + GoToTypeDefinition, GoToTypeDefinitionSplit, GotoDefinitionKind, HighlightKey, Navigated, + PointForPosition, SelectPhase, editor_settings::GoToDefinitionFallback, scroll::ScrollAmount, }; use gpui::{ - App, AsyncWindowContext, Context, Entity, HighlightStyle, Modifiers, Pixels, Task, + App, AsyncWindowContext, Context, Entity, Focusable, HighlightStyle, Modifiers, Pixels, Task, UnderlineStyle, Window, px, }; use language::{Bias, ToOffset}; @@ -207,26 +206,22 @@ impl Editor { window: &mut Window, cx: &mut Context, ) { + let focus_handle = self.focus_handle(cx); let reveal_task = self.cmd_click_reveal_task(point, modifiers, window, cx); - cx.spawn_in(window, async move |editor, cx| { + cx.spawn_in(window, async move |_, cx| { let definition_revealed = reveal_task.await.log_err().unwrap_or(Navigated::No); - let find_references = editor - .update_in(cx, |editor, window, cx| { - if definition_revealed == Navigated::Yes { - return None; - } - match EditorSettings::get_global(cx).go_to_definition_fallback { - GoToDefinitionFallback::None => None, - GoToDefinitionFallback::FindAllReferences => { - editor.find_all_references(&FindAllReferences::default(), window, cx) - } - } - }) - .ok() - .flatten(); - if let Some(find_references) = find_references { - find_references.await.log_err(); + if definition_revealed == Navigated::Yes { + return; } + cx.update(|window, cx| { + match EditorSettings::get_global(cx).go_to_definition_fallback { + GoToDefinitionFallback::None => {} + GoToDefinitionFallback::FindAllReferences => { + focus_handle.dispatch_action(&FindAllReferences::default(), window, cx); + } + } + }) + .ok(); }) .detach(); } @@ -328,7 +323,9 @@ impl Editor { } (true, false) => self.go_to_type_definition(&GoToTypeDefinition, window, cx), (false, true) => self.go_to_definition_split(&GoToDefinitionSplit, window, cx), - (false, false) => self.go_to_definition(&GoToDefinition::default(), window, cx), + (false, false) => { + self.go_to_definition_of_kind(GotoDefinitionKind::Symbol, false, window, cx) + } } } else { Task::ready(Ok(Navigated::No)) diff --git a/crates/editor/src/navigation.rs b/crates/editor/src/navigation.rs index fef44102f6..737227777c 100644 --- a/crates/editor/src/navigation.rs +++ b/crates/editor/src/navigation.rs @@ -2372,7 +2372,7 @@ impl Editor { }) } - fn go_to_definition_of_kind( + pub(crate) fn go_to_definition_of_kind( &mut self, kind: GotoDefinitionKind, split: bool, diff --git a/crates/lsp_locations/src/lsp_locations.rs b/crates/lsp_locations/src/lsp_locations.rs index 90f29ae7bc..807856eb81 100644 --- a/crates/lsp_locations/src/lsp_locations.rs +++ b/crates/lsp_locations/src/lsp_locations.rs @@ -778,6 +778,7 @@ mod tests { use editor::test::editor_lsp_test_context::EditorLspTestContext; use gpui::TestAppContext; use indoc::indoc; + use workspace::Item as _; async fn rust_cx( capabilities: lsp::ServerCapabilities, @@ -969,4 +970,46 @@ mod tests { assert_eq!(matches(&mut cx, "zzzz"), 0); assert_eq!(matches(&mut cx, ""), 2); } + + #[gpui::test] + async fn test_cmd_click_fallback_honors_lsp_results_location(cx: &mut TestAppContext) { + cx.update(crate::init); + let mut cx = rust_cx( + lsp::ServerCapabilities { + definition_provider: Some(lsp::OneOf::Left(true)), + references_provider: Some(lsp::OneOf::Left(true)), + ..Default::default() + }, + cx, + ) + .await; + cx.update(|_window, cx| { + cx.update_global::(|settings, cx| { + settings.update_user_settings(cx, |settings| { + settings.editor.lsp_results_location = Some(OpenResultsIn::Picker); + }); + }); + }); + cx.set_state(SOURCE); + cx.lsp + .set_request_handler::(async move |_params, _| { + Ok(None) + }); + cx.lsp + .set_request_handler::(async move |params, _| { + let uri = params.text_document_position.text_document.uri; + Ok(Some(references(uri, &[(1, 8, 11), (2, 14, 17)]))) + }); + + let screen_coord = cx + .editor(|editor, _, cx| editor.pixel_position_of_cursor(cx)) + .unwrap(); + cx.simulate_click(screen_coord, gpui::Modifiers::secondary_key()); + cx.run_until_parked(); + + assert!( + active_picker(&mut cx).is_some(), + "the cmd-click go-to-definition fallback should open the references picker when lsp_results_location is picker" + ); + } }