lang

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package lang provides a language registry mapping file extensions to tree-sitter languages and their embedded query files.

Index

Constants

This section is empty.

Variables

View Source
var Languages = map[string]*Language{}

Languages maps language names to their configuration. Populated by init() functions in per-language files.

Functions

func CollapseWhitespace

func CollapseWhitespace(s string) string

CollapseWhitespace replaces runs of whitespace with a single space and trims.

func ForExtension

func ForExtension(ext string) string

ForExtension returns the language name for a file extension, or "" if unsupported.

func NodeText

func NodeText(node *sitter.Node, source []byte) string

NodeText returns the source text of a tree-sitter node.

Types

type Language

type Language struct {
	Name       string
	Extensions []string

	// FindMethodClass returns the enclosing class name if a @definition.function
	// is actually a method (Python/Ruby style). Returns "" if not a method.
	FindMethodClass func(node *sitter.Node, source []byte) string

	// FindReceiverType returns the receiver type name for a @definition.method
	// node (Go style). Returns "" if not applicable.
	FindReceiverType func(node *sitter.Node, source []byte) string

	// ExtractSignature returns a signature string for a definition node.
	ExtractSignature func(node *sitter.Node, kind model.SymbolKind, source []byte) string

	// FindEnclosingDef returns the qualified name of the enclosing function/method
	// for a call-site node (e.g., "MyType.Method" or "funcName").
	// Returns "" if the call is at top-level or inside an anonymous function.
	FindEnclosingDef func(node *sitter.Node, source []byte) string

	// FindEnclosingType returns the type name that owns a field/member node
	// (e.g. the struct or class containing a field declaration). Returns ""
	// if the node is not inside a named type definition.
	FindEnclosingType func(node *sitter.Node, source []byte) string
	// contains filtered or unexported fields
}

Language holds tree-sitter configuration for a supported language.

func (*Language) GetLanguage

func (l *Language) GetLanguage() *sitter.Language

GetLanguage returns the tree-sitter Language pointer.

func (*Language) GetTagQuery

func (l *Language) GetTagQuery() (*sitter.Query, error)

GetTagQuery returns the compiled tree-sitter query (safe to share across goroutines).

func (*Language) NewParser

func (l *Language) NewParser() *sitter.Parser

NewParser creates a fresh tree-sitter parser for this language. Each goroutine must use its own parser (not thread-safe).

Jump to

Keyboard shortcuts

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