Skip to content

fix: improve diagnostic display for syntax errors and large code ranges#506

Merged
fansenze merged 1 commit intomainfrom
fix/diagnostic-display-20260316
Mar 17, 2026
Merged

fix: improve diagnostic display for syntax errors and large code ranges#506
fansenze merged 1 commit intomainfrom
fix/diagnostic-display-20260316

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Mar 17, 2026

Summary

  • Syntax error output: Previously dumped the entire file source text into the error message, making it unreadable. Now renders syntax errors with code snippets (like tsc --pretty), using the same box format as lint rule diagnostics.
  • Large code range display: Previously showed "Error range is too big. Skipping code block printing." when a diagnostic spanned 13+ lines. Now uses tsc-style folding — shows first 2 lines + .. + last 2 lines, so users always see code context.

Before / After

1. Syntax errors

Before — dumps entire file source into the error string, repeated for each error:

error creating TS program: found 2 syntactic errors. [Expression expected. const x = ;
const y = ;
const z = 1;
 Expression expected. const x = ;
const y = ;
const z = 1;
]

After — each error rendered with TS code, file location, and code snippet:

 TS1109  — [error] Expression expected.
  ╭─┴──────────( index.ts:1:11 )─────
  │ 1 │  const x = ;
  │ 2 │  const y = ;
  ╰────────────────────────────────

 TS1109  — [error] Expression expected.
  ╭─┴──────────( index.ts:2:11 )─────
  │ 1 │  const x = ;
  │ 2 │  const y = ;
  │ 3 │  const z = 1;
  ╰────────────────────────────────

2. Large code range (13+ lines)

Before — code snippet skipped entirely:

 max-lines-per-function  — [error] Function has too many lines (22).
  ╭─┴──────────( index.ts:1:1 )─────
  │  Error range is too big. Skipping code block printing.
  ╰────────────────────────────────

After — first 2 + .. + last 2 lines (tsc-style folding):

 max-lines-per-function  — [error] Function has too many lines (22).
  ╭─┴──────────( index.ts:1:1 )─────
  │  1 │  function reallyLongFunction() {
  │  2 │    const step1 = performStep(1);
  │ .. │
  │ 23 │  }
  │ 24 │
  ╰────────────────────────────────

3. Short code range (unchanged, for comparison)

 no-unused-vars  — [warn] 'unused' is defined but never used
  ╭─┴──────────( index.ts:2:7 )─────
  │ 1 │  const a = 1;
  │ 2 │  const unused = 42;
  │ 3 │  const b = 2;
  ╰────────────────────────────────

Codebox under 5 lines is displayed in full — same behavior as before.

Related Links

N/A

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the user experience for diagnostic messages by improving how syntax errors and large code ranges are displayed. The changes aim to provide clearer, more concise, and actionable feedback, aligning the output format with familiar tools like TypeScript's compiler for better readability and debugging.

Highlights

  • Improved Syntax Error Display: Syntax error messages now use a tsc-like file(line,col): error TS{code}: message format, replacing the previous unreadable full file source dump.
  • Enhanced Large Code Range Display: Diagnostic messages for large code ranges (5+ lines) now employ tsc-style folding, showing the first two and last two lines with an ellipsis in between, instead of a "Error range is too big" message.
Changelog
  • cmd/rslint/cmd.go
    • Removed the fixed-size buffer and "Error range is too big" message for diagnostic code blocks.
    • Implemented a dynamic line buffer and a folding mechanism for diagnostic code blocks that span 5 or more lines, displaying the first two, an ellipsis, and the last two lines.
  • cmd/rslint/cmd_test.go
    • Imported the fmt package.
    • Introduced createTestDiagnostic and renderDiagnostic helper functions for easier diagnostic testing.
    • Added new test suites (TestPrintDiagnosticFold, TestPrintDiagnosticSingleLine, TestPrintDiagnosticEdgeCases, TestSyntaxErrorFormat, TestSyntaxErrorFormatMultiple) to validate the new diagnostic display and folding logic, as well as the improved syntax error formatting.
  • internal/utils/create_program.go
    • Imported the strings and scanner packages.
    • Refactored the syntactic diagnostic error reporting to format messages in a file(line,col): error TS{code}: message style, improving clarity and consistency.
Activity
  • The author has marked "Tests updated (or not required)." as complete, indicating that new tests were added to cover the changes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly improves the diagnostic display, making syntax errors more readable and handling large code ranges gracefully with folding. The changes align well with the goal of providing a cleaner, tsc-like output. The implementation is solid, and the new tests are comprehensive. However, I've identified a critical bug in the code folding logic that results in incorrect output and highlighting. I've provided a detailed comment with a suggested fix to address this.

@fansenze fansenze force-pushed the fix/diagnostic-display-20260316 branch from 5f990fb to 6cbcf93 Compare March 17, 2026 03:12
@fansenze fansenze requested a review from hardfist March 17, 2026 03:23
- Syntax errors: render with code snippets like tsc --pretty, using the
  same box format as lint rule diagnostics. Introduce SyntacticError type
  to carry raw ast.Diagnostic for rich rendering in the CLI.
- Large code ranges: replace fixed-size array (13) and "Error range is
  too big" fallback with dynamic allocation and tsc-style folding
  (first 2 lines + ... + last 2 lines).
@fansenze fansenze force-pushed the fix/diagnostic-display-20260316 branch from 6cbcf93 to 6a91c8a Compare March 17, 2026 05:09
@fansenze fansenze merged commit 2d75a6f into main Mar 17, 2026
14 checks passed
@fansenze fansenze deleted the fix/diagnostic-display-20260316 branch March 17, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants