Skip to content

feat(lsp): apply project-specific rustfmt settings - #295

Merged
fcoury-oai merged 1 commit into
mainfrom
fcoury/project-rustfmt-settings
Aug 21, 2026
Merged

fcoury-oai merged 1 commit into
mainfrom
fcoury/project-rustfmt-settings

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Why

Some Rust repositories keep formatter arguments in .vscode/settings.json instead of a Red configuration file. Red previously ignored those project settings, so saving a nested Cargo crate could format imports differently from the repository's conventions unless every Rust project inherited a global override.

What changed

  • Discover the nearest project-local .vscode/settings.json between the Cargo workspace and its Git repository root, including linked worktrees.
  • Parse VS Code JSONC and apply only rust-analyzer.rustfmt.extraArgs to that workspace's LSP initialization and configuration responses. Explicit Red LSP settings take precedence.
  • Reject malformed or oversized settings, invalid arguments, and settings symlinked outside the repository; ignore executable, command, and environment overrides.
  • Document the behavior and cover workspace discovery, JSONC, precedence, project isolation, security boundaries, the LSP handshake, and formatting through a real rust-analyzer process.

How to Test

  1. Open a nested Rust crate in a repository whose existing .vscode/settings.json contains "rust-analyzer.rustfmt.extraArgs": ["--config", "imports_granularity=Item"].

  2. Save a file containing use std::{fmt::Display, io::Write};. Expect separate use std::fmt::Display; and use std::io::Write; lines without adding or changing repository configuration.

  3. Configure explicit rustfmt.extraArgs in Red and reopen the project. Expect the explicit settings to win; opening another repository must not inherit the first project's settings.

  4. Run the focused regressions and opt-in real-server smoke test:

    cargo test -p red workspace_settings --lib --all-features
    RED_RUN_REAL_LSP_TESTS=1 cargo test -p red real_rust_analyzer_formats_nested_workspace_with_project_settings --lib --all-features -- --nocapture

Validated locally with 2,091 passing library tests and cargo clippy --all-targets --all-features -- -D warnings.

@fcoury-oai
fcoury-oai merged commit 83329b6 into main Aug 21, 2026
10 checks passed
@fcoury-oai
fcoury-oai deleted the fcoury/project-rustfmt-settings branch August 21, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant