mouse_context_menu.rs

 1use crate::{DisplayPoint, Editor, EditorMode, SelectMode};
 2use context_menu::ContextMenuItem;
 3use gpui::{Pixels, Point, ViewContext};
 4
 5pub fn deploy_context_menu(
 6    editor: &mut Editor,
 7    position: Point<Pixels>,
 8    point: DisplayPoint,
 9    cx: &mut ViewContext<Editor>,
10) {
11    todo!();
12
13    // if !editor.focused {
14    //     cx.focus_self();
15    // }
16
17    // // Don't show context menu for inline editors
18    // if editor.mode() != EditorMode::Full {
19    //     return;
20    // }
21
22    // // Don't show the context menu if there isn't a project associated with this editor
23    // if editor.project.is_none() {
24    //     return;
25    // }
26
27    // // Move the cursor to the clicked location so that dispatched actions make sense
28    // editor.change_selections(None, cx, |s| {
29    //     s.clear_disjoint();
30    //     s.set_pending_display_range(point..point, SelectMode::Character);
31    // });
32
33    // editor.mouse_context_menu.update(cx, |menu, cx| {
34    //     menu.show(
35    //         position,
36    //         AnchorCorner::TopLeft,
37    //         vec![
38    //             ContextMenuItem::action("Rename Symbol", Rename),
39    //             ContextMenuItem::action("Go to Definition", GoToDefinition),
40    //             ContextMenuItem::action("Go to Type Definition", GoToTypeDefinition),
41    //             ContextMenuItem::action("Find All References", FindAllReferences),
42    //             ContextMenuItem::action(
43    //                 "Code Actions",
44    //                 ToggleCodeActions {
45    //                     deployed_from_indicator: false,
46    //                 },
47    //             ),
48    //             ContextMenuItem::Separator,
49    //             ContextMenuItem::action("Reveal in Finder", RevealInFinder),
50    //         ],
51    //         cx,
52    //     );
53    // });
54    // cx.notify();
55}
56
57// #[cfg(test)]
58// mod tests {
59//     use super::*;
60//     use crate::{editor_tests::init_test, test::editor_lsp_test_context::EditorLspTestContext};
61//     use indoc::indoc;
62
63//     #[gpui::test]
64//     async fn test_mouse_context_menu(cx: &mut gpui::TestAppContext) {
65//         init_test(cx, |_| {});
66
67//         let mut cx = EditorLspTestContext::new_rust(
68//             lsp::ServerCapabilities {
69//                 hover_provider: Some(lsp::HoverProviderCapability::Simple(true)),
70//                 ..Default::default()
71//             },
72//             cx,
73//         )
74//         .await;
75
76//         cx.set_state(indoc! {"
77//             fn teˇst() {
78//                 do_work();
79//             }
80//         "});
81//         let point = cx.display_point(indoc! {"
82//             fn test() {
83//                 do_wˇork();
84//             }
85//         "});
86//         cx.update_editor(|editor, cx| deploy_context_menu(editor, Default::default(), point, cx));
87
88//         cx.assert_editor_state(indoc! {"
89//             fn test() {
90//                 do_wˇork();
91//             }
92//         "});
93//         cx.editor(|editor, app| assert!(editor.mouse_context_menu.read(app).visible()));
94//     }
95// }