Skip to content

Fix gutter width for following context lines - #417

Open
RanaPriyansh wants to merge 1 commit into
brendanzab:masterfrom
RanaPriyansh:repro/context-gutter-352
Open

RanaPriyansh wants to merge 1 commit into
brendanzab:masterfrom
RanaPriyansh:repro/context-gutter-352

Conversation

@RanaPriyansh

Copy link
Copy Markdown

Problem

Following context can cross a line-number digit boundary. The renderer then places source gutter separators in different columns.

Change

Update the gutter width when an actual following context line is inserted. Add regression coverage for single-line, multiline, 9-to-10, and 99-to-100 boundaries.

Add controls for zero context, same-width context, and requested context beyond EOF.

Verification

  • cargo test -p codespan-reporting --test term context_digit_boundary -- --nocapture
  • cargo test -p codespan-reporting --no-default-features
  • cargo test -p codespan-reporting --no-default-features --features std
  • cargo test -p codespan-reporting
  • cargo test --workspace
  • cargo fmt --all -- --check
  • cargo clippy --all

All listed checks pass on Rust 1.95.0 in the captured local receipts.

Limitations

Validated locally on macOS with Rust 1.95.0. The repository CI matrix has not run on this candidate.

This change makes no performance claim and does not change public APIs.

AI assistance was used to prepare this change and its tests.

Fixes #352.

@RanaPriyansh
RanaPriyansh force-pushed the repro/context-gutter-352 branch from bab9199 to 1845ca8 Compare September 24, 2026 09:44
@kaleidawave

Copy link
Copy Markdown
Collaborator

Can you show the fix that this change provides with before and after code blocks of the rendered diagnostic output

@RanaPriyansh

Copy link
Copy Markdown
Author

Thanks. Here is the rendered output for the 9→10 boundary. The source gutter separators do not align before the change. The fix adds the space required by the two-digit context line.

Before:

error: boundary
  ┌─ boundary.rs:9:1
  │
9 │ line9
  │ ^^^^^
10 │ line10

After:

error: boundary
   ┌─ boundary.rs:9:1
   │
 9 │ line9
   │ ^^^^^
10 │ line10

The 99→100 case shows the same correction. I also checked a multiline label ending on line 9. The label shape stays the same, and the outer gutters align. Both outputs use the same fixture and emit_into_string renderer path.

Codex used.

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.

Wrong outer padding

2 participants