Documentation
¶
Overview ¶
Package syntax incrementally tokenizes TextMate grammars and colors their scopes with VS Code themes. Documents retain line states and token buffers.
Index ¶
- Variables
- func ReleaseGrammarCache()
- type Capture
- type Color
- type Definitions
- type Document
- func (d *Document) Captures() []Capture
- func (d *Document) Close()
- func (d *Document) CloseKeepingGrammar(grace time.Duration)
- func (d *Document) Language() string
- func (d *Document) Tokens(theme *Theme, definitions *Definitions) []Token
- func (d *Document) Update[V piecetree.Value](filename string, value V) error
- func (d *Document) UpdateRange[V piecetree.Value](filename string, value V, start, oldEnd, newEnd int) error
- func (d *Document) UpdateSnapshot(filename string, source piecetree.Snapshot) error
- type FontStyle
- type Painter
- type Style
- type Theme
- type Token
Constants ¶
This section is empty.
Variables ¶
var BuiltinThemeIDs = [...]string{"monokai", "dark-plus", "light-plus"}
Functions ¶
func ReleaseGrammarCache ¶
func ReleaseGrammarCache()
ReleaseGrammarCache forgets shared lookup entries. Active documents keep their grammar, line states and captures.
Types ¶
type Capture ¶
Capture is a render-neutral UTF-8 byte range. Scopes preserves the full TextMate scope stack; Capture is its coarse category for editor behavior.
type Definitions ¶
type Definitions struct {
Captures map[string]string `json:"captures"`
SourceScopes map[string]string `json:"sourceScopes"`
}
Definitions maps lexical token categories to TextMate scopes. The longest capture prefix wins, so function.method.call can inherit function.method.
func DefaultDefinitions ¶
func DefaultDefinitions() *Definitions
func ParseDefinitions ¶
func ParseDefinitions(data []byte) (*Definitions, error)
func (*Definitions) Scope ¶
func (d *Definitions) Scope(capture string) string
func (*Definitions) WithOverrides ¶
func (d *Definitions) WithOverrides(overrides *Definitions) *Definitions
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document caches each line's ending state and tokens. Updates tokenize from the first changed line until the unchanged suffix has the same start state. Its buffers are reused; a Document belongs to one worker.
func (*Document) CloseKeepingGrammar ¶ added in v0.1.11
CloseKeepingGrammar releases the document and lets another document reuse its compiled grammar across GCs. Only the most recently closed grammar stays warm.
func (*Document) Tokens ¶
func (d *Document) Tokens(theme *Theme, definitions *Definitions) []Token
Tokens recolors cached scopes. Neither theme changes nor identical updates invoke the tokenizer. The unchanged source/theme path allocates no memory.
func (*Document) Update ¶
Update detects file extensions or language IDs. Unknown languages stay plain.
type Painter ¶
type Painter struct {
// contains filtered or unexported fields
}
Painter resolves lexical scopes locally, independent of the tokenizer.
type Theme ¶
Theme is immutable after loading and can be shared by multiple documents.
func BuiltinTheme ¶
func (*Theme) LookupColor ¶
LookupColor distinguishes an omitted color from an explicitly transparent one.