Put context servers behind a trait (#20432)

This PR puts context servers behind the `ContextServer` trait to allow
us to provide context servers from an extension.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-11-08 13:36:41 -05:00 committed by GitHub
parent 01503511ad
commit 09c599385a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 102 additions and 61 deletions

View file

@ -20,18 +20,18 @@ use crate::slash_command::create_label_for_command;
pub struct ContextServerSlashCommand {
server_manager: Model<ContextServerManager>,
server_id: String,
server_id: Arc<str>,
prompt: Prompt,
}
impl ContextServerSlashCommand {
pub fn new(
server_manager: Model<ContextServerManager>,
server: &Arc<ContextServer>,
server: &Arc<dyn ContextServer>,
prompt: Prompt,
) -> Self {
Self {
server_id: server.id.clone(),
server_id: server.id(),
prompt,
server_manager,
}
@ -89,7 +89,7 @@ impl SlashCommand for ContextServerSlashCommand {
if let Some(server) = self.server_manager.read(cx).get_server(&server_id) {
cx.foreground_executor().spawn(async move {
let Some(protocol) = server.client.read().clone() else {
let Some(protocol) = server.client() else {
return Err(anyhow!("Context server not initialized"));
};
@ -143,7 +143,7 @@ impl SlashCommand for ContextServerSlashCommand {
let manager = self.server_manager.read(cx);
if let Some(server) = manager.get_server(&server_id) {
cx.foreground_executor().spawn(async move {
let Some(protocol) = server.client.read().clone() else {
let Some(protocol) = server.client() else {
return Err(anyhow!("Context server not initialized"));
};
let result = protocol.run_prompt(&prompt_name, prompt_args).await?;