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

Use stable toolchain for rust-analyzer on xtensa targets #69

Merged
merged 4 commits into from
Jan 14, 2025

Conversation

lasernoises
Copy link
Contributor

It seems that rust-analyzer doesn't support custom toolchains, but the documentation suggests adding an override such that rust-analzer runs on the stable toolchain: https://rust-analyzer.github.io/manual.html#toolchain.

@bjoernQ
Copy link
Collaborator

bjoernQ commented Dec 30, 2024

Apparently the difference this setting makes is using the proc-macro-server from the stable toolchain instead of the one from the esp toolchain.

The esp toolchain is usually released when a new stable toolchain is released (sometimes it takes us a few days) - not sure if this makes a difference then

Do you have an example for when using the esp toolchain is worse than using stable?

@lasernoises
Copy link
Contributor Author

Sorry, I should have added more detail when opening this.

rust-analyzer doesn't seem to work at all on the esp toolchain.

In helix I get the following in the log:

2024-12-30T17:53:50.846 helix_lsp::transport [ERROR] rust-analyzer err <- "error: 'rust-analyzer' is not installed for the custom toolchain 'esp'.\n"
2024-12-30T17:53:50.846 helix_lsp::transport [ERROR] rust-analyzer err <- "note: this is a custom toolchain, which cannot use `rustup component add`\n"
2024-12-30T17:53:50.846 helix_lsp::transport [ERROR] rust-analyzer err <- "help: if you built this toolchain from source, and used `rustup toolchain link`, then you may be able to build the component with `x.py`\n"
2024-12-30T17:53:50.846 helix_lsp::transport [ERROR] rust-analyzer err: <- StreamClosed
2024-12-30T17:53:50.846 helix_lsp [ERROR] failed to initialize language server: server closed the stream

And I can't add it with rustup. rustup component add rust-analyzer gives the following error:

error: toolchain 'esp' does not support components

I found this Reddit thread which suggested overriding the toolchain: https://www.reddit.com/r/rust/comments/13d2tls/rustanalyzer_and_toolchain_for_esp/
And since

In this configuration rust-analyzer doesn't seem to run perfectly. It seems to not show all errors, but hover and go-to-definion and so on seem to work for the most part at least.

But maybe I'm missing something. Someone in the Reddit thread suggested that it works in VSCode because it bundles rust-analyzer, but for me that doesn't seem to be the case (I think using the rust-analyzer builds from the VSCode plugin is optional). So maybe the issue doesn't affect everyone on the esp toolchain.

Someone also suggested symlinking rust-analyzer from stable into the esp toolchain, but I'd be a bit worried about that causing problems with esup update or maybe rustup.

Or is there a different way to get rust-analyzer working on the esp toolchain?

@bjoernQ
Copy link
Collaborator

bjoernQ commented Dec 31, 2024

Thanks for the update!

I'm using VSCode with the RA-plugin installed from the marketplace - there are always some minor problems, but it usually works. Can't say much (or anything) about Helix.

Interestingly rust-analyzer isn't contained in the official toolchains for me, too. (error: Unknown binary 'rust-analyzer.exe' in official toolchain 'stable-x86_64-pc-windows-msvc'.) And we ship rust-analyzer-proc-macro-srv with the esp-toolchain

This doesn't seem to make anything worse so I would be fine with merging this (given it makes RA work for others) - but maybe worth to have this checked by another maintainer first.

@SergioGasquez
Copy link
Member

I also use RA with VS Code, the changes seem to work for me too, although they report several issues regarding missing xtensa targets:
image

@lasernoises
Copy link
Contributor Author

Sorry for the delay. I've been tinkering around a bit more and figured out some improvements.

Adding this to .helix/languages.toml makes the errors show properly in Helix for me:

check.extraEnv.RUSTUP_TOOLCHAIN = "esp"

Doing the same in VSCode config.json also seems to make the "can't find crate for core" errors go away.

But then using go-to-definition for core still sends me to the library source for the stable toolchain. Adding this makes that work:

cargo.extraEnv.RUSTUP_TOOLCHAIN = "esp"

I think because that env is used running rustc --print sysroot in rust-analyzer.

I'll try updating the PR later today or tomorrow.

@lasernoises
Copy link
Contributor Author

Ok, I've made the adjustment. I've also updated the changelog (hope I did that right).

Copy link
Member

@SergioGasquez SergioGasquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for your investigation and improving the RA config!

@SergioGasquez SergioGasquez added this pull request to the merge queue Jan 14, 2025
Merged via the queue into esp-rs:main with commit d9d5081 Jan 14, 2025
10 checks passed
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

Successfully merging this pull request may close these issues.

3 participants