rust-lang / rust-lang/rust-analyzer

Better autocomplete ranking: Exact matches shouldn't de-prioritize macros & results should prioritize local namespace items

Open
#18,546 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-completion C-enhancement
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:
Image

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.

Image

Assert is similar to panic:

Image

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:

Image

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:

Image

IntelliJ results are:

  1. a "live template" with an exact string match for pr (what RA calls a snippet)
  2. the macro println!, which in my experience, is used much more frequently than print
  3. a local function parse_recipient
  4. the print! macro
  5. 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.