Show icon to toggle inline assist

This commit is contained in:
Antonio Scandurra 2023-08-28 12:13:44 +02:00
parent d804afcfa9
commit 1fb7ce0f4a
5 changed files with 31 additions and 5 deletions

1
Cargo.lock generated
View file

@ -5647,6 +5647,7 @@ dependencies = [
name = "quick_action_bar" name = "quick_action_bar"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ai",
"editor", "editor",
"gpui", "gpui",
"search", "search",

View file

@ -215,7 +215,11 @@ impl AssistantPanel {
}) })
} }
fn inline_assist(workspace: &mut Workspace, _: &InlineAssist, cx: &mut ViewContext<Workspace>) { pub fn inline_assist(
workspace: &mut Workspace,
_: &InlineAssist,
cx: &mut ViewContext<Workspace>,
) {
let this = if let Some(this) = workspace.panel::<AssistantPanel>(cx) { let this = if let Some(this) = workspace.panel::<AssistantPanel>(cx) {
if this if this
.update(cx, |assistant, cx| assistant.load_api_key(cx)) .update(cx, |assistant, cx| assistant.load_api_key(cx))

View file

@ -9,6 +9,7 @@ path = "src/quick_action_bar.rs"
doctest = false doctest = false
[dependencies] [dependencies]
ai = { path = "../ai" }
editor = { path = "../editor" } editor = { path = "../editor" }
gpui = { path = "../gpui" } gpui = { path = "../gpui" }
search = { path = "../search" } search = { path = "../search" }

View file

@ -1,25 +1,29 @@
use ai::{assistant::InlineAssist, AssistantPanel};
use editor::Editor; use editor::Editor;
use gpui::{ use gpui::{
elements::{Empty, Flex, MouseEventHandler, ParentElement, Svg}, elements::{Empty, Flex, MouseEventHandler, ParentElement, Svg},
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
Action, AnyElement, Element, Entity, EventContext, Subscription, View, ViewContext, ViewHandle, Action, AnyElement, Element, Entity, EventContext, Subscription, View, ViewContext, ViewHandle,
WeakViewHandle,
}; };
use search::{buffer_search, BufferSearchBar}; use search::{buffer_search, BufferSearchBar};
use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView}; use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView, Workspace};
pub struct QuickActionBar { pub struct QuickActionBar {
buffer_search_bar: ViewHandle<BufferSearchBar>, buffer_search_bar: ViewHandle<BufferSearchBar>,
active_item: Option<Box<dyn ItemHandle>>, active_item: Option<Box<dyn ItemHandle>>,
_inlay_hints_enabled_subscription: Option<Subscription>, _inlay_hints_enabled_subscription: Option<Subscription>,
workspace: WeakViewHandle<Workspace>,
} }
impl QuickActionBar { impl QuickActionBar {
pub fn new(buffer_search_bar: ViewHandle<BufferSearchBar>) -> Self { pub fn new(buffer_search_bar: ViewHandle<BufferSearchBar>, workspace: &Workspace) -> Self {
Self { Self {
buffer_search_bar, buffer_search_bar,
active_item: None, active_item: None,
_inlay_hints_enabled_subscription: None, _inlay_hints_enabled_subscription: None,
workspace: workspace.weak_handle(),
} }
} }
@ -86,6 +90,21 @@ impl View for QuickActionBar {
)); ));
} }
bar.add_child(render_quick_action_bar_button(
2,
"icons/radix/magic-wand.svg",
false,
("Generate code...".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() bar.into_any()
} }
} }

View file

@ -264,8 +264,9 @@ pub fn initialize_workspace(
toolbar.add_item(breadcrumbs, cx); toolbar.add_item(breadcrumbs, cx);
let buffer_search_bar = cx.add_view(BufferSearchBar::new); let buffer_search_bar = cx.add_view(BufferSearchBar::new);
toolbar.add_item(buffer_search_bar.clone(), cx); toolbar.add_item(buffer_search_bar.clone(), cx);
let quick_action_bar = let quick_action_bar = cx.add_view(|_| {
cx.add_view(|_| QuickActionBar::new(buffer_search_bar)); QuickActionBar::new(buffer_search_bar, workspace)
});
toolbar.add_item(quick_action_bar, cx); toolbar.add_item(quick_action_bar, cx);
let project_search_bar = cx.add_view(|_| ProjectSearchBar::new()); let project_search_bar = cx.add_view(|_| ProjectSearchBar::new());
toolbar.add_item(project_search_bar, cx); toolbar.add_item(project_search_bar, cx);