41

For VS Code, I use rust-analyzer to handle syntax highlighting and flychecking.

How do I remove the inlay type and parameter annotations in grey below?

enter image description here

kmdreko
  • 42,554
  • 6
  • 57
  • 106
Thorkil Værge
  • 2,727
  • 5
  • 32
  • 48
  • parameter hints and type hints – Stargateur Nov 10 '21 at 08:51
  • 18
    I wish rust analyzer turned off inlay annotations by default. While they're great for people who want them, using them by default adds unnecessary noise to the language. An important benefit of strong type inference like Rust's is that you don't have to clutter the code with annotations. While the code is technically not cluttered here (the annotations are just added by the IDE), _visually_ the result is as if they are. – user4815162342 Nov 10 '21 at 12:11
  • While I agree about the default setting, I personally favor the Microsoft style guide which says that all declarations should be explicitly type annotated, except for calls to a constructor. My main problem with `rust-analyzer` was the mess that the "inlays" made to my line lengths, which is normally strictly enforced by my auto formatter. I might be in the minority about explicit type annotations though. – Thorkil Værge Nov 10 '21 at 12:17
  • More like type annotation "help" amirite? – Thorkil Værge Nov 10 '21 at 12:23
  • "I personally favor the Microsoft style guide which says that all declarations should be explicitly type annotated" since when there is a microsoft style for Rust ? also, that simply is impossible in Rust and is a bad idea anyway. – Stargateur Nov 10 '21 at 13:57
  • 2
    @user4815162342 An important benefit of strong type inference like Rust's is that *you* don't have to clutter the code with annotations. I still want to see the inferred type of an expression (especially when I'm not sure what type a function returns), I just don't want to have to type it out myself. – BallpointBen Nov 10 '21 at 15:13
  • @BallpointBen Oh, it's definitely useful to be able to see the result of type inference, and that's typically available by hovering over the variable. I'm only taking about showing the result of _all_ type inferences and cluttering the declaration of every variable. That's fine for people who opt in, but it's a bad default because it adds unnecessary text and makes the whole language appear cluttered and weird. – user4815162342 Nov 10 '21 at 15:29
  • Here's how you'd keep the hint but remove the bright blue background: [Disable background color for types in BSCode while using Rust](/q/73020238/2189130) – kmdreko Jul 18 '22 at 14:15

2 Answers2

64

Update Sept 2022.

They now use VSCode builtin inlay function from 1.67

I setup mine as follow:

{
  "editor.inlayHints.enabled": "offUnlessPressed"
}

Then you can toggle them with Ctrl+Alt pressed.


Old Answer

There is now a togglable command (Ctrl+Shift+P) : Rust Analyzer: Toggle inlay hints

Vincent Tjeng
  • 693
  • 8
  • 25
melMass
  • 3,813
  • 1
  • 31
  • 30
53

New Answer for VS Code: https://stackoverflow.com/a/72338341/9363973


Old answer:

In Visual Studio Code you can easily do this.

  1. Open the settings page (Ctrl+,)
  2. Search for "rust-analyzer inlay"
  3. Uncheck things you don't want
    • In your case that would be "Parameter Hints" and "Type Hints"

If you're not using Visual Studio Code you'll need to manually edit the JSON config file of rust-analyzer (helpful link to the documentation). Basically

  1. Open the JSON config file in your favourite text editor
  2. Add a new property to the root of the JSON object like so:
{
    "inlayHints": {
        "typeHints": false,
        "parameterHints": false
    },
    // further configuration
}
MindSwipe
  • 7,193
  • 24
  • 47