Introduce code generation (#2901)

![CleanShot 2023-08-28 at 12 24
36@2x](https://github.com/zed-industries/zed/assets/482957/f97cb399-1ac2-4fa9-94a7-137d1eec711c)


Release Notes:

- Added a new "Inline Assist" feature that lets you transform a
selection or generate new code at the cursor location by hitting
`ctrl-enter`.
This commit is contained in:
Antonio Scandurra 2023-08-30 14:58:22 +02:00 committed by GitHub
commit ea17d1638e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 2043 additions and 274 deletions

View file

@ -1,25 +1,29 @@
use ai::{assistant::InlineAssist, AssistantPanel};
use editor::Editor;
use gpui::{
elements::{Empty, Flex, MouseEventHandler, ParentElement, Svg},
platform::{CursorStyle, MouseButton},
Action, AnyElement, Element, Entity, EventContext, Subscription, View, ViewContext, ViewHandle,
WeakViewHandle,
};
use search::{buffer_search, BufferSearchBar};
use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView};
use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView, Workspace};
pub struct QuickActionBar {
buffer_search_bar: ViewHandle<BufferSearchBar>,
active_item: Option<Box<dyn ItemHandle>>,
_inlay_hints_enabled_subscription: Option<Subscription>,
workspace: WeakViewHandle<Workspace>,
}
impl QuickActionBar {
pub fn new(buffer_search_bar: ViewHandle<BufferSearchBar>) -> Self {
pub fn new(buffer_search_bar: ViewHandle<BufferSearchBar>, workspace: &Workspace) -> Self {
Self {
buffer_search_bar,
active_item: None,
_inlay_hints_enabled_subscription: None,
workspace: workspace.weak_handle(),
}
}
@ -88,6 +92,21 @@ impl View for QuickActionBar {
));
}
bar.add_child(render_quick_action_bar_button(
2,
"icons/radix/magic-wand.svg",
false,
("Inline Assist".into(), Some(Box::new(InlineAssist))),
cx,
move |this, cx| {
if let Some(workspace) = this.workspace.upgrade(cx) {
workspace.update(cx, |workspace, cx| {
AssistantPanel::inline_assist(workspace, &Default::default(), cx);
});
}
},
));
bar.into_any()
}
}