Skip to content

Render error listings with a line index - #593

Merged
stepchowfun merged 1 commit into
mainfrom
line-index-listings
Oct 4, 2026
Merged

stepchowfun merged 1 commit into
mainfrom
line-index-listings

Conversation

@stepchowfun

Copy link
Copy Markdown
Owner

This ports the changes to error.rs from Mull, along with the line_index.rs it now depends on. Both files now match Mull's byte for byte, except for Mull's quick fixes (the Fix type, the fix field and accessor, and the corresponding constructor argument).

  • Each error's listing finds its lines with a LineIndex instead of scanning the source from its start, so reporting many errors no longer takes time proportional to the number of errors times the size of the source. Error::new's source context is now (&str, &LineIndex, SourceRange).
  • format_errors appends each error to the output instead of rebuilding it, which was quadratic in the number of errors.
  • A listing no longer panics when a range ends within a line's indentation, excludes indentation from every line's highlight, and no longer ends with a row of only spaces when its last line has nothing highlighted.

Each phase which reports errors builds a LineIndex once at its entry point and passes it along when constructing errors, so the many tests that call these phases don't change.

The only visible change in the output is that an error at the end of a file is followed by an empty line rather than a line of spaces.

Status: Ready

Fixes: N/A

This ports the changes to error.rs from Mull, along with the line_index.rs
it now depends on, so both files match Mull's apart from its quick fixes:

- Each error's listing finds its lines with an index of the source's
  lines instead of scanning the source from its start, so reporting many
  errors no longer takes time proportional to the number of errors times
  the size of the source.
- Formatting a list of errors appends each one to the output instead of
  rebuilding it, which was quadratic in the number of errors.
- A listing no longer panics when a range ends within a line's
  indentation, excludes indentation from every line's highlight, and no
  longer ends with a row of only spaces when its last line has nothing
  highlighted.

Each phase which reports errors builds an index of the source's lines
once and passes it along when constructing errors.
@stepchowfun
stepchowfun merged commit 3f5cead into main Oct 4, 2026
6 checks passed
@stepchowfun
stepchowfun deleted the line-index-listings branch October 4, 2026 02:50
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