Home > Net >  Can I remove type annotation help from rust-analyzer?
Can I remove type annotation help from rust-analyzer?

Time:11-11

For VS Code, I use rust-analyzer to handle syntax highlighting and flychecking. But if I don't add type annotations to declarations in the code, rust-analyzer shows the missing type annotations in the file without actually inserting it in the code. Is there a way to turn this off?

I prefer to add my own type annotations and I'm more likely to forget that if rust-analyzer shows me the missing annotations, and sometimes they're in the way as I have auto formatting on save set, and this formatting breaks up the lines correctly. With rust-analyzers's type annotation help, some lines become too long to fit on my screen.

In the picture below, it's the grey text I'm referring to. I would like it gone. enter image description here

CodePudding user response:

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
}
  • Related