Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions internal/gat/gat.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Config struct {
}

type Gat struct {
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
lexer chroma.Lexer
explicitLexer chroma.Lexer
formatter chroma.Formatter
style *chroma.Style
renderMarkdown bool
Expand All @@ -54,7 +54,7 @@ func New(cfg *Config) (*Gat, error) {
if err != nil {
return nil, err
}
g.lexer = l
g.explicitLexer = l
}

// formatter
Expand Down Expand Up @@ -147,15 +147,16 @@ func (g *Gat) Print(w io.Writer, r io.Reader, opts ...PrintOption) error {
}

// analyse lexer
if g.lexer == nil {
lexer := g.explicitLexer
if lexer == nil {
l, err := lexers.Get(lexers.WithFilename(opt.Filename), lexers.WithSource(src))
if err != nil {
return err
}
g.lexer = l
lexer = l
}

if g.renderMarkdown && g.lexer.Config().Name == "markdown" {
if g.renderMarkdown && lexer.Config().Name == "markdown" {
r, err := glamour.NewTermRenderer(
glamour.WithAutoStyle(),
glamour.WithWordWrap(-1),
Expand All @@ -177,7 +178,7 @@ func (g *Gat) Print(w io.Writer, r io.Reader, opts ...PrintOption) error {

// pretty code
if opt.Pretty {
p, ok := prettier.Get(g.lexer.Config().Name)
p, ok := prettier.Get(lexer.Config().Name)
if ok {
s, err := p.Pretty(src)
if err == nil {
Expand All @@ -187,7 +188,7 @@ func (g *Gat) Print(w io.Writer, r io.Reader, opts ...PrintOption) error {
}

// print
it, err := g.lexer.Tokenise(nil, src)
it, err := lexer.Tokenise(nil, src)
if err != nil {
return err
}
Expand Down