zed icon indicating copy to clipboard operation
zed copied to clipboard

[nixos] rust analyzer doesn't seem to be here

Open makoConstruct opened this issue 1 year ago • 4 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

Rust analyzer is totally silent. Go to definition doesn't work. Errors aren't flagged, ctrl+t is empty. No errors are being communicated (← this is the part that's easiest to fix) in project diagnostics or anything I can see.

Oddly, project symbols is still populated.

Environment

Zed: v0.149.3 (Zed) OS: Linux X11 nixos 23.11 Memory: 15.5 GiB Architecture: x86_64 GPU: NVIDIA GeForce RTX 3060 || NVIDIA || 545.29.02

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

makoConstruct avatar Aug 22 '24 21:08 makoConstruct

https://wiki.nixos.org/wiki/Zed

ribelo avatar Aug 22 '24 22:08 ribelo

@makoConstruct Did the config described at wiki.nixos.org/wiki/Zed work for you?

Here, we'll assume rust-analyzer is globally installed in your system profile at /run/current-system/sw/bin/rust-analyzer. You may want to adapt this path in the following code snippet to something more relevant to your use case.

Add the following snippet to your zed configuration file:

 "lsp": {
   "rust-analyzer": {
     "binary": {
       "path": "/run/current-system/sw/bin/rust-analyzer",
     },
   }
 }

notpeter avatar Aug 23 '24 13:08 notpeter

@notpeter I wasn't able to find rust-analyzer anywhere, no.

Should it be added as a dependency?

Rust stuff often isn't added as a dependency on nixos because people like to manage it through rustup, but it sounds like the rustup version of rust-analyzer isn't kept up to date so rust-analyzer should possibly be treated differently?

makoConstruct avatar Aug 23 '24 18:08 makoConstruct

@makoConstruct

On NixOS it's generally best to install rust-analyzer and Rust using the rust-overlay from https://github.com/oxalica/rust-overlay. This approach provides more flexibility and ensures you can keep everything up-to-date.

Here's an example of how you could set it up in your configuration:

(rust-bin.selectLatestNightlyWith
  (toolchain: toolchain.default.override {
    extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" "rustc" ];
    targets = [ "wasm32-unknown-unknown" "x86_64-unknown-linux-gnu" "x86_64-unknown-linux-musl" ];
  }))

This setup allows you to select the latest nightly build and customize it with specific extensions and targets. It includes rust-analyzer, which ensures you're getting the most up-to-date version directly integrated with your Rust toolchain.

ribelo avatar Aug 24 '24 13:08 ribelo

Thanks for this @ribelo. NixOS is different enough from other environments that it might be worth creating some dedicated documentation. Similarly Zed should probably try and do less on NixOS (bail with an error rather than trying and failing).

Perhaps once this is merged:

  • https://github.com/zed-industries/zed/pull/14034

It might make sense to set this as a default in NixOS builds.

@makoConstruct If @ribelo's instructions weren't enough to get a working environment going, please comment and I'm happy to reopen.

notpeter avatar Aug 28 '24 16:08 notpeter

@ribelo @notpeter

the instructions were appreciated. I ended up adjusting my unstable packages to:

(with (import inputs.nixpkgs-unstable {
  inherit system;
  config.allowUnfree = true;
  overlays = [ inputs.rust-overlay.overlays.default ];
}); [
  (rust-bin.selectLatestNightlyWith
    (toolchain: toolchain.default.override {
      extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" "rustc" ];
      targets = [ "wasm32-unknown-unknown" "x86_64-unknown-linux-gnu" ];
    }))
    
    zed-editor
    # ... [the rest of my unstable packages]
])

rust-analyzer and everything is all in PATH. Zed is now v0.149.6

However, rust-analyzer still isn't being found by zed.

2024-08-31T17:32:00.271029424+12:00 [INFO] found user-installed language server for Rust. path: "/run/current-system/sw/bin/rust-analyzer", arguments: []
2024-08-31T17:32:00.271061288+12:00 [INFO] starting language server. binary path: "/run/current-system/sw/bin/rust-analyzer", working directory: "/home/mako/programming/web/about/gen", args: []
2024-08-31T17:32:00.271961863+12:00 [ERROR] failed to start language server "rust-analyzer": failed to spawn command. path: "/run/current-system/sw/bin/rust-analyzer", working directory: "/home/mako/programming/web/about/gen", args: []

It's very strange that it says found user-installed language server for Rust. path: "/run/current-system/sw/bin/rust-analyzer" given that this file isn't actually there. I'm not sure where rust-analyzer is.

On zed's ui, there used to be a repeated failed attempt to download rust, iirc? That's no longer showing. There's now no indication on the surface that anything is wrong aside from the missing features.

makoConstruct avatar Aug 31 '24 05:08 makoConstruct

@ribelo where do you put that in your configuration? I put mine in my home-manager packages. If you're putting it in environment.systemPackages it's conceivable to me that this would make a difference.

makoConstruct avatar Sep 01 '24 21:09 makoConstruct

@ribelo @makoConstruct Can you post your configuration, so that we know how exactly you made it work : )

k3yss avatar Sep 02 '24 16:09 k3yss

I don't think there's any information there that wasn't in my comment, but sure: https://gist.github.com/makoConstruct/c1511025c8360a4cf0ab6021e4c52b5f

makoConstruct avatar Sep 02 '24 23:09 makoConstruct