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

lang

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 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
	// 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