rust-lang / rust-lang/rust-analyzer

Autocomplete should sort core::Result::Ok(()) before importing an Ok function from a library.

Open
#17,652 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-completion C-feature
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.

image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.