Include mention context in acp-based native agent (#36006)
Also adds data-layer support for symbols, thread, and rules. Release Notes: - N/A --------- Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
parent
2444321756
commit
44953375cc
9 changed files with 630 additions and 231 deletions
|
@ -1,13 +1,15 @@
|
|||
mod connection;
|
||||
mod diff;
|
||||
mod mention;
|
||||
mod terminal;
|
||||
|
||||
pub use connection::*;
|
||||
pub use diff::*;
|
||||
pub use mention::*;
|
||||
pub use terminal::*;
|
||||
|
||||
use action_log::ActionLog;
|
||||
use agent_client_protocol as acp;
|
||||
use agent_client_protocol::{self as acp};
|
||||
use anyhow::{Context as _, Result};
|
||||
use editor::Bias;
|
||||
use futures::{FutureExt, channel::oneshot, future::BoxFuture};
|
||||
|
@ -21,12 +23,7 @@ use std::error::Error;
|
|||
use std::fmt::Formatter;
|
||||
use std::process::ExitStatus;
|
||||
use std::rc::Rc;
|
||||
use std::{
|
||||
fmt::Display,
|
||||
mem,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
use std::{fmt::Display, mem, path::PathBuf, sync::Arc};
|
||||
use ui::App;
|
||||
use util::ResultExt;
|
||||
|
||||
|
@ -53,38 +50,6 @@ impl UserMessage {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MentionPath<'a>(&'a Path);
|
||||
|
||||
impl<'a> MentionPath<'a> {
|
||||
const PREFIX: &'static str = "@file:";
|
||||
|
||||
pub fn new(path: &'a Path) -> Self {
|
||||
MentionPath(path)
|
||||
}
|
||||
|
||||
pub fn try_parse(url: &'a str) -> Option<Self> {
|
||||
let path = url.strip_prefix(Self::PREFIX)?;
|
||||
Some(MentionPath(Path::new(path)))
|
||||
}
|
||||
|
||||
pub fn path(&self) -> &Path {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for MentionPath<'_> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"[@{}]({}{})",
|
||||
self.0.file_name().unwrap_or_default().display(),
|
||||
Self::PREFIX,
|
||||
self.0.display()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct AssistantMessage {
|
||||
pub chunks: Vec<AssistantMessageChunk>,
|
||||
|
@ -367,16 +332,24 @@ impl ContentBlock {
|
|||
) {
|
||||
let new_content = match block {
|
||||
acp::ContentBlock::Text(text_content) => text_content.text.clone(),
|
||||
acp::ContentBlock::ResourceLink(resource_link) => {
|
||||
if let Some(path) = resource_link.uri.strip_prefix("file://") {
|
||||
format!("{}", MentionPath(path.as_ref()))
|
||||
acp::ContentBlock::Resource(acp::EmbeddedResource {
|
||||
resource:
|
||||
acp::EmbeddedResourceResource::TextResourceContents(acp::TextResourceContents {
|
||||
uri,
|
||||
..
|
||||
}),
|
||||
..
|
||||
}) => {
|
||||
if let Some(uri) = MentionUri::parse(&uri).log_err() {
|
||||
uri.to_link()
|
||||
} else {
|
||||
resource_link.uri.clone()
|
||||
uri.clone()
|
||||
}
|
||||
}
|
||||
acp::ContentBlock::Image(_)
|
||||
| acp::ContentBlock::Audio(_)
|
||||
| acp::ContentBlock::Resource(_) => String::new(),
|
||||
| acp::ContentBlock::Resource(acp::EmbeddedResource { .. })
|
||||
| acp::ContentBlock::ResourceLink(_) => String::new(),
|
||||
};
|
||||
|
||||
match self {
|
||||
|
@ -1329,7 +1302,7 @@ mod tests {
|
|||
use serde_json::json;
|
||||
use settings::SettingsStore;
|
||||
use smol::stream::StreamExt as _;
|
||||
use std::{cell::RefCell, rc::Rc, time::Duration};
|
||||
use std::{cell::RefCell, path::Path, rc::Rc, time::Duration};
|
||||
|
||||
use util::path;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue