Getting the type of the expression under my cursor?


#1

I’d like to be able to run rustc --type-at-pos file/path.rs:line:col and get the type of the expression beneath that position. Does it already exist, or are there plans to build it? Should I file a GitHub issue?


#2

Ah, this is probably more of a job for Racer than rustc.


#3

I know RLS has it (or if it’s some other part of the Visual Studio Code plugin). I guess you could try to set it up if your editor works with the language server protocol.


#4

Thanks! This is exactly the kind of project I’m looking for.


#5

Have to say the type info from Intellij idea’s rust plugin is pretty good as well


#6

Does IntelliJ not just use RLS under the hood? Looks like VSCode just asks RLS for type information; I’d assume IntelliJ does the same.


#7

They do their own thing actually, see https://intellij-rust.github.io/docs/faq.html


#8
  • Visual Studio Code supports this with the official Rust extension.
  • Atom supports this with autocomplete-racer, or Atom 1.21 with the tokamak IDE.

#9

Seems to work for (neo)vim as well: https://www.reddit.com/r/rust/comments/72a1p4/how_the_rls_rust_language_server_works/dnha0s4/.