Compare commits
1 Commits
git-clone
...
inline-ass
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7cf3c306a |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -327,6 +327,7 @@ dependencies = [
|
|||||||
"buffer_diff",
|
"buffer_diff",
|
||||||
"chrono",
|
"chrono",
|
||||||
"client",
|
"client",
|
||||||
|
"clock",
|
||||||
"cloud_llm_client",
|
"cloud_llm_client",
|
||||||
"collections",
|
"collections",
|
||||||
"command_palette_hooks",
|
"command_palette_hooks",
|
||||||
@@ -342,6 +343,7 @@ dependencies = [
|
|||||||
"futures 0.3.31",
|
"futures 0.3.31",
|
||||||
"fuzzy",
|
"fuzzy",
|
||||||
"gpui",
|
"gpui",
|
||||||
|
"gpui_tokio",
|
||||||
"html_to_markdown",
|
"html_to_markdown",
|
||||||
"http_client",
|
"http_client",
|
||||||
"image",
|
"image",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ doctest = false
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
test-support = ["gpui/test-support", "language/test-support"]
|
test-support = ["gpui/test-support", "language/test-support"]
|
||||||
|
unit-eval = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
acp_thread.workspace = true
|
acp_thread.workspace = true
|
||||||
@@ -47,6 +48,7 @@ fs.workspace = true
|
|||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
fuzzy.workspace = true
|
fuzzy.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
|
gpui_tokio.workspace = true
|
||||||
html_to_markdown.workspace = true
|
html_to_markdown.workspace = true
|
||||||
http_client.workspace = true
|
http_client.workspace = true
|
||||||
indoc.workspace = true
|
indoc.workspace = true
|
||||||
@@ -106,6 +108,7 @@ acp_thread = { workspace = true, features = ["test-support"] }
|
|||||||
agent = { workspace = true, features = ["test-support"] }
|
agent = { workspace = true, features = ["test-support"] }
|
||||||
assistant_text_thread = { workspace = true, features = ["test-support"] }
|
assistant_text_thread = { workspace = true, features = ["test-support"] }
|
||||||
buffer_diff = { workspace = true, features = ["test-support"] }
|
buffer_diff = { workspace = true, features = ["test-support"] }
|
||||||
|
clock.workspace = true
|
||||||
db = { workspace = true, features = ["test-support"] }
|
db = { workspace = true, features = ["test-support"] }
|
||||||
editor = { workspace = true, features = ["test-support"] }
|
editor = { workspace = true, features = ["test-support"] }
|
||||||
gpui = { workspace = true, "features" = ["test-support"] }
|
gpui = { workspace = true, "features" = ["test-support"] }
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ use settings::{
|
|||||||
|
|
||||||
use zed_actions::agent::{OpenClaudeCodeOnboardingModal, ReauthenticateAgent};
|
use zed_actions::agent::{OpenClaudeCodeOnboardingModal, ReauthenticateAgent};
|
||||||
|
|
||||||
use crate::ui::{AcpOnboardingModal, ClaudeCodeOnboardingModal};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AddContextServer, AgentDiffPane, DeleteRecentlyOpenThread, Follow, InlineAssistant,
|
AddContextServer, AgentDiffPane, DeleteRecentlyOpenThread, Follow, InlineAssistant,
|
||||||
NewTextThread, NewThread, OpenActiveThreadAsMarkdown, OpenAgentDiff, OpenHistory,
|
NewTextThread, NewThread, OpenActiveThreadAsMarkdown, OpenAgentDiff, OpenHistory,
|
||||||
@@ -39,6 +38,10 @@ use crate::{
|
|||||||
ExternalAgent, NewExternalAgentThread, NewNativeAgentThreadFromSummary, placeholder_command,
|
ExternalAgent, NewExternalAgentThread, NewNativeAgentThreadFromSummary, placeholder_command,
|
||||||
};
|
};
|
||||||
use crate::{ManageProfiles, context_store::ContextStore};
|
use crate::{ManageProfiles, context_store::ContextStore};
|
||||||
|
use crate::{
|
||||||
|
inline_assistant::ContextProviders,
|
||||||
|
ui::{AcpOnboardingModal, ClaudeCodeOnboardingModal},
|
||||||
|
};
|
||||||
use agent_settings::AgentSettings;
|
use agent_settings::AgentSettings;
|
||||||
use ai_onboarding::AgentPanelOnboarding;
|
use ai_onboarding::AgentPanelOnboarding;
|
||||||
use anyhow::{Result, anyhow};
|
use anyhow::{Result, anyhow};
|
||||||
@@ -455,6 +458,10 @@ pub struct AgentPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AgentPanel {
|
impl AgentPanel {
|
||||||
|
pub(crate) fn workspace(&self) -> WeakEntity<Workspace> {
|
||||||
|
self.workspace.clone()
|
||||||
|
}
|
||||||
|
|
||||||
fn serialize(&mut self, cx: &mut Context<Self>) {
|
fn serialize(&mut self, cx: &mut Context<Self>) {
|
||||||
let width = self.width;
|
let width = self.width;
|
||||||
let selected_agent = self.selected_agent.clone();
|
let selected_agent = self.selected_agent.clone();
|
||||||
@@ -2700,17 +2707,12 @@ impl rules_library::InlineAssistDelegate for PromptLibraryInlineAssist {
|
|||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let prompt_store = None;
|
let context_providers = ContextProviders::empty(project, cx);
|
||||||
let thread_store = None;
|
|
||||||
let context_store = cx.new(|_| ContextStore::new(project.clone()));
|
|
||||||
assistant.assist(
|
assistant.assist(
|
||||||
prompt_editor,
|
prompt_editor,
|
||||||
self.workspace.clone(),
|
|
||||||
context_store,
|
|
||||||
project,
|
|
||||||
prompt_store,
|
|
||||||
thread_store,
|
|
||||||
initial_prompt,
|
initial_prompt,
|
||||||
|
context_providers,
|
||||||
|
self.workspace.clone(),
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ mod context_picker;
|
|||||||
mod context_server_configuration;
|
mod context_server_configuration;
|
||||||
mod context_store;
|
mod context_store;
|
||||||
mod context_strip;
|
mod context_strip;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod evals;
|
||||||
mod inline_assistant;
|
mod inline_assistant;
|
||||||
mod inline_prompt_editor;
|
mod inline_prompt_editor;
|
||||||
mod language_model_selector;
|
mod language_model_selector;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ use util::rel_path::RelPath;
|
|||||||
use workspace::{Workspace, notifications::NotifyResultExt};
|
use workspace::{Workspace, notifications::NotifyResultExt};
|
||||||
|
|
||||||
use crate::context_picker::thread_context_picker::ThreadContextPicker;
|
use crate::context_picker::thread_context_picker::ThreadContextPicker;
|
||||||
|
use crate::inline_assistant::ContextProviders;
|
||||||
use crate::{context::RULES_ICON, context_store::ContextStore};
|
use crate::{context::RULES_ICON, context_store::ContextStore};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
@@ -172,12 +173,18 @@ pub(super) struct ContextPicker {
|
|||||||
impl ContextPicker {
|
impl ContextPicker {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: WeakEntity<Workspace>,
|
||||||
thread_store: Option<WeakEntity<HistoryStore>>,
|
context_stores: ContextProviders,
|
||||||
prompt_store: Option<WeakEntity<PromptStore>>,
|
|
||||||
context_store: WeakEntity<ContextStore>,
|
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
let context_store = context_stores.context_store.downgrade();
|
||||||
|
let thread_store = context_stores.thread_store.clone();
|
||||||
|
let prompt_store = context_stores
|
||||||
|
.prompt_store
|
||||||
|
.as_ref()
|
||||||
|
.map(Entity::downgrade)
|
||||||
|
.clone();
|
||||||
|
|
||||||
let subscriptions = context_store
|
let subscriptions = context_store
|
||||||
.upgrade()
|
.upgrade()
|
||||||
.map(|context_store| {
|
.map(|context_store| {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ use util::paths::PathStyle;
|
|||||||
use util::rel_path::RelPath;
|
use util::rel_path::RelPath;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
|
use crate::inline_assistant::ContextProviders;
|
||||||
use crate::{
|
use crate::{
|
||||||
context::{AgentContextHandle, AgentContextKey, RULES_ICON},
|
context::{AgentContextHandle, AgentContextKey, RULES_ICON},
|
||||||
context_store::ContextStore,
|
context_store::ContextStore,
|
||||||
@@ -245,17 +246,15 @@ pub struct ContextPickerCompletionProvider {
|
|||||||
impl ContextPickerCompletionProvider {
|
impl ContextPickerCompletionProvider {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: WeakEntity<Workspace>,
|
||||||
context_store: WeakEntity<ContextStore>,
|
context_stores: ContextProviders,
|
||||||
thread_store: Option<WeakEntity<HistoryStore>>,
|
|
||||||
prompt_store: Option<WeakEntity<PromptStore>>,
|
|
||||||
editor: WeakEntity<Editor>,
|
editor: WeakEntity<Editor>,
|
||||||
exclude_buffer: Option<WeakEntity<Buffer>>,
|
exclude_buffer: Option<WeakEntity<Buffer>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
workspace,
|
workspace,
|
||||||
context_store,
|
context_store: context_stores.context_store.downgrade(),
|
||||||
thread_store,
|
thread_store: context_stores.thread_store,
|
||||||
prompt_store,
|
prompt_store: context_stores.prompt_store.as_ref().map(Entity::downgrade),
|
||||||
editor,
|
editor,
|
||||||
excluded_buffer: exclude_buffer,
|
excluded_buffer: exclude_buffer,
|
||||||
}
|
}
|
||||||
@@ -1292,7 +1291,7 @@ mod tests {
|
|||||||
editor
|
editor
|
||||||
});
|
});
|
||||||
|
|
||||||
let context_store = cx.new(|_| ContextStore::new(project.downgrade()));
|
let context_providers = ContextProviders::empty(project.downgrade(), cx);
|
||||||
|
|
||||||
let editor_entity = editor.downgrade();
|
let editor_entity = editor.downgrade();
|
||||||
editor.update_in(&mut cx, |editor, window, cx| {
|
editor.update_in(&mut cx, |editor, window, cx| {
|
||||||
@@ -1307,11 +1306,10 @@ mod tests {
|
|||||||
.map(Entity::downgrade)
|
.map(Entity::downgrade)
|
||||||
});
|
});
|
||||||
window.focus(&editor.focus_handle(cx));
|
window.focus(&editor.focus_handle(cx));
|
||||||
|
|
||||||
editor.set_completion_provider(Some(Rc::new(ContextPickerCompletionProvider::new(
|
editor.set_completion_provider(Some(Rc::new(ContextPickerCompletionProvider::new(
|
||||||
workspace.downgrade(),
|
workspace.downgrade(),
|
||||||
context_store.downgrade(),
|
context_providers,
|
||||||
None,
|
|
||||||
None,
|
|
||||||
editor_entity,
|
editor_entity,
|
||||||
last_opened_buffer,
|
last_opened_buffer,
|
||||||
))));
|
))));
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ pub enum ContextStoreEvent {
|
|||||||
impl EventEmitter<ContextStoreEvent> for ContextStore {}
|
impl EventEmitter<ContextStoreEvent> for ContextStore {}
|
||||||
|
|
||||||
impl ContextStore {
|
impl ContextStore {
|
||||||
|
pub fn project(&self) -> WeakEntity<Project> {
|
||||||
|
self.project.clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(project: WeakEntity<Project>) -> Self {
|
pub fn new(project: WeakEntity<Project>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
project,
|
project,
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ use crate::{
|
|||||||
AcceptSuggestedContext, AgentPanel, FocusDown, FocusLeft, FocusRight, FocusUp,
|
AcceptSuggestedContext, AgentPanel, FocusDown, FocusLeft, FocusRight, FocusUp,
|
||||||
ModelUsageContext, RemoveAllContext, RemoveFocusedContext, ToggleContextPicker,
|
ModelUsageContext, RemoveAllContext, RemoveFocusedContext, ToggleContextPicker,
|
||||||
context_picker::ContextPicker,
|
context_picker::ContextPicker,
|
||||||
|
inline_assistant::ContextProviders,
|
||||||
ui::{AddedContext, ContextPill},
|
ui::{AddedContext, ContextPill},
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
context::AgentContextHandle,
|
context::AgentContextHandle,
|
||||||
context_store::{ContextStore, SuggestedContext},
|
context_store::{ContextStore, SuggestedContext},
|
||||||
};
|
};
|
||||||
use agent::HistoryStore;
|
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
@@ -42,10 +42,8 @@ pub struct ContextStrip {
|
|||||||
|
|
||||||
impl ContextStrip {
|
impl ContextStrip {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
context_store: Entity<ContextStore>,
|
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: WeakEntity<Workspace>,
|
||||||
thread_store: Option<WeakEntity<HistoryStore>>,
|
inline_services: ContextProviders,
|
||||||
prompt_store: Option<WeakEntity<PromptStore>>,
|
|
||||||
context_picker_menu_handle: PopoverMenuHandle<ContextPicker>,
|
context_picker_menu_handle: PopoverMenuHandle<ContextPicker>,
|
||||||
suggest_context_kind: SuggestContextKind,
|
suggest_context_kind: SuggestContextKind,
|
||||||
model_usage_context: ModelUsageContext,
|
model_usage_context: ModelUsageContext,
|
||||||
|
|||||||
1869
crates/agent_ui/src/evals.rs
Normal file
1869
crates/agent_ui/src/evals.rs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,7 @@ use agent_settings::AgentSettings;
|
|||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
use client::telemetry::Telemetry;
|
use client::telemetry::Telemetry;
|
||||||
use collections::{HashMap, HashSet, VecDeque, hash_map};
|
use collections::{HashMap, HashSet, VecDeque, hash_map};
|
||||||
|
use editor::EditorSnapshot;
|
||||||
use editor::RowExt;
|
use editor::RowExt;
|
||||||
use editor::SelectionEffects;
|
use editor::SelectionEffects;
|
||||||
use editor::scroll::ScrollOffset;
|
use editor::scroll::ScrollOffset;
|
||||||
@@ -87,6 +88,38 @@ enum InlineAssistTarget {
|
|||||||
Terminal(Entity<TerminalView>),
|
Terminal(Entity<TerminalView>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub(crate) struct ContextProviders {
|
||||||
|
pub(crate) workspace: Option<WeakEntity<Workspace>>,
|
||||||
|
pub(crate) prompt_store: Option<Entity<PromptStore>>,
|
||||||
|
pub(crate) thread_store: Option<WeakEntity<HistoryStore>>,
|
||||||
|
pub(crate) context_store: Entity<ContextStore>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ContextProviders {
|
||||||
|
pub(crate) fn project(&self, cx: &mut App) -> WeakEntity<Project> {
|
||||||
|
self.context_store.read(cx).project()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn from_panel(agent_panel: &AgentPanel) -> Self {
|
||||||
|
Self {
|
||||||
|
workspace: Some(agent_panel.workspace()),
|
||||||
|
prompt_store: agent_panel.prompt_store().as_ref().cloned(),
|
||||||
|
thread_store: Some(agent_panel.thread_store().downgrade()),
|
||||||
|
context_store: agent_panel.inline_assist_context_store().clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn empty(project: WeakEntity<Project>, cx: &mut App) -> Self {
|
||||||
|
Self {
|
||||||
|
workspace: None,
|
||||||
|
prompt_store: None,
|
||||||
|
thread_store: None,
|
||||||
|
context_store: cx.new(|_| ContextStore::new(project.clone())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct InlineAssistant {
|
pub struct InlineAssistant {
|
||||||
next_assist_id: InlineAssistId,
|
next_assist_id: InlineAssistId,
|
||||||
next_assist_group_id: InlineAssistGroupId,
|
next_assist_group_id: InlineAssistGroupId,
|
||||||
@@ -274,11 +307,8 @@ impl InlineAssistant {
|
|||||||
let Some(agent_panel) = workspace.panel::<AgentPanel>(cx) else {
|
let Some(agent_panel) = workspace.panel::<AgentPanel>(cx) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let agent_panel = agent_panel.read(cx);
|
|
||||||
|
|
||||||
let prompt_store = agent_panel.prompt_store().as_ref().cloned();
|
let services = ContextProviders::from_panel(agent_panel.read(cx));
|
||||||
let thread_store = Some(agent_panel.thread_store().downgrade());
|
|
||||||
let context_store = agent_panel.inline_assist_context_store().clone();
|
|
||||||
|
|
||||||
let handle_assist =
|
let handle_assist =
|
||||||
|window: &mut Window, cx: &mut Context<Workspace>| match inline_assist_target {
|
|window: &mut Window, cx: &mut Context<Workspace>| match inline_assist_target {
|
||||||
@@ -287,10 +317,6 @@ impl InlineAssistant {
|
|||||||
assistant.assist(
|
assistant.assist(
|
||||||
&active_editor,
|
&active_editor,
|
||||||
cx.entity().downgrade(),
|
cx.entity().downgrade(),
|
||||||
context_store,
|
|
||||||
workspace.project().downgrade(),
|
|
||||||
prompt_store,
|
|
||||||
thread_store,
|
|
||||||
action.prompt.clone(),
|
action.prompt.clone(),
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
@@ -302,10 +328,8 @@ impl InlineAssistant {
|
|||||||
assistant.assist(
|
assistant.assist(
|
||||||
&active_terminal,
|
&active_terminal,
|
||||||
cx.entity().downgrade(),
|
cx.entity().downgrade(),
|
||||||
workspace.project().downgrade(),
|
|
||||||
prompt_store,
|
|
||||||
thread_store,
|
|
||||||
action.prompt.clone(),
|
action.prompt.clone(),
|
||||||
|
services,
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
@@ -350,25 +374,20 @@ impl InlineAssistant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn assist(
|
fn codegen_ranges(
|
||||||
&mut self,
|
&mut self,
|
||||||
editor: &Entity<Editor>,
|
editor: &Entity<Editor>,
|
||||||
workspace: WeakEntity<Workspace>,
|
snapshot: &EditorSnapshot,
|
||||||
context_store: Entity<ContextStore>,
|
|
||||||
project: WeakEntity<Project>,
|
|
||||||
prompt_store: Option<Entity<PromptStore>>,
|
|
||||||
thread_store: Option<WeakEntity<HistoryStore>>,
|
|
||||||
initial_prompt: Option<String>,
|
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) {
|
) -> Option<(Vec<Range<Anchor>>, Selection<Point>)> {
|
||||||
let (snapshot, initial_selections, newest_selection) = editor.update(cx, |editor, cx| {
|
let (initial_selections, newest_selection) = editor.update(cx, |editor, _| {
|
||||||
let snapshot = editor.snapshot(window, cx);
|
(
|
||||||
let selections = editor.selections.all::<Point>(&snapshot.display_snapshot);
|
editor.selections.all::<Point>(&snapshot.display_snapshot),
|
||||||
let newest_selection = editor
|
editor
|
||||||
.selections
|
.selections
|
||||||
.newest::<Point>(&snapshot.display_snapshot);
|
.newest::<Point>(&snapshot.display_snapshot),
|
||||||
(snapshot, selections, newest_selection)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if there is already an inline assistant that contains the
|
// Check if there is already an inline assistant that contains the
|
||||||
@@ -381,7 +400,7 @@ impl InlineAssistant {
|
|||||||
&& newest_selection.end.row <= range.end.row
|
&& newest_selection.end.row <= range.end.row
|
||||||
{
|
{
|
||||||
self.focus_assist(*assist_id, window, cx);
|
self.focus_assist(*assist_id, window, cx);
|
||||||
return;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -473,6 +492,25 @@ impl InlineAssistant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some((codegen_ranges, newest_selection))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn assist(
|
||||||
|
&mut self,
|
||||||
|
editor: &Entity<Editor>,
|
||||||
|
initial_prompt: Option<String>,
|
||||||
|
services: ContextProviders,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) {
|
||||||
|
let snapshot = editor.update(cx, |editor, cx| editor.snapshot(window, cx));
|
||||||
|
|
||||||
|
let Some((codegen_ranges, newest_selection)) =
|
||||||
|
self.codegen_ranges(editor, &snapshot, window, cx)
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let assist_group_id = self.next_assist_group_id.post_inc();
|
let assist_group_id = self.next_assist_group_id.post_inc();
|
||||||
let prompt_buffer = cx.new(|cx| {
|
let prompt_buffer = cx.new(|cx| {
|
||||||
MultiBuffer::singleton(
|
MultiBuffer::singleton(
|
||||||
@@ -484,53 +522,26 @@ impl InlineAssistant {
|
|||||||
let mut assists = Vec::new();
|
let mut assists = Vec::new();
|
||||||
let mut assist_to_focus = None;
|
let mut assist_to_focus = None;
|
||||||
for range in codegen_ranges {
|
for range in codegen_ranges {
|
||||||
let assist_id = self.next_assist_id.post_inc();
|
let (assist_id, prompt_block_id, end_block_id, prompt_editor) = self.single_assist(
|
||||||
let codegen = cx.new(|cx| {
|
range.clone(),
|
||||||
BufferCodegen::new(
|
editor,
|
||||||
editor.read(cx).buffer().clone(),
|
prompt_buffer.clone(),
|
||||||
range.clone(),
|
services.clone(),
|
||||||
None,
|
window,
|
||||||
context_store.clone(),
|
cx,
|
||||||
project.clone(),
|
);
|
||||||
prompt_store.clone(),
|
|
||||||
self.telemetry.clone(),
|
|
||||||
self.prompt_builder.clone(),
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
let editor_margins = Arc::new(Mutex::new(EditorMargins::default()));
|
|
||||||
let prompt_editor = cx.new(|cx| {
|
|
||||||
PromptEditor::new_buffer(
|
|
||||||
assist_id,
|
|
||||||
editor_margins,
|
|
||||||
self.prompt_history.clone(),
|
|
||||||
prompt_buffer.clone(),
|
|
||||||
codegen.clone(),
|
|
||||||
self.fs.clone(),
|
|
||||||
context_store.clone(),
|
|
||||||
workspace.clone(),
|
|
||||||
thread_store.clone(),
|
|
||||||
prompt_store.as_ref().map(|s| s.downgrade()),
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
if assist_to_focus.is_none() {
|
if assist_to_focus.is_none() {
|
||||||
let focus_assist = if newest_selection.reversed {
|
let focus_assist = if newest_selection.reversed {
|
||||||
range.start.to_point(snapshot) == newest_selection.start
|
range.start.to_point(&snapshot) == newest_selection.start
|
||||||
} else {
|
} else {
|
||||||
range.end.to_point(snapshot) == newest_selection.end
|
range.end.to_point(&snapshot) == newest_selection.end
|
||||||
};
|
};
|
||||||
if focus_assist {
|
if focus_assist {
|
||||||
assist_to_focus = Some(assist_id);
|
assist_to_focus = Some(assist_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let [prompt_block_id, end_block_id] =
|
|
||||||
self.insert_assist_blocks(editor, &range, &prompt_editor, cx);
|
|
||||||
|
|
||||||
assists.push((
|
assists.push((
|
||||||
assist_id,
|
assist_id,
|
||||||
range,
|
range,
|
||||||
@@ -574,11 +585,66 @@ impl InlineAssistant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn single_assist(
|
||||||
|
&mut self,
|
||||||
|
range: Range<Anchor>,
|
||||||
|
editor: &Entity<Editor>,
|
||||||
|
workspace: WeakEntity<Workspace>,
|
||||||
|
prompt_buffer: Entity<MultiBuffer>,
|
||||||
|
services: ContextProviders,
|
||||||
|
project: &WeakEntity<Project>,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) -> (
|
||||||
|
InlineAssistId,
|
||||||
|
CustomBlockId,
|
||||||
|
CustomBlockId,
|
||||||
|
Entity<PromptEditor<BufferCodegen>>,
|
||||||
|
) {
|
||||||
|
let assist_id = self.next_assist_id.post_inc();
|
||||||
|
let codegen = cx.new(|cx| {
|
||||||
|
BufferCodegen::new(
|
||||||
|
editor.read(cx).buffer().clone(),
|
||||||
|
range.clone(),
|
||||||
|
None,
|
||||||
|
context_store.clone(),
|
||||||
|
project.clone(),
|
||||||
|
prompt_store.clone(),
|
||||||
|
self.telemetry.clone(),
|
||||||
|
self.prompt_builder.clone(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let editor_margins = Arc::new(Mutex::new(EditorMargins::default()));
|
||||||
|
let prompt_editor = cx.new(|cx| {
|
||||||
|
PromptEditor::new_buffer(
|
||||||
|
assist_id,
|
||||||
|
editor_margins,
|
||||||
|
self.prompt_history.clone(),
|
||||||
|
prompt_buffer.clone(),
|
||||||
|
codegen.clone(),
|
||||||
|
self.fs.clone(),
|
||||||
|
context_store.clone(),
|
||||||
|
workspace.clone(),
|
||||||
|
thread_store.clone(),
|
||||||
|
prompt_store.as_ref().map(|s| s.downgrade()),
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let [prompt_block_id, end_block_id] =
|
||||||
|
self.insert_assist_blocks(editor, &range, &prompt_editor, cx);
|
||||||
|
|
||||||
|
(assist_id, prompt_block_id, end_block_id, prompt_editor)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn suggest_assist(
|
pub fn suggest_assist(
|
||||||
&mut self,
|
&mut self,
|
||||||
editor: &Entity<Editor>,
|
editor: &Entity<Editor>,
|
||||||
mut range: Range<Anchor>,
|
mut range: Range<Anchor>,
|
||||||
initial_prompt: String,
|
prompt_buffer: Entity<MultiBuffer>,
|
||||||
initial_transaction_id: Option<TransactionId>,
|
initial_transaction_id: Option<TransactionId>,
|
||||||
focus: bool,
|
focus: bool,
|
||||||
workspace: Entity<Workspace>,
|
workspace: Entity<Workspace>,
|
||||||
@@ -587,9 +653,8 @@ impl InlineAssistant {
|
|||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) -> InlineAssistId {
|
) -> InlineAssistId {
|
||||||
|
/// !!!!!!!!
|
||||||
let assist_group_id = self.next_assist_group_id.post_inc();
|
let assist_group_id = self.next_assist_group_id.post_inc();
|
||||||
let prompt_buffer = cx.new(|cx| Buffer::local(&initial_prompt, cx));
|
|
||||||
let prompt_buffer = cx.new(|cx| MultiBuffer::singleton(prompt_buffer, cx));
|
|
||||||
|
|
||||||
let assist_id = self.next_assist_id.post_inc();
|
let assist_id = self.next_assist_id.post_inc();
|
||||||
|
|
||||||
@@ -1879,11 +1944,15 @@ impl CodeActionProvider for AssistantCodeActionProvider {
|
|||||||
.context("invalid range")?;
|
.context("invalid range")?;
|
||||||
|
|
||||||
let prompt_store = prompt_store.await.ok();
|
let prompt_store = prompt_store.await.ok();
|
||||||
|
|
||||||
|
const PROMPT: &'static str = "Fix Diagnostics";
|
||||||
cx.update_global(|assistant: &mut InlineAssistant, window, cx| {
|
cx.update_global(|assistant: &mut InlineAssistant, window, cx| {
|
||||||
|
let prompt_buffer = cx.new(|cx| Buffer::local(PROMPT, cx));
|
||||||
|
let prompt_buffer = cx.new(|cx| MultiBuffer::singleton(prompt_buffer, cx));
|
||||||
let assist_id = assistant.suggest_assist(
|
let assist_id = assistant.suggest_assist(
|
||||||
&editor,
|
&editor,
|
||||||
range,
|
range,
|
||||||
"Fix Diagnostics".into(),
|
prompt_buffer,
|
||||||
None,
|
None,
|
||||||
true,
|
true,
|
||||||
workspace,
|
workspace,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ use crate::context::{AgentContextHandle, AgentContextKey};
|
|||||||
use crate::context_picker::{ContextPicker, ContextPickerCompletionProvider, crease_for_mention};
|
use crate::context_picker::{ContextPicker, ContextPickerCompletionProvider, crease_for_mention};
|
||||||
use crate::context_store::{ContextStore, ContextStoreEvent};
|
use crate::context_store::{ContextStore, ContextStoreEvent};
|
||||||
use crate::context_strip::{ContextStrip, ContextStripEvent, SuggestContextKind};
|
use crate::context_strip::{ContextStrip, ContextStripEvent, SuggestContextKind};
|
||||||
|
use crate::inline_assistant::ContextProviders;
|
||||||
use crate::terminal_codegen::TerminalCodegen;
|
use crate::terminal_codegen::TerminalCodegen;
|
||||||
use crate::{
|
use crate::{
|
||||||
CycleNextInlineAssist, CyclePreviousInlineAssist, ModelUsageContext, RemoveAllContext,
|
CycleNextInlineAssist, CyclePreviousInlineAssist, ModelUsageContext, RemoveAllContext,
|
||||||
@@ -773,10 +774,8 @@ impl PromptEditor<BufferCodegen> {
|
|||||||
prompt_buffer: Entity<MultiBuffer>,
|
prompt_buffer: Entity<MultiBuffer>,
|
||||||
codegen: Entity<BufferCodegen>,
|
codegen: Entity<BufferCodegen>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
context_store: Entity<ContextStore>,
|
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: WeakEntity<Workspace>,
|
||||||
thread_store: Option<WeakEntity<HistoryStore>>,
|
services: ContextProviders,
|
||||||
prompt_store: Option<WeakEntity<PromptStore>>,
|
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<PromptEditor<BufferCodegen>>,
|
cx: &mut Context<PromptEditor<BufferCodegen>>,
|
||||||
) -> PromptEditor<BufferCodegen> {
|
) -> PromptEditor<BufferCodegen> {
|
||||||
@@ -945,10 +944,8 @@ impl PromptEditor<TerminalCodegen> {
|
|||||||
prompt_buffer: Entity<MultiBuffer>,
|
prompt_buffer: Entity<MultiBuffer>,
|
||||||
codegen: Entity<TerminalCodegen>,
|
codegen: Entity<TerminalCodegen>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
context_store: Entity<ContextStore>,
|
context_providers: ContextProviders,
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: WeakEntity<Workspace>,
|
||||||
thread_store: Option<WeakEntity<HistoryStore>>,
|
|
||||||
prompt_store: Option<WeakEntity<PromptStore>>,
|
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
context::load_context,
|
context::load_context,
|
||||||
context_store::ContextStore,
|
context_store::ContextStore,
|
||||||
|
inline_assistant::ContextProviders,
|
||||||
inline_prompt_editor::{
|
inline_prompt_editor::{
|
||||||
CodegenStatus, PromptEditor, PromptEditorEvent, TerminalInlineAssistId,
|
CodegenStatus, PromptEditor, PromptEditorEvent, TerminalInlineAssistId,
|
||||||
},
|
},
|
||||||
@@ -72,10 +73,8 @@ impl TerminalInlineAssistant {
|
|||||||
&mut self,
|
&mut self,
|
||||||
terminal_view: &Entity<TerminalView>,
|
terminal_view: &Entity<TerminalView>,
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: WeakEntity<Workspace>,
|
||||||
project: WeakEntity<Project>,
|
|
||||||
prompt_store: Option<Entity<PromptStore>>,
|
|
||||||
thread_store: Option<WeakEntity<HistoryStore>>,
|
|
||||||
initial_prompt: Option<String>,
|
initial_prompt: Option<String>,
|
||||||
|
context_providers: ContextProviders,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) {
|
) {
|
||||||
@@ -87,7 +86,7 @@ impl TerminalInlineAssistant {
|
|||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let context_store = cx.new(|_cx| ContextStore::new(project));
|
|
||||||
let codegen = cx.new(|_| TerminalCodegen::new(terminal, self.telemetry.clone()));
|
let codegen = cx.new(|_| TerminalCodegen::new(terminal, self.telemetry.clone()));
|
||||||
|
|
||||||
let prompt_editor = cx.new(|cx| {
|
let prompt_editor = cx.new(|cx| {
|
||||||
@@ -97,10 +96,8 @@ impl TerminalInlineAssistant {
|
|||||||
prompt_buffer.clone(),
|
prompt_buffer.clone(),
|
||||||
codegen,
|
codegen,
|
||||||
self.fs.clone(),
|
self.fs.clone(),
|
||||||
context_store.clone(),
|
context_providers,
|
||||||
workspace.clone(),
|
workspace.clone(),
|
||||||
thread_store.clone(),
|
|
||||||
prompt_store.as_ref().map(|s| s.downgrade()),
|
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
@@ -420,8 +417,7 @@ impl TerminalInlineAssist {
|
|||||||
terminal: &Entity<TerminalView>,
|
terminal: &Entity<TerminalView>,
|
||||||
prompt_editor: Entity<PromptEditor<TerminalCodegen>>,
|
prompt_editor: Entity<PromptEditor<TerminalCodegen>>,
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: WeakEntity<Workspace>,
|
||||||
context_store: Entity<ContextStore>,
|
context_providers: ContextProviders,
|
||||||
prompt_store: Option<Entity<PromptStore>>,
|
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|||||||
@@ -966,6 +966,7 @@ impl AppState {
|
|||||||
|
|
||||||
if !cx.has_global::<SettingsStore>() {
|
if !cx.has_global::<SettingsStore>() {
|
||||||
let settings_store = SettingsStore::test(cx);
|
let settings_store = SettingsStore::test(cx);
|
||||||
|
|
||||||
cx.set_global(settings_store);
|
cx.set_global(settings_store);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user