Skip to content

Report indentation from Format Document's layout, so a diagnostic always matches what formatting does - #397

Merged
jbearak merged 2 commits into
mainfrom
refactor/indentation-from-formatter
Nov 6, 2026
Merged

jbearak merged 2 commits into
mainfrom
refactor/indentation-from-formatter

Conversation

@jbearak

@jbearak jbearak commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Indentation diagnostics tell the user to "Use Format Document to fix", but they computed expected indentation separately from the formatter, with their own AST walks, a raw brace scan, and a comment heuristic, and the two disagreed. Across Stata's 3,780 base ados, formatting every file still left 9,360 indentation diagnostics in 349 files.

Decision: the default source-preserving formatter is the authority. A code line is reported when Format Document (source-preserving) would re-indent it: MISSING_INDENTATION when it would indent the line more, UNNECESSARY_INDENTATION when less. Kept from before:

  • comment-only lines and lines inside a block comment aren't reported (Format Document still re-indents them);
  • structural parse errors still suppress their enclosing block;
  • tab width still follows tab stops.

The analyzer's own layout code (about 650 lines) is gone. Its tests now go through analyze() on real documents; tests of deleted internals and fake ast: null documents moved to a shared helper, expect_line_at_depth.

Behaviour changes worth knowing:

  • About 94% of diagnostics are unchanged on the base ados. 5,929 old ones disappear: those were lines Format Document leaves alone. 15,175 new ones are lines Format Document does re-indent, mostly around /* */ and /// continuations.
  • The source-preserving formatter places a line relative to its block header rather than at an absolute depth. The diagnostics now follow that.
  • A diagnostic's range now ends at the last leading whitespace character, not at its visual width. LSP positions count characters.
  • A line such as /* c */ display 1 is reported when Format Document moves it; it used to be exempt. Lines whose inner spacing Format Document also changes (display\t1) are still checked.

Proof: after Format Document, 34 indentation diagnostics remain across 11 of 3,803 files, down from 9,360 in 349 files. The 34 are places where formatting twice changes more, which is a separate formatter idempotence issue. Timing is 35 ms on an 11,000-line ado. Typecheck, lint, and bun test ./tests pass (9642 tests).

Reviewed with sol-loop: 2 rounds with gpt-6.1-sol. Sol verdict: approved

Created with Claude Opus 5.5 in T3 Code.

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 35 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 69 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 2fd250b4-67cd-4115-9767-17d445137f84
Commits

Reviewing files that changed from the base of the PR and between bb722c2 and 716ce4e.

Files selected for processing: 12

  • docs/diagnostics.md
  • src/providers/indentation-diagnostics.ts
  • tests/integration/indentation-diagnostics.test.ts
  • tests/property/block-comment-indentation-exclusion.prop.test.ts
  • tests/property/else-block-indentation-depth.prop.test.ts
  • tests/property/embedded-block-end-indentation.prop.test.ts
  • tests/property/helpers/indentation-test-utils.ts
  • tests/property/post-block-comment-diagnostic-resumption.prop.test.ts
  • tests/property/prefix-command-brace-block-indentation.prop.test.ts
  • tests/property/visual-width-calculation.prop.test.ts
  • tests/repro_else_indent.test.ts
  • tests/unit/inline-if-indentation.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@jbearak
jbearak force-pushed the refactor/indentation-from-formatter branch 2 times, most recently from f5609a3 to f294cd6 Compare November 6, 2026 00:11
jbearak and others added 2 commits November 5, 2026 19:17
…ays matches what formatting does

The indentation diagnostics computed each line's expected depth with
their own AST walks, a raw brace scan, and a comment heuristic, while
the formatter computed its own layout, and the two disagreed: across
Stata's 3,780 base ados, 9,360 indentation diagnostics survived Format
Document, which the messages tell the user to run. A line is now
reported exactly when source-preserving Format Document would re-indent
it (UNNECESSARY_INDENTATION when less, MISSING_INDENTATION when more).
Comment-only lines and lines inside block comments stay exempt, and
structural parse errors still suppress their block. The analyzer's own
walkers (about 650 lines) are gone; its tests now go through analyze()
on real documents.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jbearak
jbearak force-pushed the refactor/indentation-from-formatter branch from f294cd6 to 716ce4e Compare November 6, 2026 00:18
@jbearak
jbearak merged commit c115312 into main Nov 6, 2026
22 of 23 checks passed
@jbearak
jbearak deleted the refactor/indentation-from-formatter branch November 6, 2026 00:27
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