rust-lang / rust-lang/rust-analyzer
Autocomplete should sort core::Result::Ok(()) before importing an Ok function from a library.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
I regularly use anyhow / color_eyre in projects, typing Ok in visual studio pops up a autocomplete that contains methods that are named Ok in addition to the Result::Ok enum variant from the prelude. The latter should be the first completion. I regularly tab complete this only to produce failing code as the method is not the correct type for the return type.
Preferentially, this seems like a value that doesn't require any imports should sort higher than any value that does.
If that's not possible, then items from the rust prelude should generally sort higher.
If that's not possible, then there should be some special cased items that sort higher like this.
Repro:
cargo new
cargo add anyhow
in a function like:
fn foo() -> std::io::Result<()> {
ok$0
}
Expected:
Ok(...)
Ok(...) (use anyhow::Ok)
Happy to implement. Just point me in the approximate direction.
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
Reproduce the completion ordering with cargo new, cargo add anyhow, and the shown std::io::Result<()> function, then trace rust-analyzer's autocomplete ranking entry point. Done means the prelude Result::Ok completion appears before the imported anyhow::Ok completion in this example, with coverage for the ordering behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100