zed: Use CLI env for lang servers, tasks, terminal (#17075)
This changes the Zed CLI `zed` to pass along the environment to the Zed project that it opens (if it opens a new one). In projects, this CLI environment will now take precedence over any environment that's acquired by running a login shell in a projects folder. The result is that `zed my/folder` now always behaves as if one would run `zed --foreground` without any previous Zed version running. Closes #7894 Closes #16293 Related issues: - It fixes the issue described in here: https://github.com/zed-industries/zed/issues/4977#issuecomment-2305272027 Release Notes: - Improved the Zed CLI `zed` to pass along the environment as it was on the CLI to the opened Zed project. That environment is then used when opening new terminals, spawning tasks, or language servers. Specifically: - If Zed was started via `zed my-folder`, a terminal spawned with `workspace: new terminal` will inherit these environment variables that existed on the CLI - Specific language servers that allow looking up the language server binary in the environments `$PATH` (such as `gopls`, `zls`, `rust-analyzer` if configured, ...) will look up the language server binary in the CLI environment too and use that environment when starting the process. - Language servers that are _not_ found in the CLI environment (or configured to not be found in there), will be spawned with the CLI environment in case that's set. That means users can do something like `RA_LOG=info zed .` and it will be picked up the rust-analyzer that was spawned. Demo/explanation: https://github.com/user-attachments/assets/455905cc-8b7c-4fc4-b98a-7e027d97cdfa
This commit is contained in:
parent
4f408ec65a
commit
fc4c533d0a
19 changed files with 484 additions and 227 deletions
|
@ -1061,6 +1061,7 @@ impl Workspace {
|
|||
abs_paths: Vec<PathBuf>,
|
||||
app_state: Arc<AppState>,
|
||||
requesting_window: Option<WindowHandle<Workspace>>,
|
||||
env: Option<HashMap<String, String>>,
|
||||
cx: &mut AppContext,
|
||||
) -> Task<
|
||||
anyhow::Result<(
|
||||
|
@ -1074,6 +1075,7 @@ impl Workspace {
|
|||
app_state.user_store.clone(),
|
||||
app_state.languages.clone(),
|
||||
app_state.fs.clone(),
|
||||
env,
|
||||
cx,
|
||||
);
|
||||
|
||||
|
@ -1579,7 +1581,8 @@ impl Workspace {
|
|||
if self.project.read(cx).is_local_or_ssh() {
|
||||
Task::Ready(Some(Ok(callback(self, cx))))
|
||||
} else {
|
||||
let task = Self::new_local(Vec::new(), self.app_state.clone(), None, cx);
|
||||
let env = self.project.read(cx).cli_environment(cx);
|
||||
let task = Self::new_local(Vec::new(), self.app_state.clone(), None, env, cx);
|
||||
cx.spawn(|_vh, mut cx| async move {
|
||||
let (workspace, _) = task.await?;
|
||||
workspace.update(&mut cx, callback)
|
||||
|
@ -5205,7 +5208,7 @@ pub fn join_channel(
|
|||
// no open workspaces, make one to show the error in (blergh)
|
||||
let (window_handle, _) = cx
|
||||
.update(|cx| {
|
||||
Workspace::new_local(vec![], app_state.clone(), requesting_window, cx)
|
||||
Workspace::new_local(vec![], app_state.clone(), requesting_window, None, cx)
|
||||
})?
|
||||
.await?;
|
||||
|
||||
|
@ -5263,7 +5266,7 @@ pub async fn get_any_active_workspace(
|
|||
// find an existing workspace to focus and show call controls
|
||||
let active_window = activate_any_workspace_window(&mut cx);
|
||||
if active_window.is_none() {
|
||||
cx.update(|cx| Workspace::new_local(vec![], app_state.clone(), None, cx))?
|
||||
cx.update(|cx| Workspace::new_local(vec![], app_state.clone(), None, None, cx))?
|
||||
.await?;
|
||||
}
|
||||
activate_any_workspace_window(&mut cx).context("could not open zed")
|
||||
|
@ -5308,6 +5311,7 @@ pub fn local_workspace_windows(cx: &AppContext) -> Vec<WindowHandle<Workspace>>
|
|||
pub struct OpenOptions {
|
||||
pub open_new_workspace: Option<bool>,
|
||||
pub replace_window: Option<WindowHandle<Workspace>>,
|
||||
pub env: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
|
@ -5385,6 +5389,7 @@ pub fn open_paths(
|
|||
abs_paths,
|
||||
app_state.clone(),
|
||||
open_options.replace_window,
|
||||
open_options.env,
|
||||
cx,
|
||||
)
|
||||
})?
|
||||
|
@ -5394,11 +5399,12 @@ pub fn open_paths(
|
|||
}
|
||||
|
||||
pub fn open_new(
|
||||
open_options: OpenOptions,
|
||||
app_state: Arc<AppState>,
|
||||
cx: &mut AppContext,
|
||||
init: impl FnOnce(&mut Workspace, &mut ViewContext<Workspace>) + 'static + Send,
|
||||
) -> Task<anyhow::Result<()>> {
|
||||
let task = Workspace::new_local(Vec::new(), app_state, None, cx);
|
||||
let task = Workspace::new_local(Vec::new(), app_state, None, open_options.env, cx);
|
||||
cx.spawn(|mut cx| async move {
|
||||
let (workspace, opened_paths) = task.await?;
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue