Skip to content

Commit

Permalink
highlighter: Add disabled debug logs for faster analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKar committed Jan 29, 2024
1 parent 94710f0 commit 7f6733a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/highlight/highlighter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package highlight

import (
// "log"
"regexp"
"strings"

Expand Down Expand Up @@ -94,12 +95,14 @@ func (h *Highlighter) highlightRange(fullHighlights []Group, start int, end int,
if start <= end && end <= len(fullHighlights) {
for i := start; i < end; i++ {
fullHighlights[i] = group
// log.Println("fullHighlights[", i, "]:", group)
}
}
}

func (h *Highlighter) highlightPatterns(fullHighlights []Group, start int, lineNum int, line []byte, curRegion *region) {
lineLen := util.CharacterCount(line)
// log.Println("highlightPatterns: lineNum:", lineNum, "start:", start, "line:", string(line))
if lineLen == 0 {
return
}
Expand All @@ -123,6 +126,7 @@ func (h *Highlighter) highlightPatterns(fullHighlights []Group, start int, lineN

func (h *Highlighter) highlightRegions(fullHighlights []Group, start int, lineNum int, line []byte, curRegion *region, regions []*region, nestedRegion bool) {
lineLen := util.CharacterCount(line)
// log.Println("highlightRegions: lineNum:", lineNum, "start:", start, "line:", string(line))
if lineLen == 0 {
return
}
Expand All @@ -141,10 +145,13 @@ func (h *Highlighter) highlightRegions(fullHighlights []Group, start int, lineNu
samePattern := false
startLoop:
for startIdx := 0; startIdx < len(startMatches); startIdx++ {
// log.Println("startIdx:", startIdx, "of", len(startMatches))
if startMatches[startIdx][0] < lineLen {
for endIdx := 0; endIdx < len(endMatches); endIdx++ {
// log.Println("startIdx:", startIdx, "of", len(startMatches), "/ endIdx:", endIdx, "of", len(endMatches), "/ regionEnd:", regionEnd)
if startMatches[startIdx][0] == endMatches[endIdx][0] {
// start and end are the same (pattern)
// log.Println("start == end")
samePattern = true
if len(startMatches) == len(endMatches) {
// special case in the moment both are the same
Expand All @@ -166,6 +173,7 @@ func (h *Highlighter) highlightRegions(fullHighlights []Group, start int, lineNu
continue
}
// start and end at the current line
// log.Println("start < end")
regionStart = startMatches[startIdx][0]
regionEnd = endMatches[endIdx][1]
h.highlightRange(fullHighlights, start+startMatches[startIdx][0], start+endMatches[endIdx][1], r.limitGroup)
Expand All @@ -187,6 +195,7 @@ func (h *Highlighter) highlightRegions(fullHighlights []Group, start int, lineNu
continue
}
// start and end at the current line, but switched
// log.Println("end < start")
h.highlightRange(fullHighlights, start, start+endMatches[endIdx][1], r.limitGroup)
h.highlightRegions(fullHighlights, start, lineNum, util.SliceStart(line, endMatches[endIdx][0]), r, r.rules.regions, true)
h.highlightPatterns(fullHighlights, start+endMatches[endIdx][1], lineNum, util.SliceStartEnd(line, endMatches[endIdx][1], startMatches[startIdx][0]), nil)
Expand All @@ -200,6 +209,7 @@ func (h *Highlighter) highlightRegions(fullHighlights []Group, start int, lineNu
}
if regionEnd <= startMatches[startIdx][0] {
// start at the current, but end at the next line
// log.Println("start ...")
regionStart = startMatches[startIdx][0]
regionEnd = 0
h.highlightRange(fullHighlights, start+startMatches[startIdx][0], lineLen, r.limitGroup)
Expand All @@ -215,6 +225,7 @@ func (h *Highlighter) highlightRegions(fullHighlights []Group, start int, lineNu
if (len(startMatches) == 0 && len(endMatches) > 0) || (samePattern && (len(startMatches) == len(endMatches))) {
for _, endMatch := range endMatches {
// end at the current, but start at the previous line
// log.Println("... end")
h.highlightRange(fullHighlights, start, start+endMatch[1], r.limitGroup)
h.highlightRegions(fullHighlights, start, lineNum, util.SliceStart(line, endMatch[0]), r, r.rules.regions, true)
if curRegion != nil {
Expand All @@ -235,6 +246,7 @@ func (h *Highlighter) highlightRegions(fullHighlights []Group, start int, lineNu

func (h *Highlighter) highlight(highlights LineMatch, start int, lineNum int, line []byte, curRegion *region) LineMatch {
lineLen := util.CharacterCount(line)
// log.Println("highlight: lineNum:", lineNum, "start:", start, "line:", string(line))
if lineLen == 0 {
return highlights
}
Expand Down

0 comments on commit 7f6733a

Please sign in to comment.