syntax

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package syntax provides Tree-sitter based syntax highlighting. It tokenizes source text using Tree-sitter grammars and highlight queries, returning scope-named spans that map directly to theme scopes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindMatchingBracket

func FindMatchingBracket(text, lang string, cursorPos int) (int, bool)

FindMatchingBracket returns the char position of the bracket matching the one at cursorPos, using the parse tree so string/comment brackets don't falsely match

func HasHighlightQuery

func HasHighlightQuery(lang string) bool

func IndentForNewline

func IndentForNewline(
	text core.Rope, lang string, line, pos int, style core.IndentStyle,
) (string, bool)

IndentForNewline returns syntax-aware indentation for a newline after pos

func SupportedLanguages

func SupportedLanguages() []string

Types

type Cache

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

Cache holds Tree-sitter parser and query caches for a UI context

func NewSyntaxCache

func NewSyntaxCache() *Cache

NewSyntaxCache returns an initialized SyntaxCache

func (*Cache) Tokenize

func (sc *Cache) Tokenize(text, lang string) []highlight.Span

Tokenize parses text for lang and returns highlight spans with theme scope names. Tree-sitter is tried first; Chroma is the fallback

type Range

type Range struct {
	From int
	To   int
}

Range is a character range selected by syntax

func ExpandSelection

func ExpandSelection(args SelectionArgs) (Range, bool)

ExpandSelection returns the smallest Tree-sitter named node that strictly contains the current range, or the smallest named node at the cursor for an empty range

func FindSurroundPair

func FindSurroundPair(text, lang string, cursor, skip int) (Range, bool)

FindSurroundPair returns the Range of the skip-th bracket pair enclosing cursor, or (Range{}, false) if none exists at that depth

func FindSurroundPairFor

func FindSurroundPairFor(
	text, lang string, cursor int, ch rune, skip int,
) (Range, bool)

FindSurroundPairFor returns the Range of the skip-th enclosing pair matching ch (either bracket of the pair), or (Range{}, false) if none exists

func FindTextObject

func FindTextObject(
	text, lang string, cursor int, ch rune, inside bool,
) (Range, bool)

FindTextObject finds the innermost textobject at cursor for lang. inside returns the node's inner content (delimiters stripped) vs its full range

func ShrinkSelection

func ShrinkSelection(args SelectionArgs) (Range, bool)

ShrinkSelection returns the largest Tree-sitter named node under the cursor that is strictly contained by the current range

type SelectionArgs

type SelectionArgs struct {
	Text   string
	Lang   string
	Cursor int
	Range  Range
}

SelectionArgs describes an editor range for syntax selection

Jump to

Keyboard shortcuts

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