Skip to content

fix(cmd): handle UTF-8 characters correctly in diagnostic printing#479

Merged
fansenze merged 2 commits intoweb-infra-dev:mainfrom
magic-akari:main
Mar 2, 2026
Merged

fix(cmd): handle UTF-8 characters correctly in diagnostic printing#479
fansenze merged 2 commits intoweb-infra-dev:mainfrom
magic-akari:main

Conversation

@magic-akari
Copy link
Contributor

Summary

Related Links

Checklist

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

Copilot AI review requested due to automatic review settings February 16, 2026 16:58
@gemini-code-assist
Copy link

Summary of Changes

Hello @magic-akari, 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 resolves an issue where the rslint command-line tool's diagnostic printing failed to correctly display multi-byte UTF-8 characters, leading to formatting inaccuracies. The changes introduce byte-aware processing for text within diagnostic codeboxes, ensuring that character positions and line formatting are accurately calculated regardless of the character encoding, thereby improving the readability and correctness of diagnostic output for internationalized content.

Highlights

  • UTF-8 Character Handling: Implemented correct handling of multi-byte UTF-8 characters in diagnostic printing by switching from character-based indexing to byte-based indexing.
  • Dependency Update: Imported the unicode/utf8 package to facilitate accurate byte length calculations for runes.
  • Code Refactoring: Refactored the printDiagnosticDefault function to iterate over runes and explicitly track byte positions, ensuring precise calculation of line starts and ends for diagnostic highlights.
Changelog
  • cmd/rslint/cmd.go
    • Updated diagnostic printing logic to correctly handle multi-byte UTF-8 characters.
    • Switched from rune-based indexing to byte-based indexing for position calculations within codebox text.
    • Imported the unicode/utf8 package to assist with rune byte length determination.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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

@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

The pull request correctly addresses the handling of UTF-8 characters in diagnostic printing. The changes involve importing the unicode/utf8 package, renaming lastNonSpaceIndex to lastNonSpaceByteIndex for clarity, and adjusting the loop logic to explicitly track byte positions using bytePos and utf8.RuneLen. This ensures that line start and end calculations are accurate for multi-byte characters, improving the correctness of diagnostic output.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request attempts to fix UTF-8 multi-byte character rendering issues in diagnostic output (issue #478). The changes modify the printDiagnosticDefault function in cmd/rslint/cmd.go to iterate over runes instead of bytes when calculating line start and end positions for code frame display.

Changes:

  • Added unicode/utf8 import for UTF-8 rune handling
  • Modified code frame calculation loop to iterate by runes while tracking byte positions
  • Renamed lastNonSpaceIndex to lastNonSpaceByteIndex for clarity

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@magic-akari
Copy link
Contributor Author

Test cases generated by kimi-k2.5

@fansenze
Copy link
Contributor

fansenze commented Mar 2, 2026

@magic-akari Thanks for the PR! It looks like the CI is failing due to some style/linting issues. You'll need to run npm run check-spell, npm run format:check and npm run lint:go to catch the issues.

@fansenze fansenze merged commit aaaf7a4 into web-infra-dev:main Mar 2, 2026
10 checks passed
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.

[Bug]: UTF-8 multi-byte characters rendered incorrectly in error output

3 participants