-
Notifications
You must be signed in to change notification settings - Fork 130
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 Nightly rust-analyzer RUST_SRC_PATH Wrapper #238
Comments
For what it's worth, this issues also happens when I switch back to the stable channel and use I've so far been unsuccessful getting this to work by setting |
You may have already tried this, but in that case this is for anybody else who comes across this issue. I think the previous behavior of the wrapper can be emulated by putting something like this in your shell.nix file:
(Note the trailing part after It's hard to test because like you my std completions are still not working, but this does get rid of the error from rust-analyzer about correctly setting RUST_SRC_PATH, so presumably that part worked? |
I've also been trying to figure this out. I don't see the RUST_SRC_PATH error (maybe getting swallowed) but setting it as above doesn't fix the lack of autocomplete. |
Gives I tried a few different variations on that path, but I was never able to get autocomplete working. |
Ah, I think the difference might be that I'm using rust stable, so for me the path is
I still can't get autocomplete working though, but I think my autocomplete problems are larger than this because autocomplete does not work for me in general. Currently, This might be unrelated to nixpkgs-mozilla entirely. It definitely appeared the moment I started using the rust-analyzer from nixpkgs-mozilla, but it might just be down to a version change in rust-analyzer or something else. |
It might not be nixpkgs-mozilla, but I can confirm that I've got autocomplete working through lsp-mode in Python, it's just rust-analyzer and rls that are broken. I'll eventually try doing an isolated test with rustup, too, but I'd much prefer to stay in Nix. Autocomplete also works fine for other crates, just not |
I've been grappling with this, too as I didn't turn up this Issue in my searches until now. ETA: Everything is there, but RA isn't picking it up. Feels like a |
I think the problem is the use of symlinks in the nix store. After spending too much time on this, I was able to make Hypothesis: possibly the issue is that |
Do you think this is a reasonable ticket to send over to |
It looks like this isn't the only place I think it's worth adding! |
It seems that as of 1.47 going stable, the correct |
@dfoxfranke did you try the suggestion in my comment above? I’ve been using that with working completions. |
@acowley would be nice if you could share your overlay, I also resorted to just using rustup because it's simpler :) |
@TLATER Here's part of a chan-specs = { date = "2020-09-23"; channel = "nightly"; };
ra-wrapper = self: super: {
rust-analyzerw = pkgs-host.runCommandNoCC "rust-analyzer-1999" {
pname = "rust-analyzer";
version = "1999";
nativeBuildInputs = [ pkgs-host.makeWrapper ];
} ''
mkdir -p $out/bin
cp -rL ${(super.rustChannelOf chan-specs).rust-src}/lib/rustlib/src/rust/library $out
makeWrapper ${(super.rustChannelOf chan-specs).rust-analyzer-preview}/bin/rust-analyzer $out/bin/r
ust-analyzerw --set RUST_SRC_PATH "$out/library"
'';
};
pkgs = import sources.nixpkgs {
overlays = [ moz_overlay rust-src-overlay ra-wrapper ];
}; I did this so I could add |
I haven't tested the fix yet, but I think I've identified the bug in RA. See rust-lang/rust-analyzer#3691 (comment). |
rust-lang/rust-analyzer#6246 fixes the symlink problem for me. It remains necessary either to overlay shellHook = ''
export RUST_SRC_PATH="${rustChannel.rust-src}/lib/rustlib/src/rust/library"
''; in the derivation for my VSCode environment. But this much seems like expected behavior to me, not a bug. |
@dfoxfranke Thanks a ton! What's the nicest way to use a version of rust-analyzer with that fix from within the overlay? When I run |
@deifactor I checked out and built https://github.com/rust-analyzer/rust-analyzer and then changed the symlink Make sure you build with |
Aah, I was hoping for a more Nix-y solution. I can just copy acowley's trick until this makes its way in. |
A simpler solution if you are content with rust stable is to just use the version of rust-analyzer from nixpkgs like so: mkShell {
buildInputs = [
rust-analyzer # the one from Mozilla is slightly broken https://github.com/mozilla/nixpkgs-mozilla/issues/238
(moz_nixpkgs.latest.rustChannels.stable.rust.override {
# extensions = ["rust-src"]; # unneeded because we're using rust-analyzer from nixpkgs
})
];
} It's crucial that rust-analyzer appears before rust, because the order of Then completions and goto-def etc. all seem to work for me (technically you might get out of sync, but I think rust-analyzer from nixpkgs is supposed to track rust stable so it's probably close enough):
|
# The packages available usually are:
# cargo, rust-analysis, rust-docs, rust-src, rust-std, rustc, and
# rust, which aggregates them in one package. That doesnt seem to be true anymore. Li is unable to find rust-src in the |
has anything changed for this issue? I'd love to be able to use rust-analyzer from nixpkgs-mozilla |
@drozdziak1, there isn't much point in using a nix-store rust-src; being read-only, it breaks analyzer. |
@maisiliym Breaks it how? It's been working fine for me. |
I've stumbled across this issue because I've been having issues with rust-analyzer in Nixos. @dfoxfranke it's broken because rust-analyzer tries to create Cargo.lock, but cannot inside of /nix/store:
That said, this thread has helped me to get it working. I needed to set in my export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src" which sets it to |
I previously used Rust's stable channel along with
rust-analyzer
fromnixpkgs
. This provided a wrapper aroundrust-analyzer
which setRUST_SRC_PATH
.I've recently switched to
rustChannels.nightly.rust
which provides and conflicts withrust-analyzer
. This version, however, doesn't haveRUST_SRC_PATH
set in a wrapper which seems to break most completions in lsp-mode.I believe I can just set
RUST_SRC_PATH
myself to fix this, though it seems to me that this overlay should be updated to wraprust-analyzer
in the same way thenixpkgs
derivation wrapped it.The text was updated successfully, but these errors were encountered: