mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-09-03 07:37:13 -04:00
Only include syntax layers specified by build tags; lazy-load syntax layers
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package syntax
|
||||
|
||||
import "sync"
|
||||
|
||||
var syntaxMap = make(map[string]*lazySyntax)
|
||||
|
||||
type lazySyntax struct {
|
||||
once sync.Once
|
||||
syntaxLayer []byte
|
||||
init func() []byte
|
||||
}
|
||||
|
||||
func (ls *lazySyntax) get() []byte {
|
||||
ls.once.Do(func() {
|
||||
ls.syntaxLayer = ls.init()
|
||||
})
|
||||
return ls.syntaxLayer
|
||||
}
|
||||
|
||||
func Get(id string) []byte {
|
||||
if syntax, exists := syntaxMap[id]; exists {
|
||||
return syntax.get()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
//go:build stxGo
|
||||
|
||||
package syntax
|
||||
|
||||
func GetGo() []byte {
|
||||
return []byte(`filetype: go
|
||||
func init() {
|
||||
syntaxMap["go"] = &lazySyntax{init: func() []byte {
|
||||
return []byte(`filetype: go
|
||||
|
||||
detect:
|
||||
filename: "\\.go$"
|
||||
@@ -67,4 +70,5 @@ rules:
|
||||
rules:
|
||||
- todo: "(TODO|XXX|FIXME):?"
|
||||
`)
|
||||
}}
|
||||
}
|
||||
Reference in New Issue
Block a user