Skip to content

Track and report position of first parse error - #1019

Open
Wilfred wants to merge 2 commits into
masterfrom
claude/parse-error-display-text-zxql1x
Open

Track and report position of first parse error#1019
Wilfred wants to merge 2 commits into
masterfrom
claude/parse-error-display-text-zxql1x

Conversation

@Wilfred

@Wilfred Wilfred commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

Enhanced parse error reporting to include the line and column position of the first parse error encountered, in addition to the total error count. This helps users quickly locate syntax issues in their files.

Key Changes

  • New ParseErrors struct: Replaces simple usize error count with a structured type that tracks both the total error count and the position of the first error node encountered

    • Includes a record() method to capture error positions while walking the tree-sitter AST
    • Implements Default and Clone for convenience
  • Updated ExceededParseErrorLimit error type: Changed from a tuple struct holding just the error count to a struct with named fields:

    • error_count: usize - total number of parse errors
    • first_error_pos: Option<(LineNumber, usize)> - line number and zero-indexed column of first error
  • Error tracking throughout parsing: Updated all parsing functions (to_syntax, to_syntax_with_limit, syntax_from_cursor, etc.) to use the new ParseErrors struct instead of a simple counter

  • Enhanced user-facing error messages: When parse error limit is exceeded, the error message now includes the position of the first error (e.g., "first at 5:6")

  • Documentation update: Updated manual to reflect the new error position reporting in the output example

Implementation Details

  • The ParseErrors::record() method only captures the position of the first error encountered, avoiding unnecessary overhead for subsequent errors
  • Position tracking uses the existing LineNumber type from the line_numbers crate
  • The implementation preserves backward compatibility in the parsing pipeline while enriching error diagnostics

https://claude.ai/code/session_01JmVJsk7qNYW1UQ5Fkz8zGW

@Wilfred
Wilfred force-pushed the claude/parse-error-display-text-zxql1x branch from 8d27095 to 8860a73 Compare July 23, 2026 23:21
claude added 2 commits July 28, 2026 08:50
Convert the tuple struct to a struct with a named `error_count` field,
so that further parse error metadata can be added without relying on
positional access.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JmVJsk7qNYW1UQ5Fkz8zGW
When difftastic falls back to a line-oriented diff because the parse
error limit was exceeded, append the line and column of the first parse
error to the header, e.g.:

    Text (2 JavaScript parse errors, exceeded DFT_PARSE_ERROR_LIMIT, first at 3:1)

The position is captured during the initial walk of the tree-sitter AST
via a new ParseErrors accumulator, rather than walking the tree a second
time. Columns are zero-indexed and the line is a LineNumber.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JmVJsk7qNYW1UQ5Fkz8zGW
@Wilfred
Wilfred force-pushed the claude/parse-error-display-text-zxql1x branch from 8860a73 to b76e9fb Compare July 28, 2026 08:51
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.

2 participants