context_server: Change command string field to PathBuf (#34873)

Release Notes:

- N/A
This commit is contained in:
Ben Brandt 2025-07-22 12:12:07 +02:00 committed by GitHub
parent 87014cec71
commit 3a651c546b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 22 additions and 23 deletions

View file

@ -1,4 +1,5 @@
use std::{ use std::{
path::PathBuf,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
time::Duration, time::Duration,
}; };
@ -188,7 +189,7 @@ fn context_server_input(existing: Option<(ContextServerId, ContextServerCommand)
} }
None => ( None => (
"some-mcp-server".to_string(), "some-mcp-server".to_string(),
"".to_string(), PathBuf::new(),
"[]".to_string(), "[]".to_string(),
"{}".to_string(), "{}".to_string(),
), ),
@ -199,13 +200,14 @@ fn context_server_input(existing: Option<(ContextServerId, ContextServerCommand)
/// The name of your MCP server /// The name of your MCP server
"{name}": {{ "{name}": {{
/// The command which runs the MCP server /// The command which runs the MCP server
"command": "{command}", "command": "{}",
/// The arguments to pass to the MCP server /// The arguments to pass to the MCP server
"args": {args}, "args": {args},
/// The environment variables to set /// The environment variables to set
"env": {env} "env": {env}
}} }}
}}"# }}"#,
command.display()
) )
} }

View file

