Skip to content

Commit

Permalink
view: Incremental adjustments done to syntax highlighting
Browse files Browse the repository at this point in the history
Requires pulling the latest changes from github.com/quarnster/parser
and github.com/quarnster/util
  • Loading branch information
quarnster committed Oct 30, 2013
1 parent aab8b04 commit 56fc7c8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ Done!
cd ../frontend/termbox
go run main.go

Press Ctrl+Q to exit.

# To use qt5 frontend

cd ../frontend/qt5
Expand Down
11 changes: 8 additions & 3 deletions backend/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ type (
}

SyntaxHighlighter interface {
Adjust(position, delta int)
ScopeExtent(point int) text.Region
ScopeName(point int) string
Flatten(viewport text.Region) []NamedRegion
// Flatten() []NamedRegion
}

nodeHighlighter struct {
Expand Down Expand Up @@ -129,6 +130,10 @@ func (nh *nodeHighlighter) flatten(in []NamedRegion, scopename string, node *par
return in
}

func (nh *nodeHighlighter) Flatten(viewport text.Region) []NamedRegion {
return nh.flatten(nil, "", nh.rootNode)
func (nh *nodeHighlighter) Adjust(position, delta int) {
nh.rootNode.Adjust(position, delta)
}

// func (nh *nodeHighlighter) Flatten() []NamedRegion {
// return nh.flatten(nil, "", nh.rootNode)
// }
3 changes: 2 additions & 1 deletion backend/render/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ type (
Colour color.RGBA

// The Flavour struct contains the specific settings
// used to style a particular section of text.
// used to style a particular Region.
Flavour struct {
Background Colour
Foreground Colour
Font Font
Flags ViewRegionFlags
}

// The Recipe type groups text.RegionSets by their Flavour.
Expand Down
1 change: 1 addition & 0 deletions backend/render/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
FOREGROUND
SELECTION
HIGHLIGHT
DRAW_TEXT
DEFAULT ViewRegionFlags = 0
)

Expand Down
23 changes: 16 additions & 7 deletions backend/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,25 @@ func (v *View) setBuffer(b Buffer) error {
}
v.buffer = b
// TODO(q): Dynamically load the correct syntax file
b.AddCallback(func(_ Buffer, a, b int) {
v.flush(a, b)
b.AddCallback(func(_ Buffer, position, delta int) {
v.flush(position, delta)
})
return nil
}

func (v *View) flush(a, b int) {
func (v *View) flush(position, delta int) {
func() {
v.lock.Lock()
defer v.lock.Unlock()

e := Prof.Enter("view.flush")
defer e.Exit()
v.selection.Adjust(a, b)
v.selection.Adjust(position, delta)
if v.syntax != nil {
v.syntax.Adjust(position, delta)
}
for k, v2 := range v.regions {
v2.Regions.Adjust(a, b)
v2.Regions.Adjust(position, delta)
v.regions[k] = v2
}
}()
Expand All @@ -129,6 +132,7 @@ func (v *View) flush(a, b int) {

func (v *View) parsethread() {
pc := 0
lastParse := -1
doparse := func() {
p := Prof.Enter("syntax.parse")
defer p.Exit()
Expand All @@ -155,15 +159,20 @@ func (v *View) parsethread() {
} else {
v.lock.Lock()
defer v.lock.Unlock()
v.syntax = syn
// Only set if it isn't invalid already, otherwise the
// current syntax highlighting will be more accurate
// as it will have had incremental adjustments done to it
if v.buffer.ChangeCount() == lastParse {
v.syntax = syn
}
}
}
}
lastParse := -1
for pr := range v.reparseChan {
if cc := v.buffer.ChangeCount(); lastParse != cc || pr.forced {
lastParse = cc
doparse()
v.Settings().Set("lime.syntax.updated", lastParse)
}
}
}
Expand Down

0 comments on commit 56fc7c8

Please sign in to comment.