environments: Don't load shell environments in non-local worktrees (#23138)

Thorsten Ball created

This fixes an error message that has shown up for me when joining collab
projects: "Unable to load shell environment in /<path on another
machine/"

Release Notes:

- Fixed error message about shell environment failing to load when
joining projects in collaboration.

Change summary

crates/project/src/environment.rs | 12 ++++++++++++
1 file changed, 12 insertions(+)

Detailed changes

crates/project/src/environment.rs 🔗

@@ -13,6 +13,7 @@ use crate::{
 };
 
 pub struct ProjectEnvironment {
+    worktree_store: Model<WorktreeStore>,
     cli_environment: Option<HashMap<String, String>>,
     environments: HashMap<WorktreeId, Shared<Task<Option<HashMap<String, String>>>>>,
     environment_error_messages: HashMap<WorktreeId, EnvironmentErrorMessage>,
@@ -33,6 +34,7 @@ impl ProjectEnvironment {
             .detach();
 
             Self {
+                worktree_store: worktree_store.clone(),
                 cli_environment,
                 environments: Default::default(),
                 environment_error_messages: Default::default(),
@@ -102,6 +104,16 @@ impl ProjectEnvironment {
             return Task::ready(None).shared();
         };
 
+        if self
+            .worktree_store
+            .read(cx)
+            .worktree_for_id(worktree_id, cx)
+            .map(|w| !w.read(cx).is_local())
+            .unwrap_or(true)
+        {
+            return Task::ready(None).shared();
+        }
+
         if let Some(task) = self.environments.get(&worktree_id) {
             task.clone()
         } else {