fix: Resolve lexer per file instead of caching#216
Merged
Conversation
Previously, the Gat struct cached the auto-detected lexer in the lexer field after the first Print call, causing subsequent calls to use the wrong lexer for different file types. This change: - Renames the lexer field to explicitLexer to clarify it only holds user-specified lexers - Introduces a local lexer variable in Print method that is resolved per call - Ensures auto-detected lexers are not written back to the struct field This fixes the issue where processing multiple files with different types would incorrectly use the first file's lexer for all subsequent files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
Fix ensures lexer is resolved per Print call rather than cached globally, preventing reuse of the first detected lexer across different file types.
- Rename cached field to explicitLexer to clarify semantics.
- Introduce per-call local lexer resolution instead of mutating struct.
- Avoid persisting auto-detected lexers, fixing cross-file highlighting errors.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| @@ -33,7 +33,7 @@ type Config struct { | |||
| } | |||
|
|
|||
| type Gat struct { | |||
There was a problem hiding this comment.
Consider adding a clarifying comment above explicitLexer (e.g. // explicitLexer holds only a user-specified lexer; auto-detected lexers are resolved per Print call and never cached) to prevent future regressions or reintroduction of caching.
Suggested change
| type Gat struct { | |
| type Gat struct { | |
| // explicitLexer holds only a user-specified lexer; auto-detected lexers are resolved per Print call and never cached. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, the Gat struct cached the auto-detected lexer in the lexer field after the first Print call, causing subsequent calls to use the wrong lexer for different file types.
This change:
This fixes the issue where processing multiple files with different types would incorrectly use the first file's lexer for all subsequent files.
🤖 Generated with Claude Code