Can I remove type annotation help from rust-analyzer?

Viewed 4344

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

2 Answers

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
}

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+shit+p) : Rust Analyzer: Toggle inlay hints

Related