add indexing on inline assistant opening
This commit is contained in:
parent
c0a1328532
commit
38ccf23567
1 changed files with 40 additions and 18 deletions
|
@ -24,10 +24,10 @@ use futures::StreamExt;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions,
|
||||||
elements::{
|
elements::{
|
||||||
ChildView, Component, Empty, Flex, Label, LabelStyle, MouseEventHandler, ParentElement,
|
ChildView, Component, Empty, Flex, Label, MouseEventHandler, ParentElement, SafeStylable,
|
||||||
SafeStylable, Stack, Svg, Text, UniformList, UniformListState,
|
Stack, Svg, Text, UniformList, UniformListState,
|
||||||
},
|
},
|
||||||
fonts::{HighlightStyle, TextStyle},
|
fonts::HighlightStyle,
|
||||||
geometry::vector::{vec2f, Vector2F},
|
geometry::vector::{vec2f, Vector2F},
|
||||||
platform::{CursorStyle, MouseButton, PromptLevel},
|
platform::{CursorStyle, MouseButton, PromptLevel},
|
||||||
Action, AnyElement, AppContext, AsyncAppContext, ClipboardItem, Element, Entity, ModelContext,
|
Action, AnyElement, AppContext, AsyncAppContext, ClipboardItem, Element, Entity, ModelContext,
|
||||||
|
@ -52,7 +52,7 @@ use std::{
|
||||||
};
|
};
|
||||||
use theme::{
|
use theme::{
|
||||||
components::{action_button::Button, ComponentExt},
|
components::{action_button::Button, ComponentExt},
|
||||||
AssistantStyle, Icon,
|
AssistantStyle,
|
||||||
};
|
};
|
||||||
use util::{paths::CONVERSATIONS_DIR, post_inc, ResultExt, TryFutureExt};
|
use util::{paths::CONVERSATIONS_DIR, post_inc, ResultExt, TryFutureExt};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -2755,7 +2755,7 @@ struct InlineAssistant {
|
||||||
retrieve_context: bool,
|
retrieve_context: bool,
|
||||||
semantic_index: Option<ModelHandle<SemanticIndex>>,
|
semantic_index: Option<ModelHandle<SemanticIndex>>,
|
||||||
semantic_permissioned: Option<bool>,
|
semantic_permissioned: Option<bool>,
|
||||||
project: ModelHandle<Project>,
|
project: WeakModelHandle<Project>,
|
||||||
maintain_rate_limit: Option<Task<()>>,
|
maintain_rate_limit: Option<Task<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2914,7 +2914,7 @@ impl InlineAssistant {
|
||||||
subscriptions.push(cx.observe(&semantic_index, Self::semantic_index_changed));
|
subscriptions.push(cx.observe(&semantic_index, Self::semantic_index_changed));
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
let assistant = Self {
|
||||||
id,
|
id,
|
||||||
prompt_editor,
|
prompt_editor,
|
||||||
workspace,
|
workspace,
|
||||||
|
@ -2930,9 +2930,13 @@ impl InlineAssistant {
|
||||||
retrieve_context,
|
retrieve_context,
|
||||||
semantic_permissioned: None,
|
semantic_permissioned: None,
|
||||||
semantic_index,
|
semantic_index,
|
||||||
project,
|
project: project.downgrade(),
|
||||||
maintain_rate_limit: None,
|
maintain_rate_limit: None,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
assistant.index_project(cx).log_err();
|
||||||
|
|
||||||
|
assistant
|
||||||
}
|
}
|
||||||
|
|
||||||
fn semantic_permissioned(&mut self, cx: &mut ViewContext<Self>) -> Task<Result<bool>> {
|
fn semantic_permissioned(&mut self, cx: &mut ViewContext<Self>) -> Task<Result<bool>> {
|
||||||
|
@ -2940,7 +2944,10 @@ impl InlineAssistant {
|
||||||
return Task::ready(Ok(value));
|
return Task::ready(Ok(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
let project = self.project.clone();
|
let Some(project) = self.project.upgrade(cx) else {
|
||||||
|
return Task::ready(Err(anyhow!("project was dropped")));
|
||||||
|
};
|
||||||
|
|
||||||
self.semantic_index
|
self.semantic_index
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.map(|semantic| {
|
.map(|semantic| {
|
||||||
|
@ -2966,7 +2973,10 @@ impl InlineAssistant {
|
||||||
semantic_index: ModelHandle<SemanticIndex>,
|
semantic_index: ModelHandle<SemanticIndex>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
let project = self.project.clone();
|
let Some(project) = self.project.upgrade(cx) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let status = semantic_index.read(cx).status(&project);
|
let status = semantic_index.read(cx).status(&project);
|
||||||
match status {
|
match status {
|
||||||
SemanticIndexStatus::Indexing {
|
SemanticIndexStatus::Indexing {
|
||||||
|
@ -3047,7 +3057,11 @@ impl InlineAssistant {
|
||||||
|
|
||||||
fn toggle_retrieve_context(&mut self, _: &ToggleRetrieveContext, cx: &mut ViewContext<Self>) {
|
fn toggle_retrieve_context(&mut self, _: &ToggleRetrieveContext, cx: &mut ViewContext<Self>) {
|
||||||
let semantic_permissioned = self.semantic_permissioned(cx);
|
let semantic_permissioned = self.semantic_permissioned(cx);
|
||||||
let project = self.project.clone();
|
|
||||||
|
let Some(project) = self.project.upgrade(cx) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let project_name = project
|
let project_name = project
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.worktree_root_names(cx)
|
.worktree_root_names(cx)
|
||||||
|
@ -3086,7 +3100,11 @@ impl InlineAssistant {
|
||||||
cx.emit(InlineAssistantEvent::RetrieveContextToggled {
|
cx.emit(InlineAssistantEvent::RetrieveContextToggled {
|
||||||
retrieve_context: this.retrieve_context,
|
retrieve_context: this.retrieve_context,
|
||||||
});
|
});
|
||||||
this.index_project(project, cx).log_err();
|
|
||||||
|
if this.retrieve_context {
|
||||||
|
this.index_project(cx).log_err();
|
||||||
|
}
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -3095,11 +3113,11 @@ impl InlineAssistant {
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index_project(
|
fn index_project(&self, cx: &mut ViewContext<Self>) -> anyhow::Result<()> {
|
||||||
&self,
|
let Some(project) = self.project.upgrade(cx) else {
|
||||||
project: ModelHandle<Project>,
|
return Err(anyhow!("project was dropped!"));
|
||||||
cx: &mut ViewContext<Self>,
|
};
|
||||||
) -> anyhow::Result<()> {
|
|
||||||
if let Some(semantic_index) = SemanticIndex::global(cx) {
|
if let Some(semantic_index) = SemanticIndex::global(cx) {
|
||||||
cx.spawn(|_, mut cx| async move {
|
cx.spawn(|_, mut cx| async move {
|
||||||
semantic_index
|
semantic_index
|
||||||
|
@ -3117,7 +3135,11 @@ impl InlineAssistant {
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<AnyElement<InlineAssistant>> {
|
) -> Option<AnyElement<InlineAssistant>> {
|
||||||
enum ContextStatusIcon {}
|
enum ContextStatusIcon {}
|
||||||
let project = self.project.clone();
|
|
||||||
|
let Some(project) = self.project.upgrade(cx) else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(semantic_index) = SemanticIndex::global(cx) {
|
if let Some(semantic_index) = SemanticIndex::global(cx) {
|
||||||
let status = semantic_index.update(cx, |index, _| index.status(&project));
|
let status = semantic_index.update(cx, |index, _| index.status(&project));
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue