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 does not return LSP suggestions when enabled via nix-direnv #537

Closed
antoineco opened this issue Nov 28, 2024 · 1 comment
Closed

Comments

@antoineco
Copy link

antoineco commented Nov 28, 2024

nix-direnv 3.0.6

I use the following Flake to describe a standard development environment for Rust:

flake.nix

{
  inputs = {
    nixpkgs.url = "nixpkgs/nixos-24.11";
    rust-overlay.url = "https://flakehub.com/f/oxalica/rust-overlay/0.1";
  };

  outputs =
    {
      self,
      nixpkgs,
      rust-overlay,
    }:
    let
      allSystems = [
        "x86_64-linux"
        "aarch64-darwin"
      ];

      forAllSystems =
        f:
        nixpkgs.lib.genAttrs allSystems (
          system:
          f {
            pkgs = import nixpkgs {
              inherit system;
              overlays = [
                rust-overlay.overlays.default
              ];
            };
          }
        );
    in
    {
      devShells = forAllSystems (
        { pkgs }:
        {
          rust =
            with pkgs;
            mkShell {
              name = "rust";
              packages =
                let
                  rust-stable-custom = rust-bin.stable.latest.default.override {
                    extensions = [
                      "rust-analyzer"
                      "rust-src"
                    ];
                  };
                in
                [ rust-stable-custom ];
            };
        }
      );
    };
}

If I use nix develop '.#rust' -c zsh and open my editor (Neovim), the LSP integration with rust-analyzer works flawlessly (diagnostics from clippy, completions, ...). ✅

If I instead create an .envrc with use flake ${HOME}/myflake#rust, code completions do not trigger in rust-analyzer, although the exact same Nix store directory for Rust tools is present in my PATH in both cases. ❌

This can be replicated in any Cargo project, such as the one bootstrapped by cargo init.

Simply illustated:

nix develop
image

nix direnv (no LSP completions)
image

The only noticeable difference from the LSP progress message is that, in the nix-direnv case, progress stops at:

rust-analyzer [Roots Scanned] 15/15

Whereas while using nix develop it continues after that point with:

rust-analyzer [Fetching] metadata
rust-analyzer [Loading proc-macros]
rust-analyzer [Building CrateGraph]
rust-analyzer [Indexing] 22/22 (myproject)

I haven't noticed any issue in any similar setup, using devShells for Go, Nix and Bash mainly.

I intend to investigate further the differences between the two environment (nix develop vs nix-direnv), but wanted to create an issue anyway with the observed symptoms.

@antoineco
Copy link
Author

antoineco commented Nov 29, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant