Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Jan 4, 2025
1 parent 33717d0 commit d499787
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kittens/diff/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func resolved_chroma_style() *chroma.Style {
}

var tokens_map map[string][]chroma.Token
var mu sync.Mutex

func highlight_file(path string) (highlighted string, err error) {
defer func() {
Expand Down Expand Up @@ -210,7 +211,9 @@ func highlight_file(path string) (highlighted string, err error) {
if tokens_map == nil {
tokens_map = make(map[string][]chroma.Token)
}
mu.Lock()
tokens := tokens_map[path]
mu.Unlock()
if tokens == nil {
lexer := lexers.Match(filename_for_detection)
if lexer == nil {
Expand All @@ -225,7 +228,9 @@ func highlight_file(path string) (highlighted string, err error) {
return "", err
}
tokens = iterator.Tokens()
mu.Lock()
tokens_map[path] = tokens
mu.Unlock()
}
formatter := chroma.FormatterFunc(ansi_formatter)
w := strings.Builder{}
Expand Down

0 comments on commit d499787

Please sign in to comment.