Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust-analyzer: Failed to load workspaces. #21762

Open
1 task done
feelingsonice opened this issue Dec 9, 2024 · 6 comments
Open
1 task done

rust-analyzer: Failed to load workspaces. #21762

feelingsonice opened this issue Dec 9, 2024 · 6 comments
Labels
admin read Pending admin review bug [core label] language server failure Language server doesn't work as expected rust Rust programming language support

Comments

@feelingsonice
Copy link

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

The rust-analyzer provided by from my PATH always fails to run. Yet when I run it manually via the command line it works fine.

Zed then default to its own rust-analyzer but this behavior isn't ideal.

Screenshot 2024-12-09 at 12 11 35 PM

Environment

Zed: v0.164.2 (Zed)
OS: macOS 15.1.1
Memory: 96 GiB
Architecture: aarch64

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

Running which rust-analyzer gives:/Users/<USER>/.cargo/bin/rust-analyzer

Running a command like rust-analyzer --version gives rust-analyzer 1.83.0 (90b35a62 2024-11-26).

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

Zed.log
2024-12-09T12:08:23.690352-08:00 [INFO] attempting to start language server "rust-analyzer", path: "/Users/<USER>/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs", id: 10
2024-12-09T12:08:23.690931-08:00 [INFO] found rust-analyzer in PATH. trying to run `rust-analyzer --help`
2024-12-09T12:08:23.691346-08:00 [ERROR] failed to run rust-analyzer after detecting it in PATH: binary: "/Users/<USER>/.cargo/bin/rust-analyzer": No such file or directory (os error 2)
2024-12-09T12:08:23.69272-08:00 [INFO] fetching latest version of language server "rust-analyzer"
2024-12-09T12:08:24.717056-08:00 [INFO] downloading language server "rust-analyzer"
2024-12-09T12:08:27.961329-08:00 [INFO] starting language server process. binary path: "/Users/<USER>/Library/Application Support/Zed/languages/rust-analyzer/rust-analyzer-2024-12-09", working directory: "/Users/bli/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src", args: []
2024-12-09T12:08:28.923515-08:00 [ERROR] Language server rust-analyzer (id 10) status update: Failed to load workspaces.
2024-12-09T12:08:28.923732-08:00 [ERROR] Language server rust-analyzer (id 10) status update: Failed to load workspaces.
@feelingsonice feelingsonice added admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue labels Dec 9, 2024
@jansol
Copy link
Contributor

jansol commented Dec 10, 2024

Does the problem disappear if you run rustup update && rustup component add rust-analyzer in your project directory before launching zed? I've seen some recent-ish weirdness related to how rustup handles toolchain switching.

@jansol jansol added rust Rust programming language support language server failure Language server doesn't work as expected and removed triage Maintainer needs to classify the issue labels Dec 10, 2024
@feelingsonice
Copy link
Author

Does the problem disappear if you run rustup update && rustup component add rust-analyzer in your project directory before launching zed? I've seen some recent-ish weirdness related to how rustup handles toolchain switching.

I do that regularly, like once or twice every week.

I should also add that this problem seems random. I don't see it happening all the time and it will just randomly pop up as I'm editing my files. Sometimes restarting the LSP or zed makes it go away.

@feelingsonice
Copy link
Author

@jansol this is still happening and very annoying. Any updates?

@jansol
Copy link
Contributor

jansol commented Dec 18, 2024

I don't have much time for my Rust projects, but I took a quick look just now and did not encounter the error. Then again I have a somewhat convoluted setup for rust-analyzer in an effort to pick up dependencies via nix:

"rust-analyzer": {
      "binary": {
        "path": "/run/current-system/sw/bin/bash",
        "arguments": [
          "-c",
          "if [ -e flake.nix ]; then nix develop --command rust-analyzer; else rust-analyzer; fi"
        ]
      }
    }

It seems to also be fine if I leave out the logic and just make bash invoke rust-analyzer directly.

@feelingsonice
Copy link
Author

I have a weird setup ass well 🤷

    "rust-analyzer": {
      "initialization_options": {
        "cargo": {
          "allFeatures": true,
          "buildScripts": {
            "rebuildOnSave": true
          }
        },
        "procMacro": {
          "enable": true
        },
        "checkOnSave": {
          "command": "clippy" // rust-analyzer.checkOnSave.command
        },
        "hover": {
          "references": {
            "enabled": true
          }
        },
        "imports": {
          "prefix": "crate",
          "preferPrelude": true,
          "granularity": {
            "enforce": true
          }
        },
        "inlayHints": {
          "bindingModeHints": {
            "enable": true
          },
          "closingBraceHints": {
            "minLines": 0
          },
          "closureCaptureHints": {
            "enable": true
          },
          "maxLength": null,
          "lifetimeElisionHints": {
            "useParameterNames": true,
            "enable": "skip_trivial"
          },
          "closureReturnTypeHints": {
            "enable": "always"
          }
        }
      }
    }

@s3bba
Copy link
Contributor

s3bba commented Dec 26, 2024

I'm experiencing the same issue on Arch, rust-anayzer is installed by pacman. Here is the error I get:
[2024-12-26T16:49:11+01:00 ERROR languages::rust] failed to run rust-analyzer after detecting it in PATH: binary: "/usr/bin/rust-analyzer": Not a directory (os error 20)

And it's solved by the same solution mentioned in comments above of specifying binary location manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admin read Pending admin review bug [core label] language server failure Language server doesn't work as expected rust Rust programming language support
Projects
None yet
Development

No branches or pull requests

3 participants