rust-lang / rust-lang/rust-analyzer
Better autocomplete ranking: Exact matches shouldn't de-prioritize macros & results should prioritize local namespace items
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
I have two major suggestions to improve the autocompletion results from Rust-analyzer.
Using rust-analyzer (from Zed), constants, functions, and statics are prioritized over macros when doing an exact match, often with quite surprising results.
For example, try to autocomplete panic:
rust-analyzer gives as the first result the core function panic, which end users should almost never use, instead of the obvious panic! macro. (Oddly, it also gives the panic! macro twice, a small bug.)
Likewise for format, the macro, which I would assume in 99% of cases what users want, is the 6th option.
Assert is similar to panic:
Personally, I'd love to see assert_eq ranked over assert. Note that a function assert_equal (which I haven't imported, but exists in namespace from itertools as a dependency) is prioritized over assert_eq.
It seems like macros are heavily de-prioritized. Here's autocompletion giving results for pr:
Which is a bunch of constants associated with a sql parsing crate that is a dependency but hasn't been imported anywhere in the file. Contrast the autocomplete results with those from IntelliJ for the same letters & position:
IntelliJ results are:
- a "live template" with an exact string match for pr (what RA calls a snippet)
- the macro
println!, which in my experience, is used much more frequently thanprint - a local function
parse_recipient - the
print!macro - various other results that haven't been imported yet.
The intellij results are dramatically more helpful than the RA ones.
intellij seems to either have an embedded manual ranking, or it actually prioritzes longer matching strings over shorter. (E.g. pr ranks println before it ranks print). It's somewhat counterintuitive, but I see a compelling argument for matching longer strings before shorter ones: there are more characters to type, and therefore you prefer to rely on autocomplete more, when it's a longer string.
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 at rust-analyzer’s autocomplete ranking entry point and reproduce the reported cases for panic, format, assert_eq, and pr. Compare the current ordering with the requested behavior: exact macro matches and local namespace items should rank appropriately, duplicate macro results should be removed, and the completed ranking should be covered by relevant tests.
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
- Mostly clear
- Newbie friendliness
- 35/100