syntax

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 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(
	source core.Source, 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

HasHighlightQuery reports whether a highlight query ships for lang

func IndentForNewline

func IndentForNewline(args IndentForNewlineArgs) (string, bool)

IndentForNewline returns syntax-aware indentation for a newline after Pos

func ParentNodeEnd added in v0.1.13

func ParentNodeEnd(args SelectionArgs) (int, bool)

ParentNodeEnd returns the end of the innermost named node at the cursor, which is where a syntax-aware tab jumps to; false means no node was found, which is not the same as a node whose end the cursor already sits on

func SupportedLanguages

func SupportedLanguages() []string

SupportedLanguages lists the languages with bundled highlighters

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(src core.Source) []highlight.Span

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

type FindSurroundPairArgs added in v0.2.0

type FindSurroundPairArgs struct {
	Source core.Source
	Cursor int
	Skip   int
}

FindSurroundPairArgs identifies the enclosing pair to find: the Skip-th pair around Cursor, in any bracket style

type FindSurroundPairForArgs added in v0.2.0

type FindSurroundPairForArgs struct {
	Text   string
	Lang   string
	Cursor int
	Char   rune
	Skip   int
}

FindSurroundPairForArgs identifies the enclosing bracket pair to find: the Skip-th pair matching Char around Cursor

type FindTextObjectArgs added in v0.2.0

type FindTextObjectArgs struct {
	Text   string
	Lang   string
	Cursor int
	Char   rune
	Inside bool
}

FindTextObjectArgs identifies the textobject to find: the kind selected by Char at Cursor, taken inner (Inside) or whole

type IndentForNewlineArgs added in v0.2.0

type IndentForNewlineArgs struct {
	Text  core.Rope
	Lang  string
	Line  int
	Pos   int
	Style core.IndentStyle
}

IndentForNewlineArgs carries the document position and style used to compute indentation for a new line

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(args FindSurroundPairArgs) (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(args FindSurroundPairForArgs) (Range, bool)

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

func FindTextObject

func FindTextObject(args FindTextObjectArgs) (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