Skip to content
Draft
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.

4 changes: 3 additions & 1 deletion crates/acp_thread/src/acp_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,7 @@ impl AcpThread {
output_byte_limit: Option<u64>,
cx: &mut Context<Self>,
) -> Task<Result<Entity<Terminal>>> {
dbg!(&command, &args);
let env = match &cwd {
Some(dir) => self.project.update(cx, |project, cx| {
let worktree = project.find_worktree(dir.as_path(), cx);
Expand Down Expand Up @@ -2128,14 +2129,15 @@ impl AcpThread {
let (task_command, task_args) = ShellBuilder::new(&Shell::Program(shell))
.redirect_stdin_to_dev_null()
.build(Some(command.clone()), &args);
dbg!(&task_command, &task_args);
let terminal = project
.update(cx, |project, cx| {
project.create_terminal_task(
task::SpawnInTerminal {
command: Some(task_command),
args: task_args,
cwd: cwd.clone(),
env,
env: dbg!(env),
..Default::default()
},
cx,
Expand Down
22 changes: 21 additions & 1 deletion crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub use environment::ProjectEnvironment;
#[cfg(test)]
use futures::future::join_all;
use futures::{
StreamExt,
FutureExt as _, StreamExt,
channel::mpsc::{self, UnboundedReceiver},
future::{Shared, try_join_all},
};
Expand Down Expand Up @@ -1894,12 +1894,32 @@ impl Project {
})
}

// FIXME migrate project environment stuff to use proto instead of bailing when not local

pub fn directory_environment(
&self,
shell: &Shell,
abs_path: Arc<Path>,
cx: &mut App,
) -> Shared<Task<Option<HashMap<String, String>>>> {
if let Some(remote_client) = self.remote_client() {
let response =
remote_client
.read(cx)
.proto_client()
.request(proto::GetDirectoryEnvironment {
// FIXME
project_id: REMOTE_SERVER_PROJECT_ID,
shell: Some(shell.clone().to_proto()),
directory: abs_path.to_string_lossy().to_string(),
});
return cx
.spawn(async move |_| {
let environment = response.await.log_err()?;
Some(environment.environment.into_iter().collect())
})
.shared();
}
self.environment.update(cx, |environment, cx| {
environment.get_directory_environment_for_shell(shell, abs_path, cx)
})
Expand Down
10 changes: 10 additions & 0 deletions crates/proto/proto/task.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ message SpawnInTerminal {
map<string, string> env = 4;
optional string cwd = 5;
}

message GetDirectoryEnvironment {
uint64 project_id = 1;
Shell shell = 2;
string directory = 3;
}

message DirectoryEnvironment {
map<string, string> environment = 1;
}
5 changes: 4 additions & 1 deletion crates/proto/proto/zed.proto
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ message Envelope {

GitRenameBranch git_rename_branch = 380;

RemoteStarted remote_started = 381; // current max
RemoteStarted remote_started = 381;

GetDirectoryEnvironment get_directory_environment = 382;
DirectoryEnvironment directory_environment = 383; // current max
}

reserved 87 to 88;
Expand Down
4 changes: 4 additions & 0 deletions crates/proto/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ messages!(
(GitClone, Background),
(GitCloneResponse, Background),
(ToggleLspLogs, Background),
(GetDirectoryEnvironment, Background),
(DirectoryEnvironment, Background),
(GetAgentServerCommand, Background),
(AgentServerCommand, Background),
(ExternalAgentsUpdated, Background),
Expand Down Expand Up @@ -497,6 +499,7 @@ request_messages!(
(GetDefaultBranch, GetDefaultBranchResponse),
(GitClone, GitCloneResponse),
(ToggleLspLogs, Ack),
(GetDirectoryEnvironment, DirectoryEnvironment),
(GetProcesses, GetProcessesResponse),
(GetAgentServerCommand, AgentServerCommand),
(RemoteStarted, Ack),
Expand Down Expand Up @@ -634,6 +637,7 @@ entity_messages!(
GitCheckoutFiles,
SetIndexText,
ToggleLspLogs,
GetDirectoryEnvironment,

Push,
Fetch,
Expand Down
1 change: 1 addition & 0 deletions crates/remote_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ settings.workspace = true
shellexpand.workspace = true
smol.workspace = true
sysinfo.workspace = true
task.workspace = true
util.workspace = true
watch.workspace = true
worktree.workspace = true
Expand Down
25 changes: 24 additions & 1 deletion crates/remote_server/src/headless_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct HeadlessProject {
pub languages: Arc<LanguageRegistry>,
pub extensions: Entity<HeadlessExtensionStore>,
pub git_store: Entity<GitStore>,
pub environment: Entity<ProjectEnvironment>,
// Used mostly to keep alive the toolchain store for RPC handlers.
// Local variant is used within LSP store, but that's a separate entity.
pub _toolchain_store: Entity<ToolchainStore>,
Expand Down Expand Up @@ -196,7 +197,7 @@ impl HeadlessProject {

let agent_server_store = cx.new(|cx| {
let mut agent_server_store =
AgentServerStore::local(node_runtime.clone(), fs.clone(), environment, cx);
AgentServerStore::local(node_runtime.clone(), fs.clone(), environment.clone(), cx);
agent_server_store.shared(REMOTE_SERVER_PROJECT_ID, session.clone(), cx);
agent_server_store
});
Expand Down Expand Up @@ -249,6 +250,7 @@ impl HeadlessProject {
session.add_entity_request_handler(Self::handle_open_new_buffer);
session.add_entity_request_handler(Self::handle_find_search_candidates);
session.add_entity_request_handler(Self::handle_open_server_settings);
session.add_entity_request_handler(Self::handle_get_directory_environment);
session.add_entity_message_handler(Self::handle_toggle_lsp_logs);

session.add_entity_request_handler(BufferStore::handle_update_buffer);
Expand Down Expand Up @@ -289,6 +291,7 @@ impl HeadlessProject {
languages,
extensions,
git_store,
environment,
_toolchain_store: toolchain_store,
}
}
Expand Down Expand Up @@ -758,6 +761,26 @@ impl HeadlessProject {

Ok(proto::GetProcessesResponse { processes })
}

async fn handle_get_directory_environment(
this: Entity<Self>,
envelope: TypedEnvelope<proto::GetDirectoryEnvironment>,
mut cx: AsyncApp,
) -> Result<proto::DirectoryEnvironment> {
let shell = task::Shell::from_proto(envelope.payload.shell.context("missing shell")?)?;
let directory = PathBuf::from(envelope.payload.directory);
let environment = this
.update(&mut cx, |this, cx| {
this.environment.update(cx, |environment, cx| {
environment.get_directory_environment_for_shell(&shell, directory.into(), cx)
})
})?
.await
.context("failed to get directory environment")?
.into_iter()
.collect();
Ok(proto::DirectoryEnvironment { environment })
}
}

fn prompt_to_proto(
Expand Down
33 changes: 33 additions & 0 deletions crates/task/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod task_template;
mod vscode_debug_format;
mod vscode_format;

use anyhow::Context as _;
use collections::{HashMap, HashSet, hash_map};
use gpui::SharedString;
use schemars::JsonSchema;
Expand Down Expand Up @@ -361,6 +362,38 @@ impl Shell {
Shell::System => ShellKind::system(),
}
}

pub fn from_proto(proto: proto::Shell) -> anyhow::Result<Self> {
let shell_type = proto.shell_type.context("invalid shell type")?;
let shell = match shell_type {
proto::shell::ShellType::System(_) => Self::System,
proto::shell::ShellType::Program(program) => Self::Program(program),
proto::shell::ShellType::WithArguments(program) => Self::WithArguments {
program: program.program,
args: program.args,
title_override: None,
},
};
Ok(shell)
}

pub fn to_proto(self) -> proto::Shell {
let shell_type = match self {
Shell::System => proto::shell::ShellType::System(proto::System {}),
Shell::Program(program) => proto::shell::ShellType::Program(program),
Shell::WithArguments {
program,
args,
title_override: _,
} => proto::shell::ShellType::WithArguments(proto::shell::WithArguments {
program,
args,
}),
};
proto::Shell {
shell_type: Some(shell_type),
}
}
}

type VsCodeEnvVariable = String;
Expand Down
1 change: 1 addition & 0 deletions crates/util/src/shell_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub async fn capture(
args: &[String],
directory: impl AsRef<Path>,
) -> Result<collections::HashMap<String, String>> {
dbg!(shell_path.as_ref(), &args, directory.as_ref());
#[cfg(windows)]
return capture_windows(shell_path.as_ref(), args, directory.as_ref()).await;
#[cfg(unix)]
Expand Down
Loading