Skip to content

Instantly share code, notes, and snippets.

@listochkin
Created August 7, 2024 00:28
Show Gist options
  • Save listochkin/9fcf6f8ed84ec8a07830701f530b37bd to your computer and use it in GitHub Desktop.
Save listochkin/9fcf6f8ed84ec8a07830701f530b37bd to your computer and use it in GitHub Desktop.
Rust Analyzer settings

Andrei's VSCode settings for Rust Analyzer

Custom hints, these options come straight from the Rust Analyzer manual. Check it out for more hints and for other things R-A can do for you!

"rust-analyzer.hover.actions.references.enable": true,
"rust-analyzer.diagnostics.experimental.enable": false,
// can show you if you get references or owned data when you match
"rust-analyzer.inlayHints.bindingModeHints.enable": true,
"rust-analyzer.inlayHints.closingBraceHints.minLines": 25,
// show what variables are captured and whether they are captured
// by value or reference
"rust-analyzer.inlayHints.closureCaptureHints.enable": true,
"rust-analyzer.inlayHints.closureReturnTypeHints.enable": "with_block",
// Closure notation in type and chaining inlay hints
"rust-analyzer.inlayHints.closureStyle": "rust_analyzer",
// for simple enums it shows which variant corresponds to which number
// in memory (helps with debugging serialization code, for example)
"rust-analyzer.inlayHints.discriminantHints.enable": "fieldless",
// These will show you when the compiler does Derefs behind the scenes
"rust-analyzer.inlayHints.expressionAdjustmentHints.enable": "always",
"rust-analyzer.inlayHints.expressionAdjustmentHints.mode": "prefer_prefix",
"rust-analyzer.inlayHints.implicitDrops.enable": true,
// When you get a lifetime error the unnamed annotations ('0, '1, etc.)
// in the error message are visible in code, too.
"rust-analyzer.inlayHints.lifetimeElisionHints.enable": "skip_trivial",
"rust-analyzer.inlayHints.lifetimeElisionHints.useParameterNames": false,
"rust-analyzer.inlayHints.rangeExclusiveHints.enable": true,
// "rust-analyzer.inlayHints.reborrowHints.enable": "always",
"rust-analyzer.inlayHints.typeHints.hideNamedConstructor": true,

Theme customization for unsafe Rust, ect. These settings are described in Rust Analyzer manual.

"editor.semanticTokenColorCustomizations": {
    "rules": {
        "*.unsafe:rust": "#ff00ff",
        // this line would re-color `unsafe`
        // keyword itself back to keyword color
        // (light green in my case)
        // "keyword.unsafe:rust":  "#859900",
        "unresolvedReference:rust" : "#21b321"

    },
    // theme-specific settings
    "[Solarized Light]": {
        // Most themes enable semantic
        // highlighting by default
        // if your theme disables it this
        // will force it back on.
        // "enabled": true,
        "rules": {
            // use bold for mutable stuff
            "parameter.mutable:rust": {
                "fontStyle": "bold"
            },
            "variable.mutable:rust": {
                "fontStyle": "bold"
            },
            // use slightly different color
            // for locals as opposed to
            // parameters
            "variable:rust": "#6C71C4",
            // use underlines for consuming
            // functions, function params, etc.
            "*.consuming": {
                "fontStyle": "underline"
            }
        }
    }
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment