Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 24 additions & 3 deletions crates/agent_servers/src/acp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use futures::io::BufReader;
use project::Project;
use project::agent_server_store::AgentServerCommand;
use serde::Deserialize;
use settings::Settings as _;
use task::ShellBuilder;
#[cfg(windows)]
use task::ShellKind;
use util::ResultExt as _;

use std::path::PathBuf;
Expand All @@ -21,7 +25,7 @@ use gpui::{App, AppContext as _, AsyncApp, Entity, SharedString, Task, WeakEntit

use acp_thread::{AcpThread, AuthRequired, LoadError, TerminalProviderEvent};
use terminal::TerminalBuilder;
use terminal::terminal_settings::{AlternateScroll, CursorShape};
use terminal::terminal_settings::{AlternateScroll, CursorShape, TerminalSettings};

#[derive(Debug, Error)]
#[error("Unsupported version")]
Expand Down Expand Up @@ -89,9 +93,26 @@ impl AcpConnection {
is_remote: bool,
cx: &mut AsyncApp,
) -> Result<Self> {
let mut child = util::command::new_smol_command(&command.path);
let shell = cx.update(|cx| TerminalSettings::get(None, cx).shell.clone())?;
let builder = ShellBuilder::new(&shell, cfg!(windows));
#[cfg(windows)]
let kind = builder.kind();
let (cmd, args) = builder.build(Some(command.path.display().to_string()), &command.args);

let mut child = util::command::new_smol_command(cmd);
#[cfg(windows)]
if kind == ShellKind::Cmd {
use smol::process::windows::CommandExt;
for arg in args {
child.raw_arg(arg);
}
} else {
child.args(args);
}
#[cfg(not(windows))]
child.args(args);

child
.args(command.args.iter().map(|arg| arg.as_str()))
.envs(command.env.iter().flatten())
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
Expand Down
1 change: 0 additions & 1 deletion crates/agent_servers/src/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ impl crate::AgentServer for CustomAgentServer {
let default_model = self.default_model(cx);
let store = delegate.store.downgrade();
let extra_env = load_proxy_env(cx);

cx.spawn(async move |cx| {
let (command, root_dir, login) = store
.update(cx, |store, cx| {
Expand Down
1 change: 1 addition & 0 deletions crates/context_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ smol.workspace = true
tempfile.workspace = true
url = { workspace = true, features = ["serde"] }
util.workspace = true
terminal.workspace = true

[dev-dependencies]
gpui = { workspace = true, features = ["test-support"] }
12 changes: 10 additions & 2 deletions crates/context_server/src/transport/stdio_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ use futures::{
AsyncBufReadExt as _, AsyncRead, AsyncWrite, AsyncWriteExt as _, Stream, StreamExt as _,
};
use gpui::AsyncApp;
use settings::Settings as _;
use smol::channel;
use smol::process::Child;
use terminal::terminal_settings::TerminalSettings;
use util::TryFutureExt as _;
use util::shell_builder::ShellBuilder;

use crate::client::ModelContextServerBinary;
use crate::transport::Transport;
Expand All @@ -28,9 +31,14 @@ impl StdioTransport {
working_directory: &Option<PathBuf>,
cx: &AsyncApp,
) -> Result<Self> {
let mut command = util::command::new_smol_command(&binary.executable);
let shell = cx.update(|cx| TerminalSettings::get(None, cx).shell.clone())?;
let builder = ShellBuilder::new(&shell, cfg!(windows));
let (command, args) =
builder.build(Some(binary.executable.display().to_string()), &binary.args);

let mut command = util::command::new_smol_command(command);
command
.args(&binary.args)
.args(args)
.envs(binary.env.unwrap_or_default())
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
Expand Down
2 changes: 1 addition & 1 deletion crates/languages/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ impl ToolchainLister for PythonToolchainProvider {
ShellKind::Fish => Some(format!("\"{pyenv}\" shell - fish {version}")),
ShellKind::Posix => Some(format!("\"{pyenv}\" shell - sh {version}")),
ShellKind::Nushell => Some(format!("^\"{pyenv}\" shell - nu {version}")),
ShellKind::PowerShell => None,
ShellKind::PowerShell | ShellKind::Pwsh => None,
ShellKind::Csh => None,
ShellKind::Tcsh => None,
ShellKind::Cmd => None,
Expand Down
2 changes: 1 addition & 1 deletion crates/project/src/context_server_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ impl ContextServerStore {
) {
self.stop_server(&id, cx).log_err();
}

let task = cx.spawn({
let id = server.id();
let server = server.clone();
let configuration = configuration.clone();

async move |this, cx| {
match server.clone().start(cx).await {
Ok(_) => {
Expand Down
15 changes: 13 additions & 2 deletions crates/remote/src/transport/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use tempfile::TempDir;
use util::{
paths::{PathStyle, RemotePathBuf},
rel_path::RelPath,
shell::ShellKind,
shell::{Shell, ShellKind},
shell_builder::ShellBuilder,
};

pub(crate) struct SshRemoteConnection {
Expand Down Expand Up @@ -1377,6 +1378,8 @@ fn build_command(
} else {
write!(exec, "{ssh_shell} -l")?;
};
let (command, command_args) = ShellBuilder::new(&Shell::Program(ssh_shell.to_owned()), false)
.build(Some(exec.clone()), &[]);

let mut args = Vec::new();
args.extend(ssh_args);
Expand All @@ -1387,7 +1390,9 @@ fn build_command(
}

args.push("-t".into());
args.push(exec);
args.push(command);
args.extend(command_args);

Ok(CommandTemplate {
program: "ssh".into(),
args,
Expand Down Expand Up @@ -1426,6 +1431,9 @@ mod tests {
"-p",
"2222",
"-t",
"/bin/fish",
"-i",
"-c",
"cd \"$HOME/work\" && exec env INPUT_VA=val remote_program arg1 arg2"
]
);
Expand Down Expand Up @@ -1458,6 +1466,9 @@ mod tests {
"-L",
"1:foo:2",
"-t",
"/bin/fish",
"-i",
"-c",
"cd && exec env INPUT_VA=val /bin/fish -l"
]
);
Expand Down
16 changes: 8 additions & 8 deletions crates/remote/src/transport/wsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use std::{
use util::{
paths::{PathStyle, RemotePathBuf},
rel_path::RelPath,
shell::ShellKind,
shell::{Shell, ShellKind},
shell_builder::ShellBuilder,
};

#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Deserialize, schemars::JsonSchema)]
Expand Down Expand Up @@ -433,8 +434,10 @@ impl RemoteConnection for WslRemoteConnection {
} else {
write!(&mut exec, "{} -l", self.shell)?;
}
let (command, args) =
ShellBuilder::new(&Shell::Program(self.shell.clone()), false).build(Some(exec), &[]);

let wsl_args = if let Some(user) = &self.connection_options.user {
let mut wsl_args = if let Some(user) = &self.connection_options.user {
vec![
"--distribution".to_string(),
self.connection_options.distro_name.clone(),
Expand All @@ -443,9 +446,7 @@ impl RemoteConnection for WslRemoteConnection {
"--cd".to_string(),
working_dir,
"--".to_string(),
self.shell.clone(),
"-c".to_string(),
exec,
command,
]
} else {
vec![
Expand All @@ -454,11 +455,10 @@ impl RemoteConnection for WslRemoteConnection {
"--cd".to_string(),
working_dir,
"--".to_string(),
self.shell.clone(),
"-c".to_string(),
exec,
command,
]
};
wsl_args.extend(args);

Ok(CommandTemplate {
program: "wsl.exe".to_string(),
Expand Down
Loading