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
4c9ba6a
highlighter: Perform sliceStart() in nested region only once
JoeKar Jan 17, 2024
c2820ef
highlighter: Rename firstLoc/Region into nestedLoc/Region for readabi…
JoeKar Jan 17, 2024
842c0c9
highlighter: gofmt
JoeKar Jan 17, 2024
9a486dd
highlighter: Remove canMatchEnd since it's not really useful
JoeKar Jan 17, 2024
b2a0109
highlighter: Combine HighlightStates and HighlightMatches to Highlight
JoeKar Jan 17, 2024
b84310a
highlighter: Remove statesOnly since it's not needed any longer
JoeKar Jan 17, 2024
904caa7
highlight: Remove duplicated util code
JoeKar Jan 28, 2024
6841367
highlighter: Rework of matching approach to speed up the processing
JoeKar Jan 25, 2024
d30084e
highlighter: Add disabled debug logs for faster analysis
JoeKar Jan 29, 2024
7092f01
highlighter: Fix regression in nested regions/patterns
JoeKar Feb 13, 2024
e33ec52
highlighter: Small corrections
JoeKar Feb 16, 2024
535a090
highlighter: Fix regression in nested regions/patterns (2nd)
JoeKar Feb 16, 2024
80d010c
highlighter: Fix `limitGroup` behavior of regions
JoeKar Feb 23, 2024
1c9dbbb
highlighter: Add capability to remove already captured groups
JoeKar Feb 27, 2024
f0711b9
highlighter: Add capability to remove childrens of already captured g…
JoeKar Mar 6, 2024
5b25105
highlighter: Add capability to add already removed groups again
JoeKar Mar 7, 2024
c3fbf71
highlighter: Handle `h.lastRegion` within `h.highlight()` only
JoeKar Apr 9, 2024
89216ed
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
Loading