rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.25k stars 1.6k forks source link

Inlay hints - show from what module item is used #18198

Open grappas opened 1 month ago

grappas commented 1 month ago

i.e. we import module:

use std::env::args;

and we arm args:

    let args: Vec<String> = args().collect();

What would be nice is to optionally see in inlay hints from where args() is coming from

    //----------------------VVVVVVVV - that would be greyed out without writing it
    let args: Vec<String> = std::env::args().collect();

or lets say to distinguish from different implementations of chrono structs ( if it is chrono from chrono or chrono from tiberius for example) That would increase readability. Especially for new rustaceans. :)

lnicola commented 1 month ago

You mean let args: std::Vec<std::String> = std::env::args().collect();, right?

I don't think we want to do this. It's a lot of noise, and people are already asking us to completely disable inlay hints by default because they find them to be too much. You should be able to see the full path on hover (which you can also trigger using the keyboard) or Peek Definition (Ctrl-Shift-F10).

grappas commented 1 month ago

Sure. Point for you, but... shouldn't be there a way to customize what would be shown in inlay hints? Inlay hints seems to be togglable also. At least for me in neovim with keyboard shortcut.

lnicola commented 1 month ago

shouldn't be there a way to customize what would be shown in inlay hints

You can customize the important things: whether to show them for variables, parameters, generic parameters, lifetimes, consts, whether to show chaining hints, even whether to show the colons. We have 27 settings by my count, compared to 4 for Python and 8 for TypeScript.

But in the long term, users will ask to make everything customizable, which means that nobody will ever be able to go through all the settings. Check out this tiny subset of IntelliJ's formatting settings:

Image

At least for inlay hints they have almost no settings at all:

Image

That said, if you have ambiguous imports in your code, it might be better to specify them in full tiberius::time::chrono::DateTime. They will take the same amount of screen space as the hints, and they'll always be there when you need them.

Or you can drop your chrono dependency and use the re-export, since that's what's going to work best.

grappas commented 1 month ago

It can be disabled by default. I wouldn't mind. :)