Source File
highlighter.go
Belonging Package
src.elv.sh/pkg/edit/highlight
package highlightimport ()const latesBufferSize = 128// Highlighter is a code highlighter that can deliver results asynchronously.type Highlighter struct {cfg Configstate statelates chan struct{}}type state struct {sync.Mutexcode stringstyledCode ui.Texterrors []error}func ( Config) *Highlighter {return &Highlighter{, state{}, make(chan struct{}, latesBufferSize)}}// Get returns the highlighted code and static errors found in the code.func ( *Highlighter) ( string) (ui.Text, []error) {.state.Lock()defer .state.Unlock()if == .state.code {return .state.styledCode, .state.errors}:= func( ui.Text) {.state.Lock()if .state.code != {// Late result was delivered after code has changed. Unlock and// return..state.Unlock()return}.state.styledCode =// The channel send below might block, so unlock the state first..state.Unlock().lates <- struct{}{}}, := highlight(, .cfg, ).state.code =.state.styledCode =.state.errors =return ,}// LateUpdates returns a channel for notifying late updates.func ( *Highlighter) () <-chan struct{} {return .lates}
The pages are generated with Golds v0.2.8-preview. (GOOS=darwin GOARCH=arm64)