From bf0ec13e65b9842a4ed2675631502196d9d977ef Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 3 Aug 2022 15:59:25 -0700 Subject: [PATCH 1/9] New button --- assets/keymaps/default.json | 2 +- crates/terminal/src/terminal_view.rs | 10 +++-- crates/workspace/src/pane.rs | 57 ++++++++++++++++++++++++++-- crates/workspace/src/workspace.rs | 1 + 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 63b00c1d9ecfd2f1df71cf8b0361c365a9b6be3d..f9735e7cee05fada9613da6de18f48e3e837e010 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -31,7 +31,7 @@ "cmd-n": "workspace::NewFile", "cmd-shift-n": "workspace::NewWindow", "cmd-o": "workspace::Open", - "ctrl-`": "terminal::Deploy" + "ctrl-`": "workspace::NewTerminal" } }, { diff --git a/crates/terminal/src/terminal_view.rs b/crates/terminal/src/terminal_view.rs index 8acf1c233acf822931ce7864eef731d1c1446b1a..40a882e4885ddda8fd992d069e0d5e292638bec9 100644 --- a/crates/terminal/src/terminal_view.rs +++ b/crates/terminal/src/terminal_view.rs @@ -5,17 +5,17 @@ use gpui::{ actions, elements::*, AnyViewHandle, AppContext, Entity, ModelHandle, View, ViewContext, ViewHandle, }; +use workspace::{Item, Workspace}; use crate::TerminalSize; use project::{LocalWorktree, Project, ProjectPath}; use settings::{Settings, WorkingDirectory}; use smallvec::SmallVec; use std::path::{Path, PathBuf}; -use workspace::{Item, Workspace}; use crate::connected_el::TerminalEl; -actions!(terminal, [Deploy, DeployModal]); +actions!(terminal, [DeployModal]); //Make terminal view an enum, that can give you views for the error and non-error states //Take away all the result unwrapping in the current TerminalView by making it 'infallible' @@ -59,7 +59,11 @@ impl Entity for ErrorView { impl TerminalView { ///Create a new Terminal in the current working directory or the user's home directory - pub fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext) { + pub fn deploy( + workspace: &mut Workspace, + _: &workspace::NewTerminal, + cx: &mut ViewContext, + ) { let strategy = cx .global::() .terminal_overrides diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 7ba8badc9dce7d39d85c552574433a45cd558e53..386b151e243f5ca60a67dc11e463c9557b8702a0 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1,5 +1,5 @@ use super::{ItemHandle, SplitDirection}; -use crate::{toolbar::Toolbar, Item, WeakItemHandle, Workspace}; +use crate::{toolbar::Toolbar, Item, NewFile, NewTerminal, WeakItemHandle, Workspace}; use anyhow::Result; use collections::{HashMap, HashSet, VecDeque}; use context_menu::{ContextMenu, ContextMenuItem}; @@ -65,8 +65,13 @@ pub struct DeploySplitMenu { position: Vector2F, } +#[derive(Clone, PartialEq)] +pub struct DeployNewMenu { + position: Vector2F, +} + impl_actions!(pane, [GoBack, GoForward, ActivateItem]); -impl_internal_actions!(pane, [CloseItem, DeploySplitMenu]); +impl_internal_actions!(pane, [CloseItem, DeploySplitMenu, DeployNewMenu]); const MAX_NAVIGATION_HISTORY_LEN: usize = 1024; @@ -98,6 +103,7 @@ pub fn init(cx: &mut MutableAppContext) { cx.add_action(|pane: &mut Pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx)); cx.add_action(|pane: &mut Pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx)); cx.add_action(Pane::deploy_split_menu); + cx.add_action(Pane::deploy_new_menu); cx.add_action(|workspace: &mut Workspace, _: &ReopenClosedItem, cx| { Pane::reopen_closed_item(workspace, cx).detach(); }); @@ -845,6 +851,19 @@ impl Pane { }); } + fn deploy_new_menu(&mut self, action: &DeployNewMenu, cx: &mut ViewContext) { + self.split_menu.update(cx, |menu, cx| { + menu.show( + action.position, + vec![ + ContextMenuItem::item("New File", NewFile), + ContextMenuItem::item("New Terminal", NewTerminal), + ], + cx, + ); + }); + } + pub fn toolbar(&self) -> &ViewHandle { &self.toolbar } @@ -1083,10 +1102,40 @@ impl View for Pane { .with_child(self.render_tabs(cx).flex(1., true).named("tabs")); if self.is_active { - tab_row.add_child( + tab_row.add_children([ MouseEventHandler::new::( 0, cx, + |mouse_state, cx| { + let theme = + &cx.global::().theme.workspace.tab_bar; + let style = + theme.pane_button.style_for(mouse_state, false); + Svg::new("icons/bolt_12.svg") + .with_color(style.color) + .constrained() + .with_width(style.icon_width) + .aligned() + .contained() + .with_style(style.container) + .constrained() + .with_width(style.button_width) + .with_height(style.button_width) + .aligned() + .boxed() + }, + ) + .with_cursor_style(CursorStyle::PointingHand) + .on_down( + MouseButton::Left, + |MouseButtonEvent { position, .. }, cx| { + cx.dispatch_action(DeployNewMenu { position }); + }, + ) + .boxed(), + MouseEventHandler::new::( + 1, + cx, |mouse_state, cx| { let theme = &cx.global::().theme.workspace.tab_bar; @@ -1114,7 +1163,7 @@ impl View for Pane { }, ) .boxed(), - ) + ]) } tab_row diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index c060f57072692767305e12e55fed7c2c80ce7481..c2821e1365cf9d07acb1343f6397e8a12a28b9c2 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -96,6 +96,7 @@ actions!( FollowNextCollaborator, ToggleLeftSidebar, ToggleRightSidebar, + NewTerminal, ] ); From 96cc6d5ce554e2c0a0cd0ca876b1397270b7338e Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 3 Aug 2022 16:47:41 -0700 Subject: [PATCH 2/9] Added icons to context menu --- crates/context_menu/src/context_menu.rs | 84 +++++++++++++++++------ crates/editor/src/mouse_context_menu.rs | 9 +-- crates/project_panel/src/project_panel.rs | 18 ++--- crates/theme/src/theme.rs | 2 + crates/workspace/src/pane.rs | 22 +++--- styles/src/styleTree/contextMenu.ts | 2 + 6 files changed, 93 insertions(+), 44 deletions(-) diff --git a/crates/context_menu/src/context_menu.rs b/crates/context_menu/src/context_menu.rs index 53f6bfe58776c221f9f1c761a8ffdfd78951c1c7..e66388ecd1fc37cce6358decb1d21aca4c339bcd 100644 --- a/crates/context_menu/src/context_menu.rs +++ b/crates/context_menu/src/context_menu.rs @@ -26,15 +26,17 @@ pub enum ContextMenuItem { Item { label: String, action: Box, + icon: Option, }, Separator, } impl ContextMenuItem { - pub fn item(label: impl ToString, action: impl 'static + Action) -> Self { + pub fn item(label: impl ToString, icon: Option<&str>, action: impl 'static + Action) -> Self { Self::Item { label: label.to_string(), action: Box::new(action), + icon: icon.map(|item| item.to_string()), } } @@ -254,14 +256,31 @@ impl ContextMenu { Flex::column() .with_children(self.items.iter().enumerate().map(|(ix, item)| { match item { - ContextMenuItem::Item { label, .. } => { + ContextMenuItem::Item { label, icon, .. } => { let style = style .item .style_for(Default::default(), Some(ix) == self.selected_index); - Label::new(label.to_string(), style.label.clone()) - .contained() - .with_style(style.container) - .boxed() + let mut line = Flex::row(); + if let Some(_) = icon { + line.add_child( + Empty::new() + .constrained() + .with_width(style.icon_width) + .boxed(), + ); + } + line.add_child( + Label::new(label.to_string(), style.label.clone()) + .contained() + .with_style(style.container) + .with_margin_left(if icon.is_some() { + style.icon_spacing + } else { + 0. + }) + .boxed(), + ); + line.boxed() } ContextMenuItem::Separator => Empty::new() .collapsed() @@ -314,27 +333,50 @@ impl ContextMenu { Flex::column() .with_children(self.items.iter().enumerate().map(|(ix, item)| { match item { - ContextMenuItem::Item { label, action } => { + ContextMenuItem::Item { + label, + action, + icon, + } => { let action = action.boxed_clone(); MouseEventHandler::new::(ix, cx, |state, _| { let style = style.item.style_for(state, Some(ix) == self.selected_index); - Flex::row() - .with_child( - Label::new(label.to_string(), style.label.clone()).boxed(), + + let mut line = Flex::row(); + if let Some(icon_file) = icon { + line.add_child( + Svg::new(format!("icons/{}", icon_file)) + .with_color(style.label.color) + .constrained() + .with_width(style.icon_width) + .aligned() + .boxed(), ) - .with_child({ - KeystrokeLabel::new( - action.boxed_clone(), - style.keystroke.container, - style.keystroke.text.clone(), - ) - .flex_float() - .boxed() - }) - .contained() - .with_style(style.container) + } + + line.with_child( + Label::new(label.to_string(), style.label.clone()) + .contained() + .with_margin_left(if icon.is_some() { + style.icon_spacing + } else { + 0. + }) + .boxed(), + ) + .with_child({ + KeystrokeLabel::new( + action.boxed_clone(), + style.keystroke.container, + style.keystroke.text.clone(), + ) + .flex_float() .boxed() + }) + .contained() + .with_style(style.container) + .boxed() }) .with_cursor_style(CursorStyle::PointingHand) .on_click(MouseButton::Left, move |_, cx| { diff --git a/crates/editor/src/mouse_context_menu.rs b/crates/editor/src/mouse_context_menu.rs index 513a9ed99ce06e0ac25d2f70d5f4d829155f1426..d96deb359d342ca0ebb39de089ed0455c0812624 100644 --- a/crates/editor/src/mouse_context_menu.rs +++ b/crates/editor/src/mouse_context_menu.rs @@ -48,12 +48,13 @@ pub fn deploy_context_menu( menu.show( position, vec![ - ContextMenuItem::item("Rename Symbol", Rename), - ContextMenuItem::item("Go To Definition", GoToDefinition), - ContextMenuItem::item("Go To Type Definition", GoToTypeDefinition), - ContextMenuItem::item("Find All References", FindAllReferences), + ContextMenuItem::item("Rename Symbol", None, Rename), + ContextMenuItem::item("Go To Definition", None, GoToDefinition), + ContextMenuItem::item("Go To Type Definition", None, GoToTypeDefinition), + ContextMenuItem::item("Find All References", None, FindAllReferences), ContextMenuItem::item( "Code Actions", + None, ToggleCodeActions { deployed_from_indicator: false, }, diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 0a32a8427bf489111065ca80b76c9086557e2ab8..2b5a607bed42528de5004e945d8901f93bc9a164 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -269,30 +269,32 @@ impl ProjectPanel { if !project.is_remote() { menu_entries.push(ContextMenuItem::item( "Add Folder to Project", + None, workspace::AddFolderToProject, )); if is_root { menu_entries.push(ContextMenuItem::item( "Remove from Project", + None, workspace::RemoveWorktreeFromProject(worktree_id), )); } } - menu_entries.push(ContextMenuItem::item("New File", AddFile)); - menu_entries.push(ContextMenuItem::item("New Folder", AddDirectory)); + menu_entries.push(ContextMenuItem::item("New File", None, AddFile)); + menu_entries.push(ContextMenuItem::item("New Folder", None, AddDirectory)); menu_entries.push(ContextMenuItem::Separator); - menu_entries.push(ContextMenuItem::item("Copy", Copy)); - menu_entries.push(ContextMenuItem::item("Copy Path", CopyPath)); - menu_entries.push(ContextMenuItem::item("Cut", Cut)); + menu_entries.push(ContextMenuItem::item("Copy", None, Copy)); + menu_entries.push(ContextMenuItem::item("Copy Path", None, CopyPath)); + menu_entries.push(ContextMenuItem::item("Cut", None, Cut)); if let Some(clipboard_entry) = self.clipboard_entry { if clipboard_entry.worktree_id() == worktree.id() { - menu_entries.push(ContextMenuItem::item("Paste", Paste)); + menu_entries.push(ContextMenuItem::item("Paste", None, Paste)); } } menu_entries.push(ContextMenuItem::Separator); - menu_entries.push(ContextMenuItem::item("Rename", Rename)); + menu_entries.push(ContextMenuItem::item("Rename", None, Rename)); if !is_root { - menu_entries.push(ContextMenuItem::item("Delete", Delete)); + menu_entries.push(ContextMenuItem::item("Delete", None, Delete)); } } diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index 349a505a08d0cb52b04ce5256530b92fb71e55fa..1aaeed2d7829739c4006f6aa645a89f739012367 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -267,6 +267,8 @@ pub struct ContextMenuItem { pub container: ContainerStyle, pub label: TextStyle, pub keystroke: ContainedText, + pub icon_width: f32, + pub icon_spacing: f32, } #[derive(Debug, Deserialize, Default)] diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 386b151e243f5ca60a67dc11e463c9557b8702a0..3abd05da26eb080a08aae56c15080f5372b8efcf 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -147,7 +147,7 @@ pub struct Pane { autoscroll: bool, nav_history: Rc>, toolbar: ViewHandle, - split_menu: ViewHandle, + context_menu: ViewHandle, } pub struct ItemNavHistory { @@ -203,7 +203,7 @@ impl Pane { pane: handle.clone(), })), toolbar: cx.add_view(|_| Toolbar::new(handle)), - split_menu, + context_menu: split_menu, } } @@ -837,14 +837,14 @@ impl Pane { } fn deploy_split_menu(&mut self, action: &DeploySplitMenu, cx: &mut ViewContext) { - self.split_menu.update(cx, |menu, cx| { + self.context_menu.update(cx, |menu, cx| { menu.show( action.position, vec![ - ContextMenuItem::item("Split Right", SplitRight), - ContextMenuItem::item("Split Left", SplitLeft), - ContextMenuItem::item("Split Up", SplitUp), - ContextMenuItem::item("Split Down", SplitDown), + ContextMenuItem::item("Split Right", None, SplitRight), + ContextMenuItem::item("Split Left", None, SplitLeft), + ContextMenuItem::item("Split Up", None, SplitUp), + ContextMenuItem::item("Split Down", None, SplitDown), ], cx, ); @@ -852,12 +852,12 @@ impl Pane { } fn deploy_new_menu(&mut self, action: &DeployNewMenu, cx: &mut ViewContext) { - self.split_menu.update(cx, |menu, cx| { + self.context_menu.update(cx, |menu, cx| { menu.show( action.position, vec![ - ContextMenuItem::item("New File", NewFile), - ContextMenuItem::item("New Terminal", NewTerminal), + ContextMenuItem::item("New File", Some("circle_info_12.svg"), NewFile), + ContextMenuItem::item("New Terminal", Some("terminal_12.svg"), NewTerminal), ], cx, ); @@ -1204,7 +1204,7 @@ impl View for Pane { }) .boxed(), ) - .with_child(ChildView::new(&self.split_menu).boxed()) + .with_child(ChildView::new(&self.context_menu).boxed()) .named("pane") } diff --git a/styles/src/styleTree/contextMenu.ts b/styles/src/styleTree/contextMenu.ts index 0244641ec77ec62d21160ef719ac14b7d3b0c895..6236c2bc602371838bd28c4d708c9696556eca29 100644 --- a/styles/src/styleTree/contextMenu.ts +++ b/styles/src/styleTree/contextMenu.ts @@ -16,6 +16,8 @@ export default function contextMenu(theme: Theme) { border: border(theme, "primary"), keystrokeMargin: 30, item: { + iconSpacing: 8, + iconWidth: 14, padding: { left: 4, right: 4, top: 2, bottom: 2 }, cornerRadius: 6, label: text(theme, "sans", "primary", { size: "sm" }), From 314c26e4ec3673fad9535c8e1bc772169c67d13b Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 4 Aug 2022 08:42:42 -0700 Subject: [PATCH 3/9] Removed icons --- assets/keymaps/default.json | 2 +- crates/context_menu/src/context_menu.rs | 85 +++++++---------------- crates/editor/src/mouse_context_menu.rs | 9 ++- crates/project_panel/src/project_panel.rs | 18 +++-- crates/search/src/project_search.rs | 8 ++- crates/workspace/src/pane.rs | 19 ++--- crates/workspace/src/workspace.rs | 1 + crates/zed/src/menus.rs | 2 +- 8 files changed, 55 insertions(+), 89 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index f9735e7cee05fada9613da6de18f48e3e837e010..2782dd7d6a76c47c3f1e13f739969f4d8586acc5 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -300,7 +300,7 @@ 8 ], "cmd-b": "workspace::ToggleLeftSidebar", - "cmd-shift-f": "project_search::Deploy", + "cmd-shift-f": "workspace::NewSearch", "cmd-k cmd-t": "theme_selector::Toggle", "cmd-k cmd-s": "zed::OpenKeymap", "cmd-t": "project_symbols::Toggle", diff --git a/crates/context_menu/src/context_menu.rs b/crates/context_menu/src/context_menu.rs index e66388ecd1fc37cce6358decb1d21aca4c339bcd..d49f817de64a2fd0d9817e101a37f124f4d75d91 100644 --- a/crates/context_menu/src/context_menu.rs +++ b/crates/context_menu/src/context_menu.rs @@ -22,21 +22,20 @@ pub fn init(cx: &mut MutableAppContext) { cx.add_action(ContextMenu::cancel); } +// pub enum ContextMenuItem { Item { label: String, action: Box, - icon: Option, }, Separator, } impl ContextMenuItem { - pub fn item(label: impl ToString, icon: Option<&str>, action: impl 'static + Action) -> Self { + pub fn item(label: impl ToString, action: impl 'static + Action) -> Self { Self::Item { label: label.to_string(), action: Box::new(action), - icon: icon.map(|item| item.to_string()), } } @@ -256,31 +255,15 @@ impl ContextMenu { Flex::column() .with_children(self.items.iter().enumerate().map(|(ix, item)| { match item { - ContextMenuItem::Item { label, icon, .. } => { + ContextMenuItem::Item { label, .. } => { let style = style .item .style_for(Default::default(), Some(ix) == self.selected_index); - let mut line = Flex::row(); - if let Some(_) = icon { - line.add_child( - Empty::new() - .constrained() - .with_width(style.icon_width) - .boxed(), - ); - } - line.add_child( - Label::new(label.to_string(), style.label.clone()) - .contained() - .with_style(style.container) - .with_margin_left(if icon.is_some() { - style.icon_spacing - } else { - 0. - }) - .boxed(), - ); - line.boxed() + + Label::new(label.to_string(), style.label.clone()) + .contained() + .with_style(style.container) + .boxed() } ContextMenuItem::Separator => Empty::new() .collapsed() @@ -333,50 +316,30 @@ impl ContextMenu { Flex::column() .with_children(self.items.iter().enumerate().map(|(ix, item)| { match item { - ContextMenuItem::Item { - label, - action, - icon, - } => { + ContextMenuItem::Item { label, action } => { let action = action.boxed_clone(); MouseEventHandler::new::(ix, cx, |state, _| { let style = style.item.style_for(state, Some(ix) == self.selected_index); - let mut line = Flex::row(); - if let Some(icon_file) = icon { - line.add_child( - Svg::new(format!("icons/{}", icon_file)) - .with_color(style.label.color) - .constrained() - .with_width(style.icon_width) - .aligned() + Flex::row() + .with_child( + Label::new(label.to_string(), style.label.clone()) + .contained() .boxed(), ) - } - - line.with_child( - Label::new(label.to_string(), style.label.clone()) - .contained() - .with_margin_left(if icon.is_some() { - style.icon_spacing - } else { - 0. - }) - .boxed(), - ) - .with_child({ - KeystrokeLabel::new( - action.boxed_clone(), - style.keystroke.container, - style.keystroke.text.clone(), - ) - .flex_float() + .with_child({ + KeystrokeLabel::new( + action.boxed_clone(), + style.keystroke.container, + style.keystroke.text.clone(), + ) + .flex_float() + .boxed() + }) + .contained() + .with_style(style.container) .boxed() - }) - .contained() - .with_style(style.container) - .boxed() }) .with_cursor_style(CursorStyle::PointingHand) .on_click(MouseButton::Left, move |_, cx| { diff --git a/crates/editor/src/mouse_context_menu.rs b/crates/editor/src/mouse_context_menu.rs index d96deb359d342ca0ebb39de089ed0455c0812624..513a9ed99ce06e0ac25d2f70d5f4d829155f1426 100644 --- a/crates/editor/src/mouse_context_menu.rs +++ b/crates/editor/src/mouse_context_menu.rs @@ -48,13 +48,12 @@ pub fn deploy_context_menu( menu.show( position, vec![ - ContextMenuItem::item("Rename Symbol", None, Rename), - ContextMenuItem::item("Go To Definition", None, GoToDefinition), - ContextMenuItem::item("Go To Type Definition", None, GoToTypeDefinition), - ContextMenuItem::item("Find All References", None, FindAllReferences), + ContextMenuItem::item("Rename Symbol", Rename), + ContextMenuItem::item("Go To Definition", GoToDefinition), + ContextMenuItem::item("Go To Type Definition", GoToTypeDefinition), + ContextMenuItem::item("Find All References", FindAllReferences), ContextMenuItem::item( "Code Actions", - None, ToggleCodeActions { deployed_from_indicator: false, }, diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 2b5a607bed42528de5004e945d8901f93bc9a164..0a32a8427bf489111065ca80b76c9086557e2ab8 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -269,32 +269,30 @@ impl ProjectPanel { if !project.is_remote() { menu_entries.push(ContextMenuItem::item( "Add Folder to Project", - None, workspace::AddFolderToProject, )); if is_root { menu_entries.push(ContextMenuItem::item( "Remove from Project", - None, workspace::RemoveWorktreeFromProject(worktree_id), )); } } - menu_entries.push(ContextMenuItem::item("New File", None, AddFile)); - menu_entries.push(ContextMenuItem::item("New Folder", None, AddDirectory)); + menu_entries.push(ContextMenuItem::item("New File", AddFile)); + menu_entries.push(ContextMenuItem::item("New Folder", AddDirectory)); menu_entries.push(ContextMenuItem::Separator); - menu_entries.push(ContextMenuItem::item("Copy", None, Copy)); - menu_entries.push(ContextMenuItem::item("Copy Path", None, CopyPath)); - menu_entries.push(ContextMenuItem::item("Cut", None, Cut)); + menu_entries.push(ContextMenuItem::item("Copy", Copy)); + menu_entries.push(ContextMenuItem::item("Copy Path", CopyPath)); + menu_entries.push(ContextMenuItem::item("Cut", Cut)); if let Some(clipboard_entry) = self.clipboard_entry { if clipboard_entry.worktree_id() == worktree.id() { - menu_entries.push(ContextMenuItem::item("Paste", None, Paste)); + menu_entries.push(ContextMenuItem::item("Paste", Paste)); } } menu_entries.push(ContextMenuItem::Separator); - menu_entries.push(ContextMenuItem::item("Rename", None, Rename)); + menu_entries.push(ContextMenuItem::item("Rename", Rename)); if !is_root { - menu_entries.push(ContextMenuItem::item("Delete", None, Delete)); + menu_entries.push(ContextMenuItem::item("Delete", Delete)); } } diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 0becd0d1840aa28b2f716ea5a20f65287dea27fe..ab130c135081f4b88225b2dbfc9e1409fb1baa46 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -24,7 +24,7 @@ use workspace::{ Item, ItemHandle, ItemNavHistory, Pane, ToolbarItemLocation, ToolbarItemView, Workspace, }; -actions!(project_search, [Deploy, SearchInNew, ToggleFocus]); +actions!(project_search, [SearchInNew, ToggleFocus]); #[derive(Default)] struct ActiveSearches(HashMap, WeakViewHandle>); @@ -431,7 +431,11 @@ impl ProjectSearchView { // Re-activate the most recently activated search or the most recent if it has been closed. // If no search exists in the workspace, create a new one. - fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext) { + fn deploy( + workspace: &mut Workspace, + _: &workspace::NewSearch, + cx: &mut ViewContext, + ) { // Clean up entries for dropped projects cx.update_global(|state: &mut ActiveSearches, cx| { state.0.retain(|project, _| project.is_upgradable(cx)) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 3abd05da26eb080a08aae56c15080f5372b8efcf..caccda8ecf58a10d10284d6abd09434b19115cec 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1,5 +1,5 @@ use super::{ItemHandle, SplitDirection}; -use crate::{toolbar::Toolbar, Item, NewFile, NewTerminal, WeakItemHandle, Workspace}; +use crate::{toolbar::Toolbar, Item, NewFile, NewSearch, NewTerminal, WeakItemHandle, Workspace}; use anyhow::Result; use collections::{HashMap, HashSet, VecDeque}; use context_menu::{ContextMenu, ContextMenuItem}; @@ -188,7 +188,7 @@ pub struct NavigationEntry { impl Pane { pub fn new(cx: &mut ViewContext) -> Self { let handle = cx.weak_handle(); - let split_menu = cx.add_view(|cx| ContextMenu::new(cx)); + let context_menu = cx.add_view(|cx| ContextMenu::new(cx)); Self { items: Vec::new(), is_active: true, @@ -203,7 +203,7 @@ impl Pane { pane: handle.clone(), })), toolbar: cx.add_view(|_| Toolbar::new(handle)), - context_menu: split_menu, + context_menu, } } @@ -841,10 +841,10 @@ impl Pane { menu.show( action.position, vec![ - ContextMenuItem::item("Split Right", None, SplitRight), - ContextMenuItem::item("Split Left", None, SplitLeft), - ContextMenuItem::item("Split Up", None, SplitUp), - ContextMenuItem::item("Split Down", None, SplitDown), + ContextMenuItem::item("Split Right", SplitRight), + ContextMenuItem::item("Split Left", SplitLeft), + ContextMenuItem::item("Split Up", SplitUp), + ContextMenuItem::item("Split Down", SplitDown), ], cx, ); @@ -856,8 +856,9 @@ impl Pane { menu.show( action.position, vec![ - ContextMenuItem::item("New File", Some("circle_info_12.svg"), NewFile), - ContextMenuItem::item("New Terminal", Some("terminal_12.svg"), NewTerminal), + ContextMenuItem::item("New File", NewFile), + ContextMenuItem::item("New Terminal", NewTerminal), + ContextMenuItem::item("New Search", NewSearch), ], cx, ); diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index c2821e1365cf9d07acb1343f6397e8a12a28b9c2..045e9c6f90de3cc5ed54411607519391a76fea6b 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -97,6 +97,7 @@ actions!( ToggleLeftSidebar, ToggleRightSidebar, NewTerminal, + NewSearch ] ); diff --git a/crates/zed/src/menus.rs b/crates/zed/src/menus.rs index f4a5e5e24dfd270430b593429e52a7735c9dde6f..71ab1d14e5213a73c0214778811843d2fda60a1a 100644 --- a/crates/zed/src/menus.rs +++ b/crates/zed/src/menus.rs @@ -136,7 +136,7 @@ pub fn menus() -> Vec> { }, MenuItem::Action { name: "Find In Project", - action: Box::new(search::project_search::Deploy), + action: Box::new(workspace::NewSearch), }, MenuItem::Separator, MenuItem::Action { From 907d3e403569a2aab7d080c1caa8c07eaec470b4 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 4 Aug 2022 10:16:26 -0700 Subject: [PATCH 4/9] Checkpoint, not compiling --- Cargo.lock | 1 + crates/terminal/Cargo.toml | 1 + crates/terminal/src/terminal_view.rs | 3 +++ 3 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a32f08d8f75b8ee14bf51886ecf5159ebc620d87..60518a2fafe06928fbbb28074a5322940632c218 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5356,6 +5356,7 @@ dependencies = [ "alacritty_terminal", "anyhow", "client", + "context_menu", "dirs 4.0.0", "editor", "futures", diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.toml index d06d16b1bad19be4e9481a81e670cd607b5395c3..732a03ed1e0ec74879b621fbfdae6df1fd2624f7 100644 --- a/crates/terminal/Cargo.toml +++ b/crates/terminal/Cargo.toml @@ -16,6 +16,7 @@ theme = { path = "../theme" } settings = { path = "../settings" } workspace = { path = "../workspace" } project = { path = "../project" } +context_menu = { path = "../context_menu" } smallvec = { version = "1.6", features = ["union"] } smol = "1.2.5" mio-extras = "2.0.6" diff --git a/crates/terminal/src/terminal_view.rs b/crates/terminal/src/terminal_view.rs index 40a882e4885ddda8fd992d069e0d5e292638bec9..309b3be11ad9b0eaf748b8b7058776c7648e6962 100644 --- a/crates/terminal/src/terminal_view.rs +++ b/crates/terminal/src/terminal_view.rs @@ -5,6 +5,7 @@ use gpui::{ actions, elements::*, AnyViewHandle, AppContext, Entity, ModelHandle, View, ViewContext, ViewHandle, }; +use theme::ContextMenu; use workspace::{Item, Workspace}; use crate::TerminalSize; @@ -39,6 +40,7 @@ pub struct TerminalView { modal: bool, pub content: TerminalContent, associated_directory: Option, + context_menu: ViewHandle, } pub struct ErrorView { @@ -111,6 +113,7 @@ impl TerminalView { modal, content, associated_directory: working_directory, + context_menu: cx.add_view(|cx| ContextMenu::new(cx)), } } From d823da05ee4654af9dcda71d52ab1d7dd542e083 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 4 Aug 2022 11:22:09 -0700 Subject: [PATCH 5/9] Added context menu to terminal --- crates/terminal/src/connected_el.rs | 10 ++++++- crates/terminal/src/connected_view.rs | 41 ++++++++++++++++++++++++--- crates/terminal/src/terminal.rs | 3 +- crates/terminal/src/terminal_view.rs | 13 +++++---- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/crates/terminal/src/connected_el.rs b/crates/terminal/src/connected_el.rs index b4369ab55e02a8a8c358a25bbed4de316e04d56a..000338c680ab1e1ce0bbf531b22ae452fe2c9013 100644 --- a/crates/terminal/src/connected_el.rs +++ b/crates/terminal/src/connected_el.rs @@ -33,7 +33,9 @@ use std::{ use std::{fmt::Debug, ops::Sub}; use crate::{ - connected_view::ConnectedView, mappings::colors::convert_color, Terminal, TerminalSize, + connected_view::{ConnectedView, DeployContextMenu}, + mappings::colors::convert_color, + Terminal, TerminalSize, }; ///Scrolling is unbearably sluggish by default. Alacritty supports a configurable @@ -463,6 +465,12 @@ impl TerminalEl { } }, ) + .on_click( + MouseButton::Right, + move |MouseButtonEvent { position, .. }, cx| { + cx.dispatch_action(DeployContextMenu { position }); + }, + ) .on_drag( MouseButton::Left, move |_, MouseMovedEvent { position, .. }, cx| { diff --git a/crates/terminal/src/connected_view.rs b/crates/terminal/src/connected_view.rs index e6e10c84bf2873e46fd742040508078ff6e3e861..5e336dcb03ed9aec92b4818781d30edeb97a9e82 100644 --- a/crates/terminal/src/connected_view.rs +++ b/crates/terminal/src/connected_view.rs @@ -1,8 +1,14 @@ use alacritty_terminal::term::TermMode; +use context_menu::{ContextMenu, ContextMenuItem}; use gpui::{ - actions, keymap::Keystroke, AppContext, Element, ElementBox, ModelHandle, MutableAppContext, - View, ViewContext, + actions, + elements::{ChildView, ParentElement, Stack}, + geometry::vector::Vector2F, + impl_internal_actions, + keymap::Keystroke, + AppContext, Element, ElementBox, ModelHandle, MutableAppContext, View, ViewContext, ViewHandle, }; +use workspace::pane; use crate::{connected_el::TerminalEl, Event, Terminal}; @@ -10,10 +16,16 @@ use crate::{connected_el::TerminalEl, Event, Terminal}; #[derive(Clone, Debug, PartialEq)] pub struct ScrollTerminal(pub i32); +#[derive(Clone, PartialEq)] +pub struct DeployContextMenu { + pub position: Vector2F, +} + actions!( terminal, [Up, Down, CtrlC, Escape, Enter, Clear, Copy, Paste,] ); +impl_internal_actions!(project_panel, [DeployContextMenu]); pub fn init(cx: &mut MutableAppContext) { //Global binding overrrides @@ -23,6 +35,7 @@ pub fn init(cx: &mut MutableAppContext) { cx.add_action(ConnectedView::escape); cx.add_action(ConnectedView::enter); //Useful terminal views + cx.add_action(ConnectedView::deploy_context_menu); cx.add_action(ConnectedView::copy); cx.add_action(ConnectedView::paste); cx.add_action(ConnectedView::clear); @@ -36,6 +49,7 @@ pub struct ConnectedView { has_bell: bool, // Only for styling purposes. Doesn't effect behavior modal: bool, + context_menu: ViewHandle, } impl ConnectedView { @@ -67,6 +81,7 @@ impl ConnectedView { has_new_content: true, has_bell: false, modal, + context_menu: cx.add_view(|cx| ContextMenu::new(cx)), } } @@ -87,6 +102,18 @@ impl ConnectedView { cx.emit(Event::Wakeup); } + pub fn deploy_context_menu(&mut self, action: &DeployContextMenu, cx: &mut ViewContext) { + let menu_entries = vec![ + ContextMenuItem::item("Clear Buffer", Clear), + ContextMenuItem::item("Close Terminal", pane::CloseActiveItem), + ]; + + self.context_menu + .update(cx, |menu, cx| menu.show(action.position, menu_entries, cx)); + + cx.notify(); + } + fn clear(&mut self, _: &Clear, cx: &mut ViewContext) { self.terminal.update(cx, |term, _| term.clear()); } @@ -151,8 +178,14 @@ impl View for ConnectedView { fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> ElementBox { let terminal_handle = self.terminal.clone().downgrade(); - TerminalEl::new(cx.handle(), terminal_handle, self.modal) - .contained() + + Stack::new() + .with_child( + TerminalEl::new(cx.handle(), terminal_handle, self.modal) + .contained() + .boxed(), + ) + .with_child(ChildView::new(&self.context_menu).boxed()) .boxed() } diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 4c27795d9775a2d9e0394299df06840e4780703d..4e5ca37a9debf9dae031ae5d23b8eddb5b5dfc50 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -27,7 +27,6 @@ use futures::{ use modal::deploy_modal; use settings::{Settings, Shell}; use std::{collections::HashMap, fmt::Display, path::PathBuf, sync::Arc, time::Duration}; -use terminal_view::TerminalView; use thiserror::Error; use gpui::{ @@ -43,9 +42,9 @@ use crate::mappings::{ ///Initialize and register all of our action handlers pub fn init(cx: &mut MutableAppContext) { - cx.add_action(TerminalView::deploy); cx.add_action(deploy_modal); + terminal_view::init(cx); connected_view::init(cx); } diff --git a/crates/terminal/src/terminal_view.rs b/crates/terminal/src/terminal_view.rs index 309b3be11ad9b0eaf748b8b7058776c7648e6962..ba6f49af02c0de6cec38df971defb9b2512a81ea 100644 --- a/crates/terminal/src/terminal_view.rs +++ b/crates/terminal/src/terminal_view.rs @@ -1,11 +1,11 @@ use crate::connected_view::ConnectedView; use crate::{Event, Terminal, TerminalBuilder, TerminalError}; + use dirs::home_dir; use gpui::{ - actions, elements::*, AnyViewHandle, AppContext, Entity, ModelHandle, View, ViewContext, - ViewHandle, + actions, elements::*, AnyViewHandle, AppContext, Entity, ModelHandle, MutableAppContext, View, + ViewContext, ViewHandle, }; -use theme::ContextMenu; use workspace::{Item, Workspace}; use crate::TerminalSize; @@ -18,6 +18,10 @@ use crate::connected_el::TerminalEl; actions!(terminal, [DeployModal]); +pub fn init(cx: &mut MutableAppContext) { + cx.add_action(TerminalView::deploy); +} + //Make terminal view an enum, that can give you views for the error and non-error states //Take away all the result unwrapping in the current TerminalView by making it 'infallible' //Bubble up to deploy(_modal)() calls @@ -40,7 +44,6 @@ pub struct TerminalView { modal: bool, pub content: TerminalContent, associated_directory: Option, - context_menu: ViewHandle, } pub struct ErrorView { @@ -113,7 +116,6 @@ impl TerminalView { modal, content, associated_directory: working_directory, - context_menu: cx.add_view(|cx| ContextMenu::new(cx)), } } @@ -141,7 +143,6 @@ impl View for TerminalView { TerminalContent::Connected(connected) => ChildView::new(connected), TerminalContent::Error(error) => ChildView::new(error), }; - if self.modal { let settings = cx.global::(); let container_style = settings.theme.terminal.modal_container; From c21314bfbd1a79a556d387cf573dbd19b74dafc8 Mon Sep 17 00:00:00 2001 From: ForLoveOfCats Date: Wed, 3 Aug 2022 22:32:18 -0400 Subject: [PATCH 6/9] Add ability to provide custom LSP server initialization options --- assets/settings/default.json | 3 ++- crates/project/src/project.rs | 34 ++++++++++++++++++++++++++++++++- crates/settings/src/settings.rs | 12 ++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 5c05e8eaba1b72f29d76bba9863cb90dfe01badc..505e8dd4ebb6111d7799142da7358d8664ee75ef 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -144,5 +144,6 @@ "TSX": { "tab_size": 2 } - } + }, + "lsp": {} } diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 8adc10ba5564ac57d29cb5107b9fd73d3817d53d..bc25687df6666e8b35a0c8d12f006a47d57ff4d4 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -2071,6 +2071,24 @@ impl Project { None } + fn merge_json_value_into(source: serde_json::Value, target: &mut serde_json::Value) { + use serde_json::Value; + + match (source, target) { + (Value::Object(source), Value::Object(target)) => { + for (key, value) in source { + if let Some(target) = target.get_mut(&key) { + Self::merge_json_value_into(value, target); + } else { + target.insert(key.clone(), value); + } + } + } + + (source, target) => *target = source, + } + } + fn start_language_server( &mut self, worktree_id: WorktreeId, @@ -2092,6 +2110,20 @@ impl Project { }; let key = (worktree_id, adapter.name.clone()); + let mut initialization_options = adapter.initialization_options.clone(); + + let lsp = &cx.global::().lsp.get(&adapter.name.0); + let override_options = lsp.map(|s| s.initialization_options.clone()).flatten(); + match (&mut initialization_options, override_options) { + (Some(initialization_options), Some(override_options)) => { + Self::merge_json_value_into(override_options, initialization_options); + } + + (None, override_options) => initialization_options = override_options, + + _ => {} + } + self.language_server_ids .entry(key.clone()) .or_insert_with(|| { @@ -2108,7 +2140,7 @@ impl Project { LanguageServerState::Starting(cx.spawn_weak(|this, mut cx| async move { let language_server = language_server?.await.log_err()?; let language_server = language_server - .initialize(adapter.initialization_options.clone()) + .initialize(initialization_options) .await .log_err()?; let this = this.upgrade(&cx)?; diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index c5188884562899afe3a68a4c6febc3c6a562e77e..fc5384cb3e7ac65ed502da9a6050f08ec83dda2c 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -34,6 +34,7 @@ pub struct Settings { pub terminal_overrides: TerminalSettings, pub language_defaults: HashMap, EditorSettings>, pub language_overrides: HashMap, EditorSettings>, + pub lsp: HashMap, LspSettings>, pub theme: Arc, } @@ -131,9 +132,17 @@ pub struct SettingsFileContent { #[serde(alias = "language_overrides")] pub languages: HashMap, EditorSettings>, #[serde(default)] + pub lsp: HashMap, LspSettings>, + #[serde(default)] pub theme: Option, } +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct LspSettings { + pub initialization_options: Option, +} + impl Settings { pub fn defaults( assets: impl AssetSource, @@ -174,6 +183,7 @@ impl Settings { terminal_overrides: Default::default(), language_defaults: defaults.languages, language_overrides: Default::default(), + lsp: defaults.lsp.clone(), theme: themes.get(&defaults.theme.unwrap()).unwrap(), } } @@ -218,6 +228,7 @@ impl Settings { self.terminal_defaults.font_size = data.terminal.font_size; self.terminal_overrides = data.terminal; self.language_overrides = data.languages; + self.lsp = data.lsp; } pub fn with_language_defaults( @@ -288,6 +299,7 @@ impl Settings { terminal_overrides: Default::default(), language_defaults: Default::default(), language_overrides: Default::default(), + lsp: Default::default(), projects_online_by_default: true, theme: gpui::fonts::with_font_cache(cx.font_cache().clone(), || Default::default()), } From 4549395d027cb430ae9dbf08eb668439982efc2a Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 4 Aug 2022 11:58:55 -0700 Subject: [PATCH 7/9] update icon --- crates/workspace/src/pane.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index caccda8ecf58a10d10284d6abd09434b19115cec..a05b9ac1a822b34e36701b226085c95d287ce98c 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1112,7 +1112,7 @@ impl View for Pane { &cx.global::().theme.workspace.tab_bar; let style = theme.pane_button.style_for(mouse_state, false); - Svg::new("icons/bolt_12.svg") + Svg::new("icons/plus_12.svg") .with_color(style.color) .constrained() .with_width(style.icon_width) From 4817b11cad3985234ed6a829680dc9c736d4e67b Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 4 Aug 2022 12:44:31 -0700 Subject: [PATCH 8/9] 0.50.0 --- Cargo.lock | 2 +- crates/zed/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 60518a2fafe06928fbbb28074a5322940632c218..4256d24c9ddf40bd951129caaabf951f98784ef9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6996,7 +6996,7 @@ dependencies = [ [[package]] name = "zed" -version = "0.49.1" +version = "0.50.0" dependencies = [ "activity_indicator", "anyhow", diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index be20be2fd7fb0e9df29956cf6344b10c7325d1be..0eb2aff7c47c99d2989bd664417c226510c681a0 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -3,7 +3,7 @@ authors = ["Nathan Sobo "] description = "The fast, collaborative code editor." edition = "2021" name = "zed" -version = "0.49.1" +version = "0.50.0" [lib] name = "zed" From 75278505469ef60edef10fe303303df0e64a55e7 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 4 Aug 2022 13:36:33 -0700 Subject: [PATCH 9/9] Handle RPC requests for type definitions on server and host --- crates/collab/src/integration_tests.rs | 36 +++++++++++++++++++++++--- crates/collab/src/rpc.rs | 1 + crates/project/src/project.rs | 1 + 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/crates/collab/src/integration_tests.rs b/crates/collab/src/integration_tests.rs index 1f3ccef0be0d6ecd3946e2971850d3be0b7b3412..2a68c2056e523c7965d7cdeb090a3cdf55337f61 100644 --- a/crates/collab/src/integration_tests.rs +++ b/crates/collab/src/integration_tests.rs @@ -2057,7 +2057,8 @@ async fn test_definition(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) { "a.rs": "const ONE: usize = b::TWO + b::THREE;", }, "dir-2": { - "b.rs": "const TWO: usize = 2;\nconst THREE: usize = 3;", + "b.rs": "const TWO: c::T2 = 2;\nconst THREE: usize = 3;", + "c.rs": "type T2 = usize;", } }), ) @@ -2093,7 +2094,7 @@ async fn test_definition(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) { let target_buffer = definitions_1[0].target.buffer.read(cx); assert_eq!( target_buffer.text(), - "const TWO: usize = 2;\nconst THREE: usize = 3;" + "const TWO: c::T2 = 2;\nconst THREE: usize = 3;" ); assert_eq!( definitions_1[0].target.range.to_point(target_buffer), @@ -2122,7 +2123,7 @@ async fn test_definition(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) { let target_buffer = definitions_2[0].target.buffer.read(cx); assert_eq!( target_buffer.text(), - "const TWO: usize = 2;\nconst THREE: usize = 3;" + "const TWO: c::T2 = 2;\nconst THREE: usize = 3;" ); assert_eq!( definitions_2[0].target.range.to_point(target_buffer), @@ -2133,6 +2134,35 @@ async fn test_definition(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) { definitions_1[0].target.buffer, definitions_2[0].target.buffer ); + + fake_language_server.handle_request::( + |req, _| async move { + assert_eq!( + req.text_document_position_params.position, + lsp::Position::new(0, 7) + ); + Ok(Some(lsp::GotoDefinitionResponse::Scalar( + lsp::Location::new( + lsp::Url::from_file_path("/root/dir-2/c.rs").unwrap(), + lsp::Range::new(lsp::Position::new(0, 5), lsp::Position::new(0, 7)), + ), + ))) + }, + ); + + let type_definitions = project_b + .update(cx_b, |p, cx| p.type_definition(&buffer_b, 7, cx)) + .await + .unwrap(); + cx_b.read(|cx| { + assert_eq!(type_definitions.len(), 1); + let target_buffer = type_definitions[0].target.buffer.read(cx); + assert_eq!(target_buffer.text(), "type T2 = usize;"); + assert_eq!( + type_definitions[0].target.range.to_point(target_buffer), + Point::new(0, 5)..Point::new(0, 7) + ); + }); } #[gpui::test(iterations = 10)] diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs index 4944761d58bd6bb1fb330f6fc7a5ecbf3cf62b7b..a4a48af5be6b0b5bab7cf9f93b3f826517634588 100644 --- a/crates/collab/src/rpc.rs +++ b/crates/collab/src/rpc.rs @@ -165,6 +165,7 @@ impl Server { .add_message_handler(Server::update_diagnostic_summary) .add_request_handler(Server::forward_project_request::) .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) .add_request_handler(Server::forward_project_request::) .add_request_handler(Server::forward_project_request::) .add_request_handler(Server::forward_project_request::) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index bc25687df6666e8b35a0c8d12f006a47d57ff4d4..6488afd303d4194f02e8d5e2d2d2c35bcc424645 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -389,6 +389,7 @@ impl Project { client.add_model_request_handler(Self::handle_get_completions); client.add_model_request_handler(Self::handle_lsp_command::); client.add_model_request_handler(Self::handle_lsp_command::); + client.add_model_request_handler(Self::handle_lsp_command::); client.add_model_request_handler(Self::handle_lsp_command::); client.add_model_request_handler(Self::handle_lsp_command::); client.add_model_request_handler(Self::handle_lsp_command::);