zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
50.85k stars 3.15k forks source link

rust-analyzer fails to load workspaces when using fish-shell #18771

Open jspngh opened 1 month ago

jspngh commented 1 month ago

Check for existing issues

Describe the bug / provide steps to reproduce it

On recent Zed releases, rust-analyzer stopped working for me on macOS.

I've tried 0.152.4, and there the issue is not present. I believe it is related to the new environment loading from #17717 (or adjacent changes).

This happens only when using fish as a login shell (no issue when switching to zsh). This does not happen when launching from the cli. This does not happen on Linux (with an up-to-date Zed version and also using fish).

As you can see in my logs, the character [?2004l appears, which is related to bracketed-paste mode in fish.

13888 might be related, however that issue seems to be fixed after 0.153.x, and this issue starts at that version.

Apparently if you set the FISH_UNIT_TESTS_RUNNING, bracketed-paste mode is not active in fish. After setting it using launchctl setenv FISH_UNIT_TESTS_RUNNING 1, rust-analyzer starts correctly.

My guess: now that a login shell is spawned to determine the environment variables, it doesn't interact correctly with what fish does (printing those [?2004l characters to enable bracketed-paste mode). I think this is part of the fish prompt, which gets added as additional command (for a good reason presumably).

Environment

Zed: v0.155.2 (Zed) OS: macOS 15.0.0 Memory: 36 GiB Architecture: aarch64 Fish: 3.7.1

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log

2024-10-06T08:16:08.729056+02:00 [INFO] ========== starting zed ==========
2024-10-06T08:16:08.732795+02:00 [INFO] Opening main db
2024-10-06T08:16:08.734907+02:00 [INFO] Opening main db
2024-10-06T08:16:08.749771+02:00 [INFO] Using git binary path: Some("/Applications/Zed.app/Contents/MacOS/git")
2024-10-06T08:16:08.778106+02:00 [INFO] set environment variables from shell:/opt/homebrew/bin/fish, path:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/jonas/.cargo/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Applications/VMware Fusion.app/Contents/Public
2024-10-06T08:16:08.863912+02:00 [INFO] initializing context server client
2024-10-06T08:16:08.864206+02:00 [INFO] Registering built-in prompt template: content_prompt
2024-10-06T08:16:08.864588+02:00 [INFO] Registering built-in prompt template: edit_workflow
2024-10-06T08:16:08.864735+02:00 [INFO] Registering built-in prompt template: project_slash_command
2024-10-06T08:16:08.864792+02:00 [INFO] Registering built-in prompt template: step_resolution
2024-10-06T08:16:08.865032+02:00 [INFO] Registering built-in prompt template: terminal_assistant_prompt
2024-10-06T08:16:08.865172+02:00 [INFO] No prompt template overrides directory found at /Users/jonas/.config/zed/prompt_overrides. Using built-in prompts.
2024-10-06T08:16:08.866206+02:00 [INFO] extensions updated. loading 1, reloading 0, unloading 0
2024-10-06T08:16:08.904847+02:00 [WARN] request completed with error: failed to connect to the server
2024-10-06T08:16:08.905843+02:00 [INFO] Opening main db
2024-10-06T08:16:08.905913+02:00 [WARN] request completed with error: failed to connect to the server
2024-10-06T08:16:08.910852+02:00 [INFO] building git repository, `.git` path in the worktree: ".git"
2024-10-06T08:16:08.939053+02:00 [INFO] Opening main db
2024-10-06T08:16:08.940258+02:00 [INFO] Opening main db
2024-10-06T08:16:08.940748+02:00 [INFO] set status on client 0: Authenticating
2024-10-06T08:16:08.943483+02:00 [INFO] set status on client 113263: Connecting
2024-10-06T08:16:08.947711+02:00 [WARN] request completed with error: failed to connect to the server
2024-10-06T08:16:09.021693+02:00 [INFO] attempting to start language server "rust-analyzer", path: "/Users/jonas/some/project", id: 1
2024-10-06T08:16:09.021781+02:00 [INFO] Initializing default prettier with plugins {}
2024-10-06T08:16:09.022511+02:00 [INFO] Initializing default prettier with plugins {}
2024-10-06T08:16:09.022648+02:00 [INFO] Initializing default prettier with plugins {}
2024-10-06T08:16:09.033175+02:00 [INFO] found rust-analyzer in PATH. trying to run `rust-analyzer --help`
2024-10-06T08:16:09.034252+02:00 [WARN] request completed with error: failed to connect to the server
2024-10-06T08:16:09.036362+02:00 [INFO] found user-installed language server for rust-analyzer. path: "/opt/homebrew/bin/rust-analyzer", arguments: []
2024-10-06T08:16:09.036462+02:00 [INFO] starting language server process. binary path: "/opt/homebrew/bin/rust-analyzer", working directory: "/Users/jonas/some/project", args: []
2024-10-06T08:16:09.075398+02:00 [ERROR] Language server rust-analyzer (id 1) status update: Failed to load workspaces.
2024-10-06T08:16:09.083956+02:00 [ERROR] Language server rust-analyzer (id 1) status update: Failed to load workspaces.
rust-analyzer.log
stderr: 2024-10-06T06:21:17.477594Z  INFO Using sysroot workspace=/Users/jonas/some/project/Cargo.toml src_root=None root=None
stderr: 2024-10-06T06:21:17.482699Z  INFO did fetch workspaces workspaces=[Err(Failed to load the project at /Users/jonas/some/project/Cargo.toml
stderr:
stderr: Caused by:
stderr: 0: Failed to query rust toolchain version at /Users/jonas/some/project, is your toolchain setup correctly?
stderr: 1: cd "/Users/jonas/some/project" && "/Users/jonas/.cargo/bin/cargo" "--version" failed, exit status: 1
stderr: stderr:
stderr: error: could not create home directory: '/Users/jonas
stderr: [?2004l/.rustup': Permission denied (os error 13)
stderr:
stderr:
stderr: Stack backtrace:
stderr: 0: std::backtrace::Backtrace::create
stderr: 1: anyhow::error::::msg
stderr: 2: project_model::utf8_stdout
stderr: 3: project_model::workspace::get_toolchain_version
stderr: 4: project_model::workspace::ProjectWorkspace::load
stderr: 5:  as core::iter::traits::iterator::Iterator>::fold
stderr: 6:  as alloc::vec::spec_from_iter::SpecFromIter>::from_iter
stderr: 7: core::ops::function::FnOnce::call_once{{vtable.shim}}
stderr: 8: std::sys::backtrace::__rust_begin_short_backtrace
stderr: 9: core::ops::function::FnOnce::call_once{{vtable.shim}}
stderr: 10: std::sys::pal::unix::thread::Thread::new::thread_start
stderr: 11: __pthread_deallocate)]
stderr: 2024-10-06T06:21:17.486702Z ERROR GlobalState::handle_event{event=Event::Task}:GlobalState::handle_event/task: FetchWorkspaceError: rust-analyzer failed to load workspace: Failed to load the project at /Users/jonas/some/project/Cargo.toml: Failed to query rust toolchain version at /Users/jonas/some/project, is your toolchain setup correctly?: cd "/Users/jonas/some/project" && "/Users/jonas/.cargo/bin/cargo" "--version" failed, exit status: 1
stderr: stderr:
stderr: error: could not create home directory: '/Users/jonas
stderr: [?2004l/.rustup': Permission denied (os error 13)
jspngh commented 1 month ago

Everything works fine again in v0.156.2, but I didn't investigate further on what code change fixed the issue. I'll close this, since it seems I was the only one experiencing this problem.

icoigo commented 4 weeks ago

Everything works fine again in v0.156.2, but I didn't investigate further on what code change fixed the issue. I'll close this, since it seems I was the only one experiencing this problem.

wow, it seems this issue happens to me as well. I just post a reply for this issue #14904 And after running this launchctl setenv FISH_UNIT_TESTS_RUNNING 1, it works again.

Zed version: 0.159.6

defnotjonas commented 1 week ago

The issue also exists for me. The fix by @icoigo still works.

Zed version: 0.162.4

jspngh commented 1 week ago

This popped up again recently for me as well, but I switched to zsh as to not have to deal with it. I'll re-open the issue, since more people are experiencing it. Please give it a thumbs-up for visibility to the zed team.

Also, setting FISH_UNIT_TESTS_RUNNING to 1 is a good way to check if your issue has the same root cause, but shouldn't be considered a fix :smile: