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.05k stars 3.06k forks source link

rust lsp bug: code greyed out & 'file not included in crate hierarchy' #12847

Closed extrawurst closed 5 months ago

extrawurst commented 5 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Closed source, so i cannot share a simple reproduction. I just know the same project structure works fine in vscode with rust-analyzer. zed since today suddenly stoped working.

Environment

Zed: v0.139.3 (Zed Preview) OS: macOS 14.5.0 Memory: 64 GiB Architecture: aarch64

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

Screenshot 2024-06-10 at 16 22 26

I expect to see normal syntax highlighting and code completion

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

[....]
2024-06-10T16:11:17+02:00 [INFO] starting language servers for Rust: rust-analyzer
2024-06-10T16:11:17+02:00 [INFO] starting language server "rust-analyzer", path: "/Users/stephan/code/rustunit/tinytakeoff", id: 5
2024-06-10T16:11:17+02:00 [ERROR] crates/project/src/project.rs:7312: oneshot canceled
2024-06-10T16:11:17+02:00 [ERROR] crates/project/src/project.rs:7312: oneshot canceled
2024-06-10T16:11:17+02:00 [ERROR] crates/editor/src/editor.rs:4443: oneshot canceled
2024-06-10T16:11:17+02:00 [ERROR] crates/project/src/project.rs:7312: oneshot canceled
2024-06-10T16:11:17+02:00 [ERROR] crates/editor/src/editor.rs:4443: oneshot canceled
2024-06-10T16:11:17+02:00 [INFO] starting language server. binary path: "/Users/stephan/Library/Application Support/Zed/languages/rust-analyzer/rust-analyzer-2024-06-10", working directory: "/Users/stephan/code/rustunit/tinytakeoff", args: []
2024-06-10T16:11:17+02:00 [ERROR] inlay hint update task for range Anchor { timestamp: Lamport {0: 0}, offset: 0, bias: Left, buffer_id: None }..Anchor { timestamp: Lamport {0: 1}, offset: 350, bias: Right, buffer_id: Some(BufferId(167503724711)) } failed: inlay hint fetch task: inlay hints LSP request: oneshot canceled
2024-06-10T16:11:17+02:00 [ERROR] inlay hint update task for range Anchor { timestamp: Lamport {0: 0}, offset: 0, bias: Left, buffer_id: None }..Anchor { timestamp: Lamport {0: 1}, offset: 394, bias: Right, buffer_id: Some(BufferId(4294967375)) } failed: inlay hint fetch task: inlay hints LSP request: oneshot canceled
2024-06-10T16:11:43+02:00 [INFO] Initializing default prettier with plugins {}
2024-06-10T16:11:43+02:00 [INFO] starting language servers for Rust: rust-analyzer
2024-06-10T16:11:44+02:00 [INFO] Initializing default prettier with plugins {}
2024-06-10T16:11:44+02:00 [INFO] starting language servers for TOML: taplo
2024-06-10T16:22:38+02:00 [ERROR] Cancelled LSP request task for "textDocument/inlayHint" id 19 which took over 120s
2024-06-10T16:22:38+02:00 [WARN] Generic lsp request to rust-analyzer failed: LSP request timeout
2024-06-10T16:22:38+02:00 [ERROR] Cancelled LSP request task for "textDocument/codeAction" id 21 which took over 120s
2024-06-10T16:22:38+02:00 [WARN] Generic lsp request to rust-analyzer failed: LSP request timeout
2024-06-10T16:22:38+02:00 [ERROR] crates/project/src/project.rs:7312: LSP request timeout
2024-06-10T16:22:38+02:00 [ERROR] inlay hint update task for range Anchor { timestamp: Lamport {0: 1}, offset: 492, bias: Left, buffer_id: Some(BufferId(4294967374)) }..Anchor { timestamp: Lamport {0: 1}, offset: 983, bias: Right, buffer_id: Some(BufferId(4294967374)) } failed: inlay hint fetch task: inlay hints LSP request: LSP request timeout
extrawurst commented 5 months ago

ok no it also does the same now in vscode when using the release of today, maybe due to https://github.com/rust-lang/rust-analyzer/issues/17378. downgrading RA in vscode from v0.3.1992 to v0.3.1983 is a workaround. how can I pick the RA version in ZED?

lnicola commented 5 months ago

Do you have a mod api declaration in the parent module?

extrawurst commented 5 months ago

this applies to every file in my project and yes of course this module is actually in the hierarchy, this module did not change and as stated above it must be related to the RA version v0.3.1992 (which I assume zed updated to today for me) because it also fails in vscode with that and going back to RA v0.3.1983 brings back everything as expected in vscode.

so its clearly a problem in RA.

still I would love to know how to forcefully set/downgrade the RA version in zed as in this state zed is basically bricked for me

lnicola commented 5 months ago

This was caused by https://github.com/rust-lang/rust-analyzer/pull/17350. But it doesn't make RA emit a new warning, it just makes the span bigger, because the warning wasn't noticeable enough. Please make sure that there aren't any missing module declarations on the path to api, and file a RA issue if you're sure it's a bug.

You can delete most files from your projects and most code from the remaining files. It doesn't need to build or run.

extrawurst commented 5 months ago

Please make sure that there aren't any missing module declarations on the path to api, and file a RA issue if you're sure it's a bug.

can you specify what you mean? the files are work and are actually in the build when I use cargo.

i suspected maybe the fact that I have this workspace structure where I have a main.rs and a lib.rs to maybe now breaking RA, so I tested against bevy_game_template this version which was used as a template for my project here.

and indeed it breaks RA and triggers this: https://github.com/rust-lang/rust-analyzer/issues/17376

I find the same error in the lang server logs in zed. strangely though the same does not happen in my project causing the issues here

mrnugget commented 5 months ago

I'm also running into this as of today. It goes away once rust-analyzer has fully loaded the repository. Seems like an upstream change.

still I would love to know how to forcefully set/downgrade the RA version in zed as in this state zed is basically bricked for me

You can configure the binary manually in your Zed settings.json:

{
  "lsp": {
    "rust-analyzer": {
      "binary": {
        "path": "/Users/thorstenball/tmp/rust-analyzer-aarch64-apple-darwin" // <-- must be absolute path
      }
    }
  }
}
lnicola commented 5 months ago

@extrawurst see also https://github.com/rust-lang/rust-analyzer/issues/17386.

extrawurst commented 5 months ago

yeah and that one is caused by: https://github.com/rust-lang/rust-analyzer/issues/17378

extrawurst commented 5 months ago

I can report that zed with the new rust-analyzer release 0.3.1995 works again for me. see https://github.com/rust-lang/rust-analyzer/issues/17378#issuecomment-2160044690.

will close this one