1use context_menu::ContextMenuItem;
2use gpui::{geometry::vector::Vector2F, impl_internal_actions, MutableAppContext, ViewContext};
3
4use crate::{
5 DisplayPoint, Editor, EditorMode, FindAllReferences, GoToDefinition, Rename, SelectMode,
6 ToggleCodeActions,
7};
8
9#[derive(Clone, PartialEq)]
10pub struct DeployMouseContextMenu {
11 pub position: Vector2F,
12 pub point: DisplayPoint,
13}
14
15impl_internal_actions!(editor, [DeployMouseContextMenu]);
16
17pub fn init(cx: &mut MutableAppContext) {
18 cx.add_action(deploy_context_menu);
19}
20
21pub fn deploy_context_menu(
22 editor: &mut Editor,
23 &DeployMouseContextMenu { position, point }: &DeployMouseContextMenu,
24 cx: &mut ViewContext<Editor>,
25) {
26 // Don't show context menu for inline editors
27 if editor.mode() != EditorMode::Full {
28 return;
29 }
30
31 // Don't show the context menu if there isn't a project associated with this editor
32 if editor.project.is_none() {
33 return;
34 }
35
36 // Move the cursor to the clicked location so that dispatched actions make sense
37 editor.change_selections(None, cx, |s| {
38 s.clear_disjoint();
39 s.set_pending_display_range(point..point, SelectMode::Character);
40 });
41
42 editor.mouse_context_menu.update(cx, |menu, cx| {
43 menu.show(
44 position,
45 vec![
46 ContextMenuItem::item("Rename Symbol", Rename),
47 ContextMenuItem::item("Go To Definition", GoToDefinition),
48 ContextMenuItem::item("Find All References", FindAllReferences),
49 ContextMenuItem::item(
50 "Code Actions",
51 ToggleCodeActions {
52 deployed_from_indicator: false,
53 },
54 ),
55 ],
56 cx,
57 );
58 });
59 cx.notify();
60}