Skip to content

formatOnSave with VSCode extension does not respect ignore config in rustfmt.toml #10826

Description

@BGR360

Ran into this while working in the rustc repo. There are a number of paths in rustfmt.toml that are ignored, but if you open and then save any of them, then the rust-analyzer VSCode extension still formats the contents with rustfmt.

Minimal steps to reproduce

  1. Create empty project with cargo new.

  2. Write some poorly formatted code to src/main.rs:

     fn   main ()
     {
    println!("Hello, world!");
     }
  3. Ignore src/main.rs in rustfmt.toml:

    ignore = [
        "src/main.rs",
    ]
  4. Demonstrate that nightly rustfmt respects this configuration:

    $ cargo +nightly fmt -- src/main.rs
    $ cat src/main.rs
     fn   main ()
     {
    println!("Hello, world!");
     }
    
  5. Enable formatOnSave using nightly rustfmt in one of two ways:

    Option 1: rust-toolchain

    In rust-toolchain:

    nightly
    

    In .vscode/settings.json:

    {
        "editor.formatOnSave": true
    }

    Option 2: overrideCommand

    In .vscode/settings.json:

    {
        "rust-analyzer.rustfmt.overrideCommand": [
            "/YOUR/HOME/.rustup/toolchains/nightly-YOUR-HOST-TRIPLE/bin/rustfmt"
        ],
        "editor.formatOnSave": true
    }
  6. Open src/main.rs in VSCode and save.

Observed Behavior

The rust-analyzer extension formats the code in src/main.rs.

Expected behavior

The rust-analyzer extension respects the configuration in rustfmt.toml and
does not format the code in src/main.rs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-idegeneral IDE featuresC-bugCategory: bugS-unactionableIssue requires feedback, design decisions or is blocked on other work

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions