Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlighter: Change the parsing approach to significantly improve performance #3127

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
acb2586
highlighter: Perform sliceStart() in nested region only once
JoeKar Jan 17, 2024
ca29fa3
highlighter: Rename firstLoc/Region into nestedLoc/Region for readabi…
JoeKar Jan 17, 2024
ee69f75
highlighter: gofmt
JoeKar Jan 17, 2024
e98a8a4
highlighter: Remove canMatchEnd since it's not really useful
JoeKar Jan 17, 2024
9925778
highlighter: Combine HighlightStates and HighlightMatches to Highlight
JoeKar Jan 17, 2024
c05d496
highlighter: Remove statesOnly since it's not needed any longer
JoeKar Jan 17, 2024
95c1fc2
highlight: Remove duplicated util code
JoeKar Jan 28, 2024
31ac145
highlighter: Rework of matching approach to speed up the processing
JoeKar Jan 25, 2024
6d922ed
highlighter: Add disabled debug logs for faster analysis
JoeKar Jan 29, 2024
74be831
highlighter: Fix regression in nested regions/patterns
JoeKar Feb 13, 2024
92073ca
highlighter: Small corrections
JoeKar Feb 16, 2024
a4be06d
highlighter: Fix regression in nested regions/patterns (2nd)
JoeKar Feb 16, 2024
4c4732b
highlighter: Fix `limitGroup` behavior of regions
JoeKar Feb 23, 2024
c1f7910
highlighter: Add capability to remove already captured groups
JoeKar Feb 27, 2024
e5611ee
highlighter: Add capability to remove childrens of already captured g…
JoeKar Mar 6, 2024
d6da952
highlighter: Add capability to add already removed groups again
JoeKar Mar 7, 2024
e9c77fa
highlighter: Handle `h.lastRegion` within `h.highlight()` only
JoeKar Apr 9, 2024
fb2ed1b
highlighter: Properly handle rehighlighting within `Highlight()`
JoeKar Apr 11, 2024
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
9 changes: 2 additions & 7 deletions internal/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ func (b *SharedBuffer) MarkModified(start, end int) {
end = util.Clamp(end, 0, len(b.lines)-1)

if b.Settings["syntax"].(bool) && b.SyntaxDef != nil {
l := -1
for i := start; i <= end; i++ {
l = util.Max(b.Highlighter.ReHighlightStates(b, i), l)
}
b.Highlighter.HighlightMatches(b, start, l)
b.Highlighter.Highlight(b, start, end)
}

for i := start; i <= end; i++ {
Expand Down Expand Up @@ -961,8 +957,7 @@ func (b *Buffer) UpdateRules() {
b.Highlighter = highlight.NewHighlighter(b.SyntaxDef)
if b.Settings["syntax"].(bool) {
go func() {
b.Highlighter.HighlightStates(b)
b.Highlighter.HighlightMatches(b, 0, b.End().Y)
b.Highlighter.Highlight(b, 0, b.End().Y)
screen.Redraw()
}()
}
Expand Down
10 changes: 10 additions & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ func SliceStartStr(str string, index int) string {
return str[:totalSize]
}

// SliceStartEnd combines SliceStart and SliceEnd into one
func SliceStartEnd(slc []byte, start int, end int) []byte {
return SliceEnd(SliceStart(slc, end), start)
}

// SliceStartEndStr is the same as SliceStartEnd but for strings
func SliceStartEndStr(str string, start int, end int) string {
return SliceEndStr(SliceStartStr(str, end), start)
}

// SliceVisualEnd will take a byte slice and slice off the start
// up to a given visual index. If the index is in the middle of a
// rune the number of visual columns into the rune will be returned
Expand Down
Loading