acp: Fix MessageEditor::set_message
for sent messages (#36715)
The `PromptCapabilities` introduced in previous PRs were only getting set on the main message editor and not for the editors in user messages. This caused a bug where mentions would disappear after resending the message, and for the completion provider to be limited to files. Release Notes: - N/A
This commit is contained in:
parent
3d80be6267
commit
14a50e2b23
3 changed files with 35 additions and 24 deletions
|
@ -87,6 +87,7 @@ impl MessageEditor {
|
|||
project: Entity<Project>,
|
||||
history_store: Entity<HistoryStore>,
|
||||
prompt_store: Option<Entity<PromptStore>>,
|
||||
prompt_capabilities: Rc<Cell<acp::PromptCapabilities>>,
|
||||
placeholder: impl Into<Arc<str>>,
|
||||
prevent_slash_commands: bool,
|
||||
mode: EditorMode,
|
||||
|
@ -100,7 +101,6 @@ impl MessageEditor {
|
|||
},
|
||||
None,
|
||||
);
|
||||
let prompt_capabilities = Rc::new(Cell::new(acp::PromptCapabilities::default()));
|
||||
let completion_provider = ContextPickerCompletionProvider::new(
|
||||
cx.weak_entity(),
|
||||
workspace.clone(),
|
||||
|
@ -203,10 +203,6 @@ impl MessageEditor {
|
|||
.detach();
|
||||
}
|
||||
|
||||
pub fn set_prompt_capabilities(&mut self, capabilities: acp::PromptCapabilities) {
|
||||
self.prompt_capabilities.set(capabilities);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn editor(&self) -> &Entity<Editor> {
|
||||
&self.editor
|
||||
|
@ -1095,15 +1091,21 @@ impl MessageEditor {
|
|||
mentions.push((start..end, mention_uri, resource.text));
|
||||
}
|
||||
}
|
||||
acp::ContentBlock::ResourceLink(resource) => {
|
||||
if let Some(mention_uri) = MentionUri::parse(&resource.uri).log_err() {
|
||||
let start = text.len();
|
||||
write!(&mut text, "{}", mention_uri.as_link()).ok();
|
||||
let end = text.len();
|
||||
mentions.push((start..end, mention_uri, resource.uri));
|
||||
}
|
||||
}
|
||||
acp::ContentBlock::Image(content) => {
|
||||
let start = text.len();
|
||||
text.push_str("image");
|
||||
let end = text.len();
|
||||
images.push((start..end, content));
|
||||
}
|
||||
acp::ContentBlock::Audio(_)
|
||||
| acp::ContentBlock::Resource(_)
|
||||
| acp::ContentBlock::ResourceLink(_) => {}
|
||||
acp::ContentBlock::Audio(_) | acp::ContentBlock::Resource(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1850,7 +1852,7 @@ impl Addon for MessageEditorAddon {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{ops::Range, path::Path, sync::Arc};
|
||||
use std::{cell::Cell, ops::Range, path::Path, rc::Rc, sync::Arc};
|
||||
|
||||
use acp_thread::MentionUri;
|
||||
use agent_client_protocol as acp;
|
||||
|
@ -1896,6 +1898,7 @@ mod tests {
|
|||
project.clone(),
|
||||
history_store.clone(),
|
||||
None,
|
||||
Default::default(),
|
||||
"Test",
|
||||
false,
|
||||
EditorMode::AutoHeight {
|
||||
|
@ -2086,6 +2089,7 @@ mod tests {
|
|||
|
||||
let context_store = cx.new(|cx| ContextStore::fake(project.clone(), cx));
|
||||
let history_store = cx.new(|cx| HistoryStore::new(context_store, cx));
|
||||
let prompt_capabilities = Rc::new(Cell::new(acp::PromptCapabilities::default()));
|
||||
|
||||
let (message_editor, editor) = workspace.update_in(&mut cx, |workspace, window, cx| {
|
||||
let workspace_handle = cx.weak_entity();
|
||||
|
@ -2095,6 +2099,7 @@ mod tests {
|
|||
project.clone(),
|
||||
history_store.clone(),
|
||||
None,
|
||||
prompt_capabilities.clone(),
|
||||
"Test",
|
||||
false,
|
||||
EditorMode::AutoHeight {
|
||||
|
@ -2139,13 +2144,10 @@ mod tests {
|
|||
editor.set_text("", window, cx);
|
||||
});
|
||||
|
||||
message_editor.update(&mut cx, |editor, _cx| {
|
||||
// Enable all prompt capabilities
|
||||
editor.set_prompt_capabilities(acp::PromptCapabilities {
|
||||
image: true,
|
||||
audio: true,
|
||||
embedded_context: true,
|
||||
});
|
||||
prompt_capabilities.set(acp::PromptCapabilities {
|
||||
image: true,
|
||||
audio: true,
|
||||
embedded_context: true,
|
||||
});
|
||||
|
||||
cx.simulate_input("Lorem ");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue