rust-lang / rust-lang/rust-analyzer
Expanded discovery command support for Cargo projects
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Hello!
In Hubris, we currently do rust-analyzer integration with a rather horrible Neovim hack, involving a stack of Lua that does ✨magic✨ and calls out to an xtask subcommand, which produces a blob of JSON that we send off to rust-analyzer on init.
This is sort of unfortunate; our ability to conditionally run code in Neovim based on the path to the file being edited is unusual, and doesn't work in environments like vscode.
@davidbarsky had mentioned that rust-analyzer had support for a discovery command for environments like Blaze and Buck. If there were a way of specifying this at the workspace level for a Cargo project, we could potentially use this in Hubris.
I would like to implement this, but I will need a bit of tutoring on how to get started. @davidbarsky had offered to point me in the right direction, so, here I am.
Background
Our build is complex, for Embedded Reasons:
- A workspace contains many firmware images, covering many boards, and many revisions of the same board.
- Each image consists of several Cargo-built standalone executables plus a Cargo-built kernel.
- Because Cargo features are not powerful enough to describe most interesting embedded use cases, we drive Cargo with a wrapper that sets a lot of environment variables and stuff.
- A single Cargo bin package in the workspace may be built different ways for many different images, and may be built multiple times for a single image (e.g. building a generic driver for several instances of a peripheral).
Our existing cargo xtask lsp command takes a path to a source file and guesses which of these environments it should be built in. (You can also override it using an environment variable, which is gross, but is the only practical way we can funnel "arguments" through the editor to the LSP.)
Editors do not currently know to run our custom LSP command, unless they've been hacked like Neovim. So what we sort of need is a "back-channel" method for communicating, from the Cargo workspace to rust-analyzer, that it is being invoked within a Hubris project and should run a particular command line to discover the correct configuration. Note that this command line will involve Cargo (to potentially build the discovery program).
While it would be neat to also implement things like building code in all environments and somehow distinguishing between them in completions etc., that seems a lot harder, so for now we're happy to continue "guessing" the right environment and taking overrides where required through the environment.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing rust-analyzer’s existing discovery-command support for environments such as Blaze and Buck, then investigate how a Cargo workspace could specify an equivalent command. The work is done when rust-analyzer can discover the correct Hubris configuration from that workspace-level setting without the Neovim-specific Lua hack.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100