Help us shape the future of Go! Take the 2026 Go Developer Survey

syntax

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package syntax wraps tree-sitter: incremental parsing and highlight spans. All CGo is confined here; the editor sees only the editor.Syntax interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Highlighter

type Highlighter struct {
	// contains filtered or unexported fields
}

Highlighter implements editor.Syntax for one buffer.

func New

func New(path string, src []byte) *Highlighter

New returns a highlighter for the file at path, or nil if the language is not supported.

func (*Highlighter) Close added in v0.6.1

func (h *Highlighter) Close()

Close frees the tree-sitter C objects — go-tree-sitter has no finalizers, so an unclosed Highlighter leaks native memory on every tab close.

func (*Highlighter) Edit

func (h *Highlighter) Edit(startOff, oldEndOff, newEndOff int, start, oldEnd, newEnd [2]int)

Edit implements editor.Syntax: feed the change to the old tree and mark it for lazy reparse on the next Spans call.

func (*Highlighter) Expand

func (h *Highlighter) Expand(src []byte, lo, hi int) (int, int, bool)

Expand implements editor.Syntax: the smallest named node strictly containing [lo, hi) — structural selection.

func (*Highlighter) Folds added in v0.14.0

func (h *Highlighter) Folds(src []byte, startOff, endOff int) [][2]int

Folds implements editor.Folder: fold regions (startLine, endLine) for the outermost multi-line named nodes starting within [startOff, endOff), sorted by start line. "Outermost" per start line: DFS visits parents first, so the first node claiming a line wins.

func (*Highlighter) Spans

func (h *Highlighter) Spans(src []byte, startOff, endOff int) []editor.HLSpan

Spans implements editor.Syntax: reparse if stale, then query the visible byte range only.

Directories

Path Synopsis
Package tsdockerfile vendors tree-sitter-dockerfile v0.2.0 (github.com/camdencheek/tree-sitter-dockerfile, MIT — see LICENSE): upstream's Go bindings module declares a broken module path and targets the old smacker tree-sitter library.
Package tsdockerfile vendors tree-sitter-dockerfile v0.2.0 (github.com/camdencheek/tree-sitter-dockerfile, MIT — see LICENSE): upstream's Go bindings module declares a broken module path and targets the old smacker tree-sitter library.
Package tsmarkdown vendors tree-sitter-markdown v0.5.3 (github.com/tree-sitter-grammars/tree-sitter-markdown, MIT — see LICENSE): upstream ships no Go bindings.
Package tsmarkdown vendors tree-sitter-markdown v0.5.3 (github.com/tree-sitter-grammars/tree-sitter-markdown, MIT — see LICENSE): upstream ships no Go bindings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL