Display types in my code while working

I'm working in vim and it seems like there should be a way for rust-analyzer or something to display the type in the code I'm working on.

I'm putting a lot of energy into mentally keeping track of types (and their concretes of generics and what is wrapped in what and sometimes wrapped in a future) while chaining together commands.

I'd like to hit a key and vim brings up a little window like autocomplete does and it tells me all that info. Does it exist?

I don't know but the keywords you want to search for are "vim rust-analyzer inline hints"

Please also consider adding more explicit types to your code. Code should be readable without IDE support.

Of course, editing code that isn't yet correct can be more difficult, but explicit types can also help the compiler and rust-analyzer give more useful type error messages.

What are you using for LSP/rust-analyzer support in vim?

Whatever it is, look for the key the provides "hover". The rust-analyzer "hover" action will display the type of the variable your cursor is on.

If your using coc-vim, for example, this is Shift-K.

Inline hints are another way to see variable types, but this looks cluttered IMO, so I always use the hover key.

Yes, and "inlay hints". Thanks erelde.

I'm using lunarvim. Don't think it's coc, but shift-k does indeed do the trick for it. Thanks.

1 Like

I was just referring to the types of std, axum, http, reqwest, tower, tokio, oh my. I feel like I'm swimming in types and not quite ready to add another one until I have a grip. I'll make nice explicit types, but just need a little reminding while getting up to speed.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.