From 3992e95109bfaf4736e5cb80f465707d501effcd Mon Sep 17 00:00:00 2001 From: Petros Amoiridis Date: Fri, 21 Apr 2023 18:29:35 +0300 Subject: [PATCH 1/6] Add newline shortcuts for popular editors --- assets/keymaps/atom.json | 4 +++- assets/keymaps/jetbrains.json | 1 + assets/keymaps/sublime_text.json | 4 +++- assets/keymaps/textmate.json | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/keymaps/atom.json b/assets/keymaps/atom.json index f73b5e0e22..99aae2638f 100644 --- a/assets/keymaps/atom.json +++ b/assets/keymaps/atom.json @@ -18,7 +18,9 @@ ], "ctrl-shift-down": "editor::AddSelectionBelow", "ctrl-shift-up": "editor::AddSelectionAbove", - "cmd-shift-backspace": "editor::DeleteToBeginningOfLine" + "cmd-shift-backspace": "editor::DeleteToBeginningOfLine", + "cmd-shift-enter": "editor::NewlineAbove", + "cmd-enter": "editor::NewlineBelow" } }, { diff --git a/assets/keymaps/jetbrains.json b/assets/keymaps/jetbrains.json index 921efdc929..59e069e7f7 100644 --- a/assets/keymaps/jetbrains.json +++ b/assets/keymaps/jetbrains.json @@ -14,6 +14,7 @@ "cmd-pagedown": "editor::MovePageDown", "cmd-pageup": "editor::MovePageUp", "ctrl-alt-shift-b": "editor::SelectToPreviousWordStart", + "cmd-alt-enter": "editor::NewlineAbove", "shift-enter": "editor::NewlineBelow", "cmd--": "editor::Fold", "cmd-=": "editor::UnfoldLines", diff --git a/assets/keymaps/sublime_text.json b/assets/keymaps/sublime_text.json index 89cfa4b262..373f3f4d3a 100644 --- a/assets/keymaps/sublime_text.json +++ b/assets/keymaps/sublime_text.json @@ -24,7 +24,9 @@ "ctrl-.": "editor::GoToHunk", "ctrl-,": "editor::GoToPrevHunk", "ctrl-backspace": "editor::DeleteToPreviousWordStart", - "ctrl-delete": "editor::DeleteToNextWordEnd" + "ctrl-delete": "editor::DeleteToNextWordEnd", + "cmd-shift-enter": "editor::NewlineAbove", + "cmd-enter": "editor::NewlineBelow" } }, { diff --git a/assets/keymaps/textmate.json b/assets/keymaps/textmate.json index 88648b89e3..1abcaa376c 100644 --- a/assets/keymaps/textmate.json +++ b/assets/keymaps/textmate.json @@ -12,6 +12,7 @@ "ctrl-shift-d": "editor::DuplicateLine", "cmd-b": "editor::GoToDefinition", "cmd-j": "editor::ScrollCursorCenter", + "cmd-alt-enter": "editor::NewlineAbove", "cmd-enter": "editor::NewlineBelow", "cmd-shift-l": "editor::SelectLine", "cmd-shift-t": "outline::Toggle", From 4ac894ffbe6016afb593de8b106b1d8ddbdb0fe2 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 21 Apr 2023 18:06:53 +0200 Subject: [PATCH 2/6] Remove unnecessary lifetime parameter from WindowContext Co-Authored-By: Nathan Sobo --- crates/editor/src/display_map/block_map.rs | 10 ++-- crates/gpui/src/app.rs | 65 ++++++++++------------ crates/gpui/src/app/window.rs | 26 ++++----- 3 files changed, 48 insertions(+), 53 deletions(-) diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rs index f5d2c83a8f..e850e43925 100644 --- a/crates/editor/src/display_map/block_map.rs +++ b/crates/editor/src/display_map/block_map.rs @@ -80,8 +80,8 @@ pub enum BlockStyle { Sticky, } -pub struct BlockContext<'a, 'b, 'c, 'd> { - pub view_context: &'d mut ViewContext<'a, 'b, 'c, Editor>, +pub struct BlockContext<'a, 'b, 'c> { + pub view_context: &'c mut ViewContext<'a, 'b, Editor>, pub anchor_x: f32, pub scroll_x: f32, pub gutter_width: f32, @@ -932,15 +932,15 @@ impl BlockDisposition { } } -impl<'a, 'b, 'c, 'd> Deref for BlockContext<'a, 'b, 'c, 'd> { - type Target = ViewContext<'a, 'b, 'c, Editor>; +impl<'a, 'b, 'c> Deref for BlockContext<'a, 'b, 'c> { + type Target = ViewContext<'a, 'b, Editor>; fn deref(&self) -> &Self::Target { self.view_context } } -impl DerefMut for BlockContext<'_, '_, '_, '_> { +impl DerefMut for BlockContext<'_, '_, '_> { fn deref_mut(&mut self) -> &mut Self::Target { self.view_context } diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 762837c478..c53a2f2c24 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -69,7 +69,7 @@ pub trait Entity: 'static { pub trait View: Entity + Sized { fn ui_name() -> &'static str; - fn render(&mut self, cx: &mut ViewContext<'_, '_, '_, Self>) -> Element; + fn render(&mut self, cx: &mut ViewContext<'_, '_, Self>) -> Element; fn focus_in(&mut self, _: AnyViewHandle, _: &mut ViewContext) {} fn focus_out(&mut self, _: AnyViewHandle, _: &mut ViewContext) {} fn key_down(&mut self, _: &KeyDownEvent, _: &mut ViewContext) -> bool { @@ -2518,12 +2518,7 @@ pub trait AnyView { ) -> Option>>>; fn ui_name(&self) -> &'static str; fn render(&mut self, cx: &mut WindowContext, view_id: usize) -> Box; - fn focus_in<'a, 'b>( - &mut self, - focused_id: usize, - cx: &mut WindowContext<'a, 'b>, - view_id: usize, - ); + fn focus_in<'a, 'b>(&mut self, focused_id: usize, cx: &mut WindowContext<'a>, view_id: usize); fn focus_out(&mut self, focused_id: usize, cx: &mut WindowContext, view_id: usize); fn key_down(&mut self, event: &KeyDownEvent, cx: &mut WindowContext, view_id: usize) -> bool; fn key_up(&mut self, event: &KeyUpEvent, cx: &mut WindowContext, view_id: usize) -> bool; @@ -2919,28 +2914,28 @@ impl DerefMut for ModelContext<'_, M> { } } -pub struct ViewContext<'a, 'b, 'c, T: ?Sized> { - window_context: Reference<'c, WindowContext<'a, 'b>>, +pub struct ViewContext<'a, 'b, T: ?Sized> { + window_context: Reference<'b, WindowContext<'a>>, view_id: usize, view_type: PhantomData, } -impl<'a, 'b, 'c, T: View> Deref for ViewContext<'a, 'b, 'c, T> { - type Target = WindowContext<'a, 'b>; +impl<'a, 'b, T: View> Deref for ViewContext<'a, 'b, T> { + type Target = WindowContext<'a>; fn deref(&self) -> &Self::Target { &self.window_context } } -impl DerefMut for ViewContext<'_, '_, '_, T> { +impl DerefMut for ViewContext<'_, '_, T> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.window_context } } -impl<'a, 'b, 'c, V: View> ViewContext<'a, 'b, 'c, V> { - pub(crate) fn mutable(window_context: &'c mut WindowContext<'a, 'b>, view_id: usize) -> Self { +impl<'a, 'b, V: View> ViewContext<'a, 'b, V> { + pub(crate) fn mutable(window_context: &'b mut WindowContext<'a>, view_id: usize) -> Self { Self { window_context: Reference::Mutable(window_context), view_id, @@ -2948,7 +2943,7 @@ impl<'a, 'b, 'c, V: View> ViewContext<'a, 'b, 'c, V> { } } - pub(crate) fn immutable(window_context: &'c WindowContext<'a, 'b>, view_id: usize) -> Self { + pub(crate) fn immutable(window_context: &'b WindowContext<'a>, view_id: usize) -> Self { Self { window_context: Reference::Immutable(window_context), view_id, @@ -2956,7 +2951,7 @@ impl<'a, 'b, 'c, V: View> ViewContext<'a, 'b, 'c, V> { } } - pub fn window_context(&mut self) -> &mut WindowContext<'a, 'b> { + pub fn window_context(&mut self) -> &mut WindowContext<'a> { &mut self.window_context } @@ -3450,7 +3445,7 @@ impl<'a, 'b, 'c, V: View> ViewContext<'a, 'b, 'c, V> { } } -impl UpgradeModelHandle for ViewContext<'_, '_, '_, V> { +impl UpgradeModelHandle for ViewContext<'_, '_, V> { fn upgrade_model_handle( &self, handle: &WeakModelHandle, @@ -3467,7 +3462,7 @@ impl UpgradeModelHandle for ViewContext<'_, '_, '_, V> { } } -impl UpgradeViewHandle for ViewContext<'_, '_, '_, V> { +impl UpgradeViewHandle for ViewContext<'_, '_, V> { fn upgrade_view_handle(&self, handle: &WeakViewHandle) -> Option> { self.window_context.upgrade_view_handle(handle) } @@ -3477,13 +3472,13 @@ impl UpgradeViewHandle for ViewContext<'_, '_, '_, V> { } } -impl ReadModel for ViewContext<'_, '_, '_, V> { +impl ReadModel for ViewContext<'_, '_, V> { fn read_model(&self, handle: &ModelHandle) -> &T { self.window_context.read_model(handle) } } -impl UpdateModel for ViewContext<'_, '_, '_, V> { +impl UpdateModel for ViewContext<'_, '_, V> { fn update_model( &mut self, handle: &ModelHandle, @@ -3493,13 +3488,13 @@ impl UpdateModel for ViewContext<'_, '_, '_, V> { } } -impl ReadView for ViewContext<'_, '_, '_, V> { +impl ReadView for ViewContext<'_, '_, V> { fn read_view(&self, handle: &ViewHandle) -> &T { self.window_context.read_view(handle) } } -impl UpdateView for ViewContext<'_, '_, '_, V> { +impl UpdateView for ViewContext<'_, '_, V> { type Output = S; fn update_view( @@ -3514,13 +3509,13 @@ impl UpdateView for ViewContext<'_, '_, '_, V> { } } -pub struct EventContext<'a, 'b, 'c, 'd, V: View> { - view_context: &'d mut ViewContext<'a, 'b, 'c, V>, +pub struct EventContext<'a, 'b, 'c, V: View> { + view_context: &'c mut ViewContext<'a, 'b, V>, pub(crate) handled: bool, } -impl<'a, 'b, 'c, 'd, V: View> EventContext<'a, 'b, 'c, 'd, V> { - pub(crate) fn new(view_context: &'d mut ViewContext<'a, 'b, 'c, V>) -> Self { +impl<'a, 'b, 'c, V: View> EventContext<'a, 'b, 'c, V> { + pub(crate) fn new(view_context: &'c mut ViewContext<'a, 'b, V>) -> Self { EventContext { view_context, handled: true, @@ -3532,21 +3527,21 @@ impl<'a, 'b, 'c, 'd, V: View> EventContext<'a, 'b, 'c, 'd, V> { } } -impl<'a, 'b, 'c, 'd, V: View> Deref for EventContext<'a, 'b, 'c, 'd, V> { - type Target = ViewContext<'a, 'b, 'c, V>; +impl<'a, 'b, 'c, V: View> Deref for EventContext<'a, 'b, 'c, V> { + type Target = ViewContext<'a, 'b, V>; fn deref(&self) -> &Self::Target { &self.view_context } } -impl DerefMut for EventContext<'_, '_, '_, '_, V> { +impl DerefMut for EventContext<'_, '_, '_, V> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.view_context } } -impl UpdateModel for EventContext<'_, '_, '_, '_, V> { +impl UpdateModel for EventContext<'_, '_, '_, V> { fn update_model( &mut self, handle: &ModelHandle, @@ -3556,13 +3551,13 @@ impl UpdateModel for EventContext<'_, '_, '_, '_, V> { } } -impl ReadView for EventContext<'_, '_, '_, '_, V> { +impl ReadView for EventContext<'_, '_, '_, V> { fn read_view(&self, handle: &crate::ViewHandle) -> &W { self.view_context.read_view(handle) } } -impl UpdateView for EventContext<'_, '_, '_, '_, V> { +impl UpdateView for EventContext<'_, '_, '_, V> { type Output = S; fn update_view( @@ -3577,7 +3572,7 @@ impl UpdateView for EventContext<'_, '_, '_, '_, V> { } } -impl UpgradeModelHandle for EventContext<'_, '_, '_, '_, V> { +impl UpgradeModelHandle for EventContext<'_, '_, '_, V> { fn upgrade_model_handle( &self, handle: &WeakModelHandle, @@ -3594,7 +3589,7 @@ impl UpgradeModelHandle for EventContext<'_, '_, '_, '_, V> { } } -impl UpgradeViewHandle for EventContext<'_, '_, '_, '_, V> { +impl UpgradeViewHandle for EventContext<'_, '_, '_, V> { fn upgrade_view_handle(&self, handle: &WeakViewHandle) -> Option> { self.view_context.upgrade_view_handle(handle) } @@ -4106,7 +4101,7 @@ impl AnyViewHandle { self.view_type } - pub fn debug_json<'a, 'b>(&self, cx: &'b WindowContext<'a, 'b>) -> serde_json::Value { + pub fn debug_json<'a, 'b>(&self, cx: &'b WindowContext<'a>) -> serde_json::Value { cx.views .get(&(self.window_id, self.view_id)) .map_or_else(|| serde_json::Value::Null, |view| view.debug_json(cx)) diff --git a/crates/gpui/src/app/window.rs b/crates/gpui/src/app/window.rs index 306e83652a..598bba10de 100644 --- a/crates/gpui/src/app/window.rs +++ b/crates/gpui/src/app/window.rs @@ -111,15 +111,15 @@ impl Window { } } -pub struct WindowContext<'a: 'b, 'b> { +pub struct WindowContext<'a> { pub(crate) app_context: Reference<'a, AppContext>, - pub(crate) window: Reference<'b, Window>, + pub(crate) window: Reference<'a, Window>, pub(crate) window_id: usize, pub(crate) refreshing: bool, pub(crate) removed: bool, } -impl Deref for WindowContext<'_, '_> { +impl Deref for WindowContext<'_> { type Target = AppContext; fn deref(&self) -> &Self::Target { @@ -127,19 +127,19 @@ impl Deref for WindowContext<'_, '_> { } } -impl DerefMut for WindowContext<'_, '_> { +impl DerefMut for WindowContext<'_> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.app_context } } -impl ReadModel for WindowContext<'_, '_> { +impl ReadModel for WindowContext<'_> { fn read_model(&self, handle: &ModelHandle) -> &T { self.app_context.read_model(handle) } } -impl UpdateModel for WindowContext<'_, '_> { +impl UpdateModel for WindowContext<'_> { fn update_model( &mut self, handle: &ModelHandle, @@ -149,13 +149,13 @@ impl UpdateModel for WindowContext<'_, '_> { } } -impl ReadView for WindowContext<'_, '_> { +impl ReadView for WindowContext<'_> { fn read_view(&self, handle: &crate::ViewHandle) -> &W { self.app_context.read_view(handle) } } -impl UpdateView for WindowContext<'_, '_> { +impl UpdateView for WindowContext<'_> { type Output = S; fn update_view( @@ -179,7 +179,7 @@ impl UpdateView for WindowContext<'_, '_> { } } -impl UpgradeModelHandle for WindowContext<'_, '_> { +impl UpgradeModelHandle for WindowContext<'_> { fn upgrade_model_handle( &self, handle: &WeakModelHandle, @@ -196,7 +196,7 @@ impl UpgradeModelHandle for WindowContext<'_, '_> { } } -impl UpgradeViewHandle for WindowContext<'_, '_> { +impl UpgradeViewHandle for WindowContext<'_> { fn upgrade_view_handle(&self, handle: &WeakViewHandle) -> Option> { self.app_context.upgrade_view_handle(handle) } @@ -206,10 +206,10 @@ impl UpgradeViewHandle for WindowContext<'_, '_> { } } -impl<'a: 'b, 'b> WindowContext<'a, 'b> { +impl<'a> WindowContext<'a> { pub fn mutable( app_context: &'a mut AppContext, - window: &'b mut Window, + window: &'a mut Window, window_id: usize, ) -> Self { Self { @@ -221,7 +221,7 @@ impl<'a: 'b, 'b> WindowContext<'a, 'b> { } } - pub fn immutable(app_context: &'a AppContext, window: &'b Window, window_id: usize) -> Self { + pub fn immutable(app_context: &'a AppContext, window: &'a Window, window_id: usize) -> Self { Self { app_context: Reference::Immutable(app_context), window: Reference::Immutable(window), From 6ee0d104d68ebe33757427b62d03f09cc0e90a3e Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 21 Apr 2023 10:08:52 -0700 Subject: [PATCH 3/6] Fix panic in remove active item --- crates/workspace/src/pane.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index c394ae4631..089618ea20 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -785,6 +785,10 @@ impl Pane { ) -> Option>> { let pane_handle = workspace.active_pane().clone(); let pane = pane_handle.read(cx); + + if pane.items.is_empty() { + return Some(Task::Ready(Some(Ok(())))); + } let active_item_id = pane.items[pane.active_item_index].id(); let task = Self::close_item_by_id(workspace, pane_handle, active_item_id, cx); @@ -2098,6 +2102,21 @@ mod tests { use gpui::{executor::Deterministic, TestAppContext}; use project::FakeFs; + #[gpui::test] + async fn test_remove_active_empty(cx: &mut TestAppContext) { + Settings::test_async(cx); + let fs = FakeFs::new(cx.background()); + + let project = Project::test(fs, None, cx).await; + let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx)); + + let task = workspace.update(cx, |workspace, cx| { + Pane::close_active_item(workspace, &CloseActiveItem, cx).unwrap() + }); + + assert!(task.await.is_ok()) + } + #[gpui::test] async fn test_add_item_with_new_item(cx: &mut TestAppContext) { cx.foreground().forbid_parking(); From 39512655aa2f236237e40ec3f948b55fa435c5fc Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 21 Apr 2023 10:38:36 -0700 Subject: [PATCH 4/6] Remove unused cyclic dependency from copilot crate Move notification handling earlier so that there are less copilot messages in the log --- Cargo.lock | 1 - crates/copilot/Cargo.toml | 1 - crates/copilot/src/copilot.rs | 15 ++++++++------- crates/copilot/src/request.rs | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b3e5c38a46..4c1e7de435 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1358,7 +1358,6 @@ dependencies = [ "smol", "theme", "util", - "workspace", ] [[package]] diff --git a/crates/copilot/Cargo.toml b/crates/copilot/Cargo.toml index bfafdbc0ca..f4d75cc582 100644 --- a/crates/copilot/Cargo.toml +++ b/crates/copilot/Cargo.toml @@ -47,4 +47,3 @@ lsp = { path = "../lsp", features = ["test-support"] } rpc = { path = "../rpc", features = ["test-support"] } settings = { path = "../settings", features = ["test-support"] } util = { path = "../util", features = ["test-support"] } -workspace = { path = "../workspace", features = ["test-support"] } diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index 182db084a1..b2da730c3f 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -378,13 +378,6 @@ impl Copilot { cx.clone(), )?; - let server = server.initialize(Default::default()).await?; - let status = server - .request::(request::CheckStatusParams { - local_checks_only: false, - }) - .await?; - server .on_notification::(|params, _cx| { match params.level { @@ -405,6 +398,14 @@ impl Copilot { ) .detach(); + let server = server.initialize(Default::default()).await?; + + let status = server + .request::(request::CheckStatusParams { + local_checks_only: false, + }) + .await?; + server .request::(request::SetEditorInfoParams { editor_info: request::EditorInfo { diff --git a/crates/copilot/src/request.rs b/crates/copilot/src/request.rs index 43b5109d02..0f9a478b91 100644 --- a/crates/copilot/src/request.rs +++ b/crates/copilot/src/request.rs @@ -143,8 +143,8 @@ pub enum LogMessage {} #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct LogMessageParams { - pub message: String, pub level: u8, + pub message: String, pub metadata_str: String, pub extra: Vec, } From aa2af53f5609c0d80a4bf0edeb930fc5572aa62f Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 21 Apr 2023 10:44:27 -0700 Subject: [PATCH 5/6] Align return of close_active_item to match original format --- 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 089618ea20..a120523131 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -787,7 +787,7 @@ impl Pane { let pane = pane_handle.read(cx); if pane.items.is_empty() { - return Some(Task::Ready(Some(Ok(())))); + return None; } let active_item_id = pane.items[pane.active_item_index].id(); From b8fd6435d76acfc7cb447f50e3af05f34bd87922 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 21 Apr 2023 10:48:34 -0700 Subject: [PATCH 6/6] Fix test covering this case --- crates/workspace/src/pane.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index a120523131..38e9bb5b54 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -2110,11 +2110,9 @@ mod tests { let project = Project::test(fs, None, cx).await; let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx)); - let task = workspace.update(cx, |workspace, cx| { - Pane::close_active_item(workspace, &CloseActiveItem, cx).unwrap() + workspace.update(cx, |workspace, cx| { + assert!(Pane::close_active_item(workspace, &CloseActiveItem, cx).is_none()) }); - - assert!(task.await.is_ok()) } #[gpui::test]