Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kurtbuilds opened this issue Nov 23, 2024 · 5 comments
Labels
A-completion autocompletion C-enhancement Category: enhancement

Comments

@kurtbuilds
Copy link

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.

@kurtbuilds
Copy link
Author

Closing b/c I think the frontend does ranking of results, not backend.

@flodiebold
Copy link
Member

We can influence the ranking.

@flodiebold flodiebold reopened this Nov 29, 2024
@lnicola lnicola added the A-completion autocompletion label Nov 29, 2024
@kurtbuilds
Copy link
Author

One other thing to add: I noticed it's quite nice how IntelliJ uses the import path as detail text if the item isn't in local scope.

@lnicola
Copy link
Member

lnicola commented Nov 29, 2024

@kurtbuilds we have that too:

Image

@kurtbuilds
Copy link
Author

That's odd. What editor are you using in your screenshot? Zed is my go to, and import paths are not visible in the previous screenshots that I posted. Maybe it's only a Zed frontend issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion C-enhancement Category: enhancement
Projects
None yet
Development

No branches or pull requests

3 participants