Skip to content

Commit bbf0218

Browse files
author
Cole Miller
committed
wip
1 parent d19b6aa commit bbf0218

File tree

7 files changed

+56
-19
lines changed

7 files changed

+56
-19
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/project/src/project.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub use environment::ProjectEnvironment;
6666
#[cfg(test)]
6767
use futures::future::join_all;
6868
use futures::{
69-
StreamExt,
69+
FutureExt as _, StreamExt,
7070
channel::mpsc::{self, UnboundedReceiver},
7171
future::{Shared, try_join_all},
7272
};
@@ -1894,12 +1894,32 @@ impl Project {
18941894
})
18951895
}
18961896

1897+
// FIXME migrate project environment stuff to use proto instead of bailing when not local
1898+
18971899
pub fn directory_environment(
18981900
&self,
18991901
shell: &Shell,
19001902
abs_path: Arc<Path>,
19011903
cx: &mut App,
19021904
) -> Shared<Task<Option<HashMap<String, String>>>> {
1905+
if let Some(remote_client) = self.remote_client() {
1906+
let response =
1907+
remote_client
1908+
.read(cx)
1909+
.proto_client()
1910+
.request(proto::GetDirectoryEnvironment {
1911+
// FIXME
1912+
project_id: REMOTE_SERVER_PROJECT_ID,
1913+
shell: Some(shell.clone().to_proto()),
1914+
directory: abs_path.to_string_lossy().to_string(),
1915+
});
1916+
return cx
1917+
.spawn(async move |_| {
1918+
let environment = response.await.log_err()?;
1919+
Some(environment.environment.into_iter().collect())
1920+
})
1921+
.shared();
1922+
}
19031923
self.environment.update(cx, |environment, cx| {
19041924
environment.get_directory_environment_for_shell(shell, abs_path, cx)
19051925
})
@@ -4963,21 +4983,6 @@ impl Project {
49634983
Project::respond_to_open_buffer_request(this, buffer, peer_id, &mut cx)
49644984
}
49654985

4966-
async fn handle_get_directory_environment(
4967-
this: Entity<Self>,
4968-
envelope: TypedEnvelope<proto::GetDirectoryEnvironment>,
4969-
mut cx: AsyncApp,
4970-
) -> Result<proto::DirectoryEnvironment> {
4971-
let shell = Shell::from_proto(envelope.payload.shell.context("missing shell")?)?;
4972-
let directory = PathBuf::from(envelope.payload.directory);
4973-
let environment = this
4974-
.update(&mut cx, |this, cx| {
4975-
this.directory_environment(shell, directory.into(), cx)
4976-
})?
4977-
.await?;
4978-
Ok(proto::DirectoryEnvironment { environment })
4979-
}
4980-
49814986
fn respond_to_open_buffer_request(
49824987
this: Entity<Self>,
49834988
buffer: Entity<Buffer>,

crates/proto/proto/task.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ message GetDirectoryEnvironment {
5656
}
5757

5858
message DirectoryEnvironment {
59-
map<string, string> env = 1;
59+
map<string, string> environment = 1;
6060
}

crates/proto/proto/zed.proto

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,10 @@ message Envelope {
418418

419419
GitRenameBranch git_rename_branch = 380;
420420

421-
RemoteStarted remote_started = 381; // current max
421+
RemoteStarted remote_started = 381;
422+
423+
GetDirectoryEnvironment get_directory_environment = 382;
424+
DirectoryEnvironment directory_environment = 383; // current max
422425
}
423426

424427
reserved 87 to 88;

crates/proto/src/proto.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ messages!(
319319
(GitClone, Background),
320320
(GitCloneResponse, Background),
321321
(ToggleLspLogs, Background),
322+
(GetDirectoryEnvironment, Background),
323+
(DirectoryEnvironment, Background),
322324
(GetAgentServerCommand, Background),
323325
(AgentServerCommand, Background),
324326
(ExternalAgentsUpdated, Background),
@@ -497,6 +499,7 @@ request_messages!(
497499
(GetDefaultBranch, GetDefaultBranchResponse),
498500
(GitClone, GitCloneResponse),
499501
(ToggleLspLogs, Ack),
502+
(GetDirectoryEnvironment, DirectoryEnvironment),
500503
(GetProcesses, GetProcessesResponse),
501504
(GetAgentServerCommand, AgentServerCommand),
502505
(RemoteStarted, Ack),
@@ -634,6 +637,7 @@ entity_messages!(
634637
GitCheckoutFiles,
635638
SetIndexText,
636639
ToggleLspLogs,
640+
GetDirectoryEnvironment,
637641

638642
Push,
639643
Fetch,

crates/remote_server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ settings.workspace = true
6060
shellexpand.workspace = true
6161
smol.workspace = true
6262
sysinfo.workspace = true
63+
task.workspace = true
6364
util.workspace = true
6465
watch.workspace = true
6566
worktree.workspace = true

crates/remote_server/src/headless_project.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub struct HeadlessProject {
5050
pub languages: Arc<LanguageRegistry>,
5151
pub extensions: Entity<HeadlessExtensionStore>,
5252
pub git_store: Entity<GitStore>,
53+
pub environment: Entity<ProjectEnvironment>,
5354
// Used mostly to keep alive the toolchain store for RPC handlers.
5455
// Local variant is used within LSP store, but that's a separate entity.
5556
pub _toolchain_store: Entity<ToolchainStore>,
@@ -196,7 +197,7 @@ impl HeadlessProject {
196197

197198
let agent_server_store = cx.new(|cx| {
198199
let mut agent_server_store =
199-
AgentServerStore::local(node_runtime.clone(), fs.clone(), environment, cx);
200+
AgentServerStore::local(node_runtime.clone(), fs.clone(), environment.clone(), cx);
200201
agent_server_store.shared(REMOTE_SERVER_PROJECT_ID, session.clone(), cx);
201202
agent_server_store
202203
});
@@ -249,6 +250,7 @@ impl HeadlessProject {
249250
session.add_entity_request_handler(Self::handle_open_new_buffer);
250251
session.add_entity_request_handler(Self::handle_find_search_candidates);
251252
session.add_entity_request_handler(Self::handle_open_server_settings);
253+
session.add_entity_request_handler(Self::handle_get_directory_environment);
252254
session.add_entity_message_handler(Self::handle_toggle_lsp_logs);
253255

254256
session.add_entity_request_handler(BufferStore::handle_update_buffer);
@@ -289,6 +291,7 @@ impl HeadlessProject {
289291
languages,
290292
extensions,
291293
git_store,
294+
environment,
292295
_toolchain_store: toolchain_store,
293296
}
294297
}
@@ -758,6 +761,26 @@ impl HeadlessProject {
758761

759762
Ok(proto::GetProcessesResponse { processes })
760763
}
764+
765+
async fn handle_get_directory_environment(
766+
this: Entity<Self>,
767+
envelope: TypedEnvelope<proto::GetDirectoryEnvironment>,
768+
mut cx: AsyncApp,
769+
) -> Result<proto::DirectoryEnvironment> {
770+
let shell = task::Shell::from_proto(envelope.payload.shell.context("missing shell")?)?;
771+
let directory = PathBuf::from(envelope.payload.directory);
772+
let environment = this
773+
.update(&mut cx, |this, cx| {
774+
this.environment.update(cx, |environment, cx| {
775+
environment.get_directory_environment_for_shell(&shell, directory.into(), cx)
776+
})
777+
})?
778+
.await
779+
.context("failed to get directory environment")?
780+
.into_iter()
781+
.collect();
782+
Ok(proto::DirectoryEnvironment { environment })
783+
}
761784
}
762785

763786
fn prompt_to_proto(

0 commit comments

Comments
 (0)