@ -6,9 +6,9 @@ pub mod test;
pub mod transport; pub mod transport;
pub mod types; pub mod types;
use std::fmt::Display;
use std::path::Path; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use std::{fmt::Display, path::PathBuf};
use anyhow::Result; use anyhow::Result;
use client::Client; use client::Client;
@ -31,7 +31,7 @@ impl Display for ContextServerId {
#[derive(Deserialize, Serialize, Clone, PartialEq, Eq, JsonSchema)] #[derive(Deserialize, Serialize, Clone, PartialEq, Eq, JsonSchema)]
pub struct ContextServerCommand { pub struct ContextServerCommand {
#[serde(rename = "command")] #[serde(rename = "command")]
pub path: String, pub path: PathBuf,
pub args: Vec<String>, pub args: Vec<String>,
pub env: Option<HashMap<String, String>>, pub env: Option<HashMap<String, String>>,
} }

View file

@ -3,7 +3,7 @@ mod dap;
mod lsp; mod lsp;
mod slash_command; mod slash_command;
use std::ops::Range; use std::{ops::Range, path::PathBuf};
use util::redact::should_redact; use util::redact::should_redact;
@ -18,7 +18,7 @@ pub type EnvVars = Vec<(String, String)>;
/// A command. /// A command.
pub struct Command { pub struct Command {
/// The command to execute. /// The command to execute.
pub command: String, pub command: PathBuf,
/// The arguments to pass to the command. /// The arguments to pass to the command.
pub args: Vec<String>, pub args: Vec<String>,
/// The environment variables to set for the command. /// The environment variables to set for the command.

View file

@ -75,7 +75,7 @@ impl From<Range> for std::ops::Range<usize> {
impl From<Command> for extension::Command { impl From<Command> for extension::Command {
fn from(value: Command) -> Self { fn from(value: Command) -> Self {
Self { Self {
command: value.command, command: value.command.into(),
args: value.args, args: value.args,
env: value.env, env: value.env,
} }
@ -958,7 +958,7 @@ impl ExtensionImports for WasmState {
command, command,
} => Ok(serde_json::to_string(&settings::ContextServerSettings { } => Ok(serde_json::to_string(&settings::ContextServerSettings {
command: Some(settings::CommandSettings { command: Some(settings::CommandSettings {
path: Some(command.path), path: command.path.to_str().map(|path| path.to_string()),
arguments: Some(command.args), arguments: Some(command.args),
env: command.env.map(|env| env.into_iter().collect()), env: command.env.map(|env| env.into_iter().collect()),
}), }),

View file

@ -610,7 +610,7 @@ mod tests {
use context_server::test::create_fake_transport; use context_server::test::create_fake_transport;
use gpui::{AppContext, TestAppContext, UpdateGlobal as _}; use gpui::{AppContext, TestAppContext, UpdateGlobal as _};
use serde_json::json; use serde_json::json;
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, path::PathBuf, rc::Rc};
use util::path; use util::path;
#[gpui::test] #[gpui::test]
@ -931,7 +931,7 @@ mod tests {
ContextServerSettings::Custom { ContextServerSettings::Custom {
enabled: true, enabled: true,
command: ContextServerCommand { command: ContextServerCommand {
path: "somebinary".to_string(), path: "somebinary".into(),
args: vec!["arg".to_string()], args: vec!["arg".to_string()],
env: None, env: None,
}, },
@ -971,7 +971,7 @@ mod tests {
ContextServerSettings::Custom { ContextServerSettings::Custom {
enabled: true, enabled: true,
command: ContextServerCommand { command: ContextServerCommand {
path: "somebinary".to_string(), path: "somebinary".into(),
args: vec!["anotherArg".to_string()], args: vec!["anotherArg".to_string()],
env: None, env: None,
}, },
@ -1053,7 +1053,7 @@ mod tests {
ContextServerSettings::Custom { ContextServerSettings::Custom {
enabled: true, enabled: true,
command: ContextServerCommand { command: ContextServerCommand {
path: "somebinary".to_string(), path: "somebinary".into(),
args: vec!["arg".to_string()], args: vec!["arg".to_string()],
env: None, env: None,
}, },
@ -1104,7 +1104,7 @@ mod tests {
ContextServerSettings::Custom { ContextServerSettings::Custom {
enabled: false, enabled: false,
command: ContextServerCommand { command: ContextServerCommand {
path: "somebinary".to_string(), path: "somebinary".into(),
args: vec!["arg".to_string()], args: vec!["arg".to_string()],
env: None, env: None,
}, },
@ -1132,7 +1132,7 @@ mod tests {
ContextServerSettings::Custom { ContextServerSettings::Custom {
enabled: true, enabled: true,
command: ContextServerCommand { command: ContextServerCommand {
path: "somebinary".to_string(), path: "somebinary".into(),
args: vec!["arg".to_string()], args: vec!["arg".to_string()],
env: None, env: None,
}, },
@ -1184,7 +1184,7 @@ mod tests {
ContextServerSettings::Custom { ContextServerSettings::Custom {
enabled: true, enabled: true,
command: ContextServerCommand { command: ContextServerCommand {
path: "somebinary".to_string(), path: "somebinary".into(),
args: vec!["arg".to_string()], args: vec!["arg".to_string()],
env: None, env: None,
}, },
@ -1256,11 +1256,11 @@ mod tests {
} }
struct FakeContextServerDescriptor { struct FakeContextServerDescriptor {
path: String, path: PathBuf,
} }
impl FakeContextServerDescriptor { impl FakeContextServerDescriptor {
fn new(path: impl Into<String>) -> Self { fn new(path: impl Into<PathBuf>) -> Self {
Self { path: path.into() } Self { path: path.into() }
} }
} }

View file

@ -61,10 +61,7 @@ impl registry::ContextServerDescriptor for ContextServerDescriptor {
let mut command = extension let mut command = extension
.context_server_command(id.clone(), extension_project.clone()) .context_server_command(id.clone(), extension_project.clone())
.await?; .await?;
command.command = extension command.command = extension.path_from_extension(&command.command);
.path_from_extension(command.command.as_ref())
.to_string_lossy()
.to_string();
log::info!("loaded command for context server {id}: {command:?}"); log::info!("loaded command for context server {id}: {command:?}");

View file

@ -581,7 +581,7 @@ impl Settings for ProjectSettings {
#[derive(Deserialize)] #[derive(Deserialize)]
struct VsCodeContextServerCommand { struct VsCodeContextServerCommand {
command: String, command: PathBuf,
args: Option<Vec<String>>, args: Option<Vec<String>>,
env: Option<HashMap<String, String>>, env: Option<HashMap<String, String>>,
// note: we don't support envFile and type // note: we don't support envFile and type