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 ¶
- func FindMatchingBracket(text, lang string, cursorPos int) (int, bool)
- func HasHighlightQuery(lang string) bool
- func IndentForNewline(text core.Rope, lang string, line, pos int, style core.IndentStyle) (string, bool)
- func ParentNodeEnd(args SelectionArgs) (int, bool)
- func SupportedLanguages() []string
- type Cache
- type Range
- func ExpandSelection(args SelectionArgs) (Range, bool)
- func FindSurroundPair(text, lang string, cursor, skip int) (Range, bool)
- func FindSurroundPairFor(text, lang string, cursor int, ch rune, skip int) (Range, bool)
- func FindTextObject(text, lang string, cursor int, ch rune, inside bool) (Range, bool)
- func ShrinkSelection(args SelectionArgs) (Range, bool)
- type SelectionArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindMatchingBracket ¶
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 ¶
HasHighlightQuery reports whether a highlight query ships for lang
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 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
type Range ¶
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 ¶
FindSurroundPair returns the Range of the skip-th bracket pair enclosing cursor, or (Range{}, false) if none exists at that depth
func FindSurroundPairFor ¶
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 ¶
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