assistant2: Background load of context + prep for refresh + efficiency (#22935)
* Now loads context on background threads. - For file and directory context, buffer ropes can be shared between threads as they are immutable. This allows for traversal and accumulation of buffer text on a background thread. - For url context, the request, parsing, and rendering is now done on a background thread. * Prepares for support of buffer reload by individually storing the text of directory buffers. * Avoids some string copying / redundant strings. - When attaching message context, no longer builds a string for each context type. - For directory context, does not build a `SharedString` for the full text, instead has a slice of `SharedString` chunks which are then directly appended to the message context. - Building a fenced codeblock for a buffer now computes a precise capacity in advance. Release Notes: - N/A
This commit is contained in:
parent
c41b25cc90
commit
0dd7ea4575
5 changed files with 245 additions and 111 deletions
|
@ -81,13 +81,12 @@ impl FetchContextPickerDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
async fn build_message(http_client: Arc<HttpClientWithUrl>, url: &str) -> Result<String> {
|
||||
let prefixed_url = if !url.starts_with("https://") && !url.starts_with("http://") {
|
||||
Some(format!("https://{url}"))
|
||||
async fn build_message(http_client: Arc<HttpClientWithUrl>, url: String) -> Result<String> {
|
||||
let url = if !url.starts_with("https://") && !url.starts_with("http://") {
|
||||
format!("https://{url}")
|
||||
} else {
|
||||
None
|
||||
url
|
||||
};
|
||||
let url = prefixed_url.as_deref().unwrap_or(url);
|
||||
|
||||
let mut response = http_client.get(&url, AsyncBody::default(), true).await?;
|
||||
|
||||
|
@ -196,7 +195,10 @@ impl PickerDelegate for FetchContextPickerDelegate {
|
|||
let url = self.url.clone();
|
||||
let confirm_behavior = self.confirm_behavior;
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
let text = Self::build_message(http_client, &url).await?;
|
||||
let text = cx
|
||||
.background_executor()
|
||||
.spawn(Self::build_message(http_client, url.clone()))
|
||||
.await?;
|
||||
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.delegate
|
||||
|
|
|
@ -201,7 +201,7 @@ impl PickerDelegate for FileContextPickerDelegate {
|
|||
let Some(task) = self
|
||||
.context_store
|
||||
.update(cx, |context_store, cx| {
|
||||
context_store.add_file(project_path, cx)
|
||||
context_store.add_file_from_path(project_path, cx)
|
||||
})
|
||||
.ok()
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue