treesitter

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

@index Language-specific grammar specifications and discovery hooks for the Tree-sitter parser.

@index Language-specific graph enrichment interfaces and shared parser context helpers.

@index Tree-sitter AST parser based on tags.scm queries.

Index

Constants

This section is empty.

Variables

View Source
var CSpec = &LangSpec{
	Name:             "c",
	FunctionTypes:    []string{"function_definition"},
	ClassTypes:       []string{"struct_specifier"},
	ImportTypes:      []string{"preproc_include"},
	CallTypes:        []string{"call_expression"},
	TestPrefix:       "test_",
	PackageDiscovery: NoopPackageDiscovery{},
}
View Source
var CppSpec = &LangSpec{
	Name:             "cpp",
	FunctionTypes:    []string{"function_definition"},
	ClassTypes:       []string{"class_specifier", "struct_specifier"},
	InterfaceTypes:   []string{},
	ImportTypes:      []string{"preproc_include"},
	CallTypes:        []string{"call_expression"},
	TestPrefix:       "TEST",
	PackageDiscovery: NoopPackageDiscovery{},
}
View Source
var GoSpec = &LangSpec{
	Name:             "go",
	FunctionTypes:    []string{"function_declaration", "method_declaration"},
	ClassTypes:       []string{"type_declaration"},
	InterfaceTypes:   []string{},
	ImportTypes:      []string{"import_declaration", "import_spec"},
	CallTypes:        []string{"call_expression"},
	TestPrefix:       "Test",
	PackageNodeType:  "package_clause",
	Semantics:        GoSemantics{},
	PackageDiscovery: GoPackageDiscovery{},
}
View Source
var JavaScriptSpec = &LangSpec{
	Name:             "javascript",
	FunctionTypes:    []string{"function_declaration", "method_definition", "arrow_function"},
	ClassTypes:       []string{"class_declaration"},
	ImportTypes:      []string{"import_statement"},
	CallTypes:        []string{"call_expression"},
	TestPrefix:       "test",
	Semantics:        JavaScriptSemantics{},
	PackageDiscovery: JavaScriptPackageDiscovery{},
}
View Source
var JavaSpec = &LangSpec{
	Name:             "java",
	FunctionTypes:    []string{"method_declaration", "constructor_declaration"},
	ClassTypes:       []string{"class_declaration"},
	InterfaceTypes:   []string{"interface_declaration"},
	ImportTypes:      []string{"import_declaration"},
	CallTypes:        []string{"method_invocation"},
	TestPrefix:       "test",
	Semantics:        JavaSemantics{},
	PackageDiscovery: JavaPackageDiscovery{},
}
View Source
var KotlinSpec = &LangSpec{
	Name:             "kotlin",
	FunctionTypes:    []string{"function_declaration"},
	ClassTypes:       []string{"class_declaration", "object_declaration"},
	InterfaceTypes:   []string{"interface_declaration"},
	ImportTypes:      []string{"import_header"},
	CallTypes:        []string{"call_expression"},
	TestPrefix:       "test",
	Semantics:        KotlinSemantics{},
	PackageDiscovery: KotlinPackageDiscovery{},
}
View Source
var LuaSpec = &LangSpec{
	Name:             "lua",
	FunctionTypes:    []string{"function_statement"},
	ClassTypes:       []string{},
	ImportTypes:      []string{},
	CallTypes:        []string{"function_call"},
	TestPrefix:       "test_",
	PackageDiscovery: NoopPackageDiscovery{},
}
View Source
var PHPSpec = &LangSpec{
	Name:             "php",
	FunctionTypes:    []string{"function_definition", "method_declaration"},
	ClassTypes:       []string{"class_declaration"},
	InterfaceTypes:   []string{"interface_declaration"},
	ImportTypes:      []string{"namespace_use_declaration"},
	CallTypes:        []string{"function_call_expression", "method_call_expression"},
	TestPrefix:       "test",
	PackageDiscovery: NoopPackageDiscovery{},
}
View Source
var PythonSpec = &LangSpec{
	Name:             "python",
	FunctionTypes:    []string{"function_definition"},
	ClassTypes:       []string{"class_definition"},
	ImportTypes:      []string{"import_statement", "import_from_statement"},
	CallTypes:        []string{"call"},
	TestPrefix:       "test_",
	Semantics:        PythonSemantics{},
	PackageDiscovery: PythonPackageDiscovery{},
}
View Source
var RubySpec = &LangSpec{
	Name:             "ruby",
	FunctionTypes:    []string{"method"},
	ClassTypes:       []string{"class"},
	ImportTypes:      []string{"call"},
	CallTypes:        []string{"call"},
	TestPrefix:       "test_",
	PackageDiscovery: NoopPackageDiscovery{},
}
View Source
var RustSpec = &LangSpec{
	Name:             "rust",
	FunctionTypes:    []string{"function_item"},
	ClassTypes:       []string{"struct_item", "enum_item"},
	InterfaceTypes:   []string{"trait_item"},
	ImportTypes:      []string{"use_declaration"},
	CallTypes:        []string{"call_expression"},
	TestPrefix:       "test_",
	TestAttributes:   []string{"test"},
	ImplTypes:        []string{"impl_item"},
	Semantics:        RustSemantics{},
	PackageDiscovery: NoopPackageDiscovery{},
}
View Source
var TypeScriptSpec = &LangSpec{
	Name:             "typescript",
	FunctionTypes:    []string{"function_declaration", "method_definition", "arrow_function"},
	ClassTypes:       []string{"class_declaration"},
	ImportTypes:      []string{"import_statement"},
	CallTypes:        []string{"call_expression"},
	TestPrefix:       "test",
	Semantics:        TypeScriptSemantics{},
	PackageDiscovery: TypeScriptPackageDiscovery{},
}

Functions

func PackageEdgesFor

func PackageEdgesFor(semantics LanguageSemantics, ctx PackageContext) []graph.Edge

PackageEdgesFor exposes package-level semantics to callers outside the treesitter package. @intent let build/update orchestration reuse optional package-level enrichment hooks.

func WithFilePackages

func WithFilePackages(ctx context.Context, packages map[string]string) context.Context

WithFilePackages stores repo-local file-path to canonical import-path mappings in ctx. @intent let parsers stamp package-less languages with a deterministic file-level package prefix.

func WithGoImportPackages

func WithGoImportPackages(ctx context.Context, packages map[string]string) context.Context

WithGoImportPackages stores repo-local Go import-path to package-name mappings in ctx. @intent preserve compatibility for callers using the original Go-specific helper.

func WithImportPackages

func WithImportPackages(ctx context.Context, packages map[string]string) context.Context

WithImportPackages stores repo-local import-path to package-name mappings in ctx. @intent let build/update provide package-clause-aware import normalization without widening parser interfaces.

Types

type CallRewriteContext

type CallRewriteContext struct {
	Root     *sitter.Node
	Node     *sitter.Node
	Content  []byte
	FilePath string
	Callee   string
	Line     int
}

CallRewriteContext carries one extracted call into a language-specific rewrite hook. @intent provide enough call-site metadata for languages with assignment or dispatch-sensitive call names.

type CallRewriteSemantics

type CallRewriteSemantics interface {
	CallRewriter(ctx SemanticContext) CallRewriter
}

CallRewriteSemantics provides optional call-site rewriting hooks. @intent avoid forcing languages without call rewrite needs to implement no-op methods.

type CallRewriter

type CallRewriter interface {
	RewriteCall(ctx CallRewriteContext) string
}

CallRewriter optionally rewrites raw callee names before call edges are emitted. @intent let language specs recover dynamic dispatch targets without adding language branches to Walker.

type CommentBlock

type CommentBlock = ingest.CommentBlock

CommentBlock records one contiguous comment region discovered in source. @intent preserve raw comment text with source line bounds for later annotation binding

type CommentContext

type CommentContext struct {
	Root     *sitter.Node
	Content  []byte
	FilePath string
	Nodes    []graph.Node
}

CommentContext carries file-level parse state into language-specific comment extraction hooks. @intent expose AST and file content so languages can surface docstrings as comment blocks.

type CommentSemantics

type CommentSemantics interface {
	AdditionalComments(ctx CommentContext) []CommentBlock
}

CommentSemantics provides optional comment extraction hooks beyond raw AST comments. @intent let languages contribute docstrings or similar constructs without Walker language branches.

type DefinitionContext

type DefinitionContext struct {
	Definition       *sitter.Node
	DefinitionType   string
	Name             string
	QualifiedName    string
	Root             *sitter.Node
	Package          string
	ImplementedTypes []string
	Content          []byte
	FilePath         string
}

DefinitionContext carries one matched definition into a language-specific enrichment hook. @intent expose definition-local AST state so languages can derive extra edges and metadata.

type DefinitionNameSemantics

type DefinitionNameSemantics interface {
	DefinitionName(ctx DefinitionContext) string
}

DefinitionNameSemantics provides optional definition-name normalization hooks. @intent let languages normalize captured definition names before node and edge fingerprints are emitted.

type DefinitionResult

type DefinitionResult struct {
	Interfaces []interfaceInfo
	Edges      []graph.Edge
}

DefinitionResult carries language-specific enrichment derived from a definition. @intent keep Walker generic while still allowing languages to accumulate interfaces and edges.

type DefinitionSemantics

type DefinitionSemantics interface {
	EnrichDefinition(ctx DefinitionContext) DefinitionResult
}

DefinitionSemantics provides optional per-definition enrichment hooks. @intent let languages enrich parsed definitions without adding language branches to Walker.

type GoPackageDiscovery

type GoPackageDiscovery struct{}

GoPackageDiscovery discovers repo-local Go packages from go.mod and package clauses. @intent model a Go import path as one package node that contains every non-test file in that package. @index Go package discovery implementation using go.mod and package statements.

func (GoPackageDiscovery) DiscoverPackages

DiscoverPackages returns package metadata keyed by import path. @intent walk the repository to identify Go packages and their source files.

type GoSemantics

type GoSemantics struct{}

GoSemantics recovers Go-specific relationships that are not explicit call edges. @intent encapsulate Go-specific graph enrichment logic such as interface implementation discovery.

func (GoSemantics) AdditionalEdges

func (GoSemantics) AdditionalEdges(ctx SemanticContext) []graph.Edge

AdditionalEdges adds Go structural and assertion-based implementation edges. @intent identify "implements" relationships using both structural and explicit compile-time assertions.

func (GoSemantics) CallRewriter

func (GoSemantics) CallRewriter(ctx SemanticContext) CallRewriter

CallRewriter returns Go call-name enrichment based on type assertion bindings. @intent preserve interface dispatch context for calls made through asserted variables.

func (GoSemantics) EnrichDefinition

func (GoSemantics) EnrichDefinition(ctx DefinitionContext) DefinitionResult

EnrichDefinition extracts Go-only interface method metadata and struct embedding edges. @intent move Go definition enrichment out of Walker and behind an optional semantics hook.

func (GoSemantics) PackageEdges

func (GoSemantics) PackageEdges(ctx PackageContext) []graph.Edge

PackageEdges adds Go structural implementation edges using package-wide method and interface sets. @intent support Go's implicit structural typing when interfaces and methods are split across files in one package.

type JavaPackageDiscovery

type JavaPackageDiscovery struct{}

JavaPackageDiscovery discovers Java packages from package declarations. @intent map JVM package declarations to package nodes so Java imports can bind to semantic package targets.

func (JavaPackageDiscovery) DiscoverPackages

DiscoverPackages returns Java package metadata keyed by package declaration. @intent group Java source files by declared package so package nodes reflect actual import targets rather than directory guesses.

type JavaScriptPackageDiscovery

type JavaScriptPackageDiscovery struct{}

JavaScriptPackageDiscovery discovers package nodes for JavaScript source trees. @intent map JavaScript source directories to package.json-based import paths.

func (JavaScriptPackageDiscovery) DiscoverPackages

DiscoverPackages returns JavaScript package metadata keyed by import path. @intent create package nodes for JavaScript directories using package.json-derived import paths.

type JavaScriptSemantics

type JavaScriptSemantics struct{}

JavaScriptSemantics recovers class inheritance edges from JavaScript class heritage clauses. @intent emit extends relationships for JavaScript classes using the same heritage parsing model as TypeScript.

func (JavaScriptSemantics) AdditionalEdges

func (JavaScriptSemantics) AdditionalEdges(ctx SemanticContext) []graph.Edge

AdditionalEdges adds JavaScript extends edges from class heritage clauses. @intent capture JavaScript class inheritance while ignoring TypeScript-only interface semantics.

func (JavaScriptSemantics) ImplementedTypes

func (JavaScriptSemantics) ImplementedTypes(ctx DefinitionContext) []string

ImplementedTypes returns query-captured relationships unchanged for JavaScript. @intent satisfy shared relationship normalization without inventing JS interface semantics.

type JavaSemantics

type JavaSemantics struct{}

JavaSemantics recovers Java extends and implements relationships from class declarations. @intent emit Java hierarchy edges directly from class declaration syntax so type resolution can bind them later.

func (JavaSemantics) AdditionalEdges

func (JavaSemantics) AdditionalEdges(ctx SemanticContext) []graph.Edge

AdditionalEdges adds Java extends and implements edges from class declarations. @intent capture Java class hierarchy semantics with package-qualified child names when available.

func (JavaSemantics) CallRewriter

func (JavaSemantics) CallRewriter(ctx SemanticContext) CallRewriter

CallRewriter returns a conservative Java receiver-type rewriter. @intent rewrite member-call chains only when local/field declarations prove the receiver types.

func (JavaSemantics) ImplementedTypes

func (JavaSemantics) ImplementedTypes(ctx DefinitionContext) []string

ImplementedTypes normalizes query-captured implements targets through Java hierarchy parsing. @intent keep generic-safe relationship extraction consistent between direct hierarchy parsing and query captures.

type KotlinPackageDiscovery

type KotlinPackageDiscovery struct{}

KotlinPackageDiscovery discovers Kotlin packages from package headers. @intent map Kotlin package headers to package nodes so imports and package containment use declared package names.

func (KotlinPackageDiscovery) DiscoverPackages

DiscoverPackages returns Kotlin package metadata keyed by package header. @intent group Kotlin source files by declared package so package nodes reflect Kotlin import targets.

type KotlinSemantics

type KotlinSemantics struct{}

KotlinSemantics recovers Kotlin superclass and interface relationships from class declarations. @intent emit Kotlin hierarchy edges from declaration text while preserving package-qualified child names.

func (KotlinSemantics) AdditionalEdges

func (KotlinSemantics) AdditionalEdges(ctx SemanticContext) []graph.Edge

AdditionalEdges adds Kotlin inherits and implements edges from class declarations. @intent capture Kotlin supertype relationships by parsing the declaration head after ':'.

func (KotlinSemantics) CallRewriter

func (KotlinSemantics) CallRewriter(ctx SemanticContext) CallRewriter

CallRewriter returns a conservative Kotlin receiver-type rewriter. @intent rewrite member-call chains only when explicit property/value types prove the receiver chain.

func (KotlinSemantics) ImplementedTypes

func (KotlinSemantics) ImplementedTypes(ctx DefinitionContext) []string

ImplementedTypes normalizes Kotlin supertype interfaces through the same parsing path used for hierarchy edges. @intent keep declaration-time and query-time interface extraction aligned for Kotlin.

type LangSpec

type LangSpec struct {
	Name             string
	FunctionTypes    []string
	ClassTypes       []string
	InterfaceTypes   []string
	ImportTypes      []string
	CallTypes        []string
	TestPrefix       string
	TestAttributes   []string
	ImplTypes        []string
	ExtensionTypes   []string
	PackageNodeType  string
	Semantics        LanguageSemantics
	PackageDiscovery PackageDiscovery
}

LangSpec describes the Tree-sitter grammar shapes used to extract graph data for one language. @intent centralize language-specific AST node names, test conventions, and extraction hints

type LanguageSemantics

type LanguageSemantics interface {
	AdditionalEdges(ctx SemanticContext) []graph.Edge
}

LanguageSemantics provides optional language-specific graph enrichment hooks. @intent keep language-specific inference opt-in while the generic parser remains shared.

func SemanticsForLanguage

func SemanticsForLanguage(language string) LanguageSemantics

SemanticsForLanguage returns the configured semantics for a language name. @intent let non-parser orchestration reuse the centralized language semantics registry without local language switches.

type NodeTypeMapping

type NodeTypeMapping struct {
	ASTType  string
	NodeKind graph.NodeKind
}

NodeTypeMapping maps a Tree-sitter node type to an internal graph node kind. @intent describe how grammar-specific node names translate into model semantics

type NoopCallRewriter

type NoopCallRewriter struct{}

NoopCallRewriter leaves extracted callee names unchanged. @intent provide the default empty implementation for language specs without call rewrite rules.

func (NoopCallRewriter) RewriteCall

func (NoopCallRewriter) RewriteCall(ctx CallRewriteContext) string

RewriteCall returns the original callee unchanged. @intent satisfy CallRewriter for languages without additional call inference.

type NoopPackageDiscovery

type NoopPackageDiscovery struct{}

NoopPackageDiscovery is used by languages that do not yet provide package/module discovery. @intent provide a default no-op implementation of the PackageDiscovery interface.

func (NoopPackageDiscovery) DiscoverPackages

DiscoverPackages returns no package nodes for unsupported language hooks. @intent let callers reuse one package-discovery flow even when a language has no package model.

type NoopSemantics

type NoopSemantics struct{}

NoopSemantics is the default implementation for languages without extra inference. @intent provide a safe fallback semantics hook when a language does not define extra graph enrichment.

func (NoopSemantics) AdditionalEdges

func (NoopSemantics) AdditionalEdges(SemanticContext) []graph.Edge

AdditionalEdges returns no extra relationships for unsupported language hooks. @intent satisfy the LanguageSemantics interface with a no-op implementation.

type PackageContext

type PackageContext = ingest.PackageContext

PackageContext carries package-wide parse state into language-specific enrichment hooks. @intent expose aggregated nodes and interfaces for languages whose relationships span multiple files.

type PackageDiscovery

type PackageDiscovery interface {
	DiscoverPackages(ctx context.Context, opts PackageDiscoveryOptions) (map[string]PackageInfo, error)
}

PackageDiscovery is the optional language hook for building package/module nodes. @intent let each language define its own multi-file import model without changing the ingest workflow service.

func PackageDiscoveryOrDefault

func PackageDiscoveryOrDefault(spec *LangSpec) PackageDiscovery

PackageDiscoveryOrDefault returns the configured discovery hook for a language or a no-op implementation. @intent ensure callers always have a valid PackageDiscovery implementation to call during repository traversal

type PackageDiscoveryOptions

type PackageDiscoveryOptions = ingest.PackageDiscoveryOptions

PackageDiscoveryOptions carries repository traversal services into language package discovery. @intent keep language-specific discovery in LangSpec while reusing service include/exclude policies.

type PackageInfo

type PackageInfo = ingest.PackageInfo

PackageInfo describes a source package/module node discovered outside a single file parse. @intent let language specs model multi-file import targets without service-level language branches.

type PackageInterfaceInfo

type PackageInterfaceInfo = ingest.PackageInterfaceInfo

PackageInterfaceInfo captures one interface name plus its declared methods. @intent let package-level enrichment travel across package boundaries without exposing walker internals.

type PackageSemantics

type PackageSemantics interface {
	PackageEdges(ctx PackageContext) []graph.Edge
}

PackageSemantics provides optional package-level enrichment hooks across multiple files. @intent let languages derive relationships that require package-wide context without widening Walker's per-file parse path.

type ParseMetadata

type ParseMetadata = ingest.ParseMetadata

ParseMetadata carries extra language-specific parse metadata beyond nodes/edges/comments. @intent expose package-level enrichment inputs to build/update paths without changing the base parser contract.

type PythonPackageDiscovery

type PythonPackageDiscovery struct{}

PythonPackageDiscovery discovers repo-local Python packages from directory layout. @intent model Python import targets as directory-based package nodes so package contains/import edges can be resolved.

func (PythonPackageDiscovery) DiscoverPackages

DiscoverPackages returns Python package metadata keyed by dotted import path. @intent group Python source files by containing directory and support both __init__.py packages and implicit namespace packages.

type PythonSemantics

type PythonSemantics struct{}

PythonSemantics recovers Python structural relationships not emitted directly by queries. @intent emit inheritance edges and docstrings while keeping the generic walker language-agnostic.

func (PythonSemantics) AdditionalComments

func (PythonSemantics) AdditionalComments(ctx CommentContext) []CommentBlock

AdditionalComments adds Python docstrings as synthetic comment blocks. @intent surface docstrings through the same binder pipeline used for ordinary comments.

func (PythonSemantics) AdditionalEdges

func (PythonSemantics) AdditionalEdges(ctx SemanticContext) []graph.Edge

AdditionalEdges adds Python inherits edges for class definitions with superclasses. @intent capture Python class inheritance from the AST so type hierarchy queries work without query-only special cases.

type RelationshipSemantics

type RelationshipSemantics interface {
	ImplementedTypes(ctx DefinitionContext) []string
}

RelationshipSemantics provides optional per-definition relationship normalization hooks. @intent let languages normalize query-captured relationships through the same definition path.

type RustSemantics

type RustSemantics struct{}

RustSemantics normalizes Rust trait impl names beyond raw query captures. @intent keep trait implementation edges stable when impl headers contain paths or generic arguments.

func (RustSemantics) AdditionalEdges

func (RustSemantics) AdditionalEdges(SemanticContext) []graph.Edge

AdditionalEdges returns no Rust-only file-local edges beyond generic walker output. @intent satisfy LanguageSemantics while keeping Rust relationship normalization in definition hooks.

func (RustSemantics) CallRewriter

func (RustSemantics) CallRewriter(ctx SemanticContext) CallRewriter

CallRewriter normalizes Rust qualified trait path and UFCS calls into a stable resolver contract. @intent preserve exact trait path and optional concrete type information without changing generic walker logic.

func (RustSemantics) DefinitionName

func (RustSemantics) DefinitionName(ctx DefinitionContext) string

DefinitionName normalizes Rust impl target type names captured from impl headers. @intent keep impl_item class names stable when the captured type includes generic arguments.

func (RustSemantics) ImplementedTypes

func (RustSemantics) ImplementedTypes(ctx DefinitionContext) []string

ImplementedTypes normalizes trait names captured from Rust impl blocks. @intent strip generic arguments and preserve full path segments for trait implementation edges.

type SemanticContext

type SemanticContext struct {
	Root           *sitter.Node
	Content        []byte
	FilePath       string
	Package        string
	ImportPackages map[string]string
	Nodes          []graph.Node
	Interfaces     []interfaceInfo
}

SemanticContext carries parsed state into language-specific enrichment hooks. @intent avoid expanding Walker with one-off language branches as graph inference grows.

type TypeScriptPackageDiscovery

type TypeScriptPackageDiscovery struct{}

TypeScriptPackageDiscovery discovers package nodes for TypeScript source trees. @intent map TypeScript source directories to package.json- and tsconfig-based import paths.

func (TypeScriptPackageDiscovery) DiscoverPackages

DiscoverPackages returns TypeScript package metadata keyed by import path. @intent create package nodes for package.json paths and tsconfig alias paths that imports can target.

type TypeScriptSemantics

type TypeScriptSemantics struct{}

TypeScriptSemantics recovers class hierarchy edges from TypeScript heritage clauses. @intent emit extends and implements relationships for TypeScript classes without adding language branches to Walker.

func (TypeScriptSemantics) AdditionalEdges

func (TypeScriptSemantics) AdditionalEdges(ctx SemanticContext) []graph.Edge

AdditionalEdges adds TypeScript extends and implements edges from class heritage clauses. @intent capture TypeScript class hierarchy semantics directly from the parsed AST.

func (TypeScriptSemantics) CallRewriter

CallRewriter returns a conservative TypeScript receiver-type rewriter. @intent rewrite member-call chains only when explicit type annotations prove each hop.

func (TypeScriptSemantics) ImplementedTypes

func (TypeScriptSemantics) ImplementedTypes(ctx DefinitionContext) []string

ImplementedTypes normalizes query-captured implements targets through the TypeScript heritage parser. @intent keep explicit query captures and AST-derived hierarchy parsing on one normalization path.

type Walker

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

Walker parses source files with Tree-sitter and emits graph nodes, edges, and comments. @intent turn language-specific ASTs into the project's normalized code graph representation @mutates parser and query during one-time initialization in NewWalker

func NewWalker

func NewWalker(spec *LangSpec, opts ...WalkerOption) *Walker

NewWalker creates a Walker and initializes reusable Tree-sitter resources for one language. @intent amortize parser and query compilation cost across many file parses @mutates Walker.parser, Walker.query, Walker.logger @requires spec is non-nil and names a supported language @ensures returned Walker reuses one parser and optional compiled tags query

func (*Walker) Close

func (w *Walker) Close()

Close releases CGo resources held by the underlying tree-sitter parser. It should be called when the Walker is no longer needed. @intent free parser-side native resources once file parsing is complete @sideEffect releases CGo resources owned by the underlying parser

func (*Walker) DiscoverPackages

func (w *Walker) DiscoverPackages(ctx context.Context, opts ingest.PackageDiscoveryOptions) (map[string]ingest.PackageInfo, error)

DiscoverPackages delegates repository package discovery to the walker's language specification. @intent implement the ingest package-discovery port without exposing LangSpec to the application.

func (*Walker) ExtractComments

func (w *Walker) ExtractComments(ctx context.Context, filePath string, content []byte) ([]CommentBlock, error)

ExtractComments parses a file and returns merged comment blocks. @intent expose comment extraction without forcing callers to build nodes and edges @requires Walker parser is initialized for the language @see treesitter.Walker.collectComments

func (*Walker) Language

func (w *Walker) Language() string

Language returns the Walker language name. @intent expose the language handled by this Walker for downstream coordination

func (*Walker) PackageEdges

func (w *Walker) PackageEdges(ctx ingest.PackageContext) []graph.Edge

PackageEdges derives package-wide semantic relationships through the walker's language specification. @intent implement the ingest package-edge port while keeping language semantics inside the Tree-sitter adapter.

func (*Walker) Parse

func (w *Walker) Parse(filePath string, content []byte) ([]graph.Node, []graph.Edge, error)

Parse parses a file and returns graph nodes and edges. @intent provide the basic parsing entry point when callers do not need comments or custom context @see treesitter.Walker.ParseWithComments

func (*Walker) ParseCacheVersion

func (w *Walker) ParseCacheVersion() string

ParseCacheVersion returns the parser/query generation used to validate serialized parse results. @intent invalidate full-build parse cache entries when language queries or parser semantics change. @domainRule bump walker-v1 whenever non-query Walker semantics change parsed nodes, edges, comments, or metadata.

func (*Walker) ParseWithComments

func (w *Walker) ParseWithComments(ctx context.Context, filePath string, content []byte) ([]graph.Node, []graph.Edge, []CommentBlock, error)

ParseWithComments parses a file and also extracts raw comment blocks. @intent produce the full parse result needed for graph building and annotation binding @mutates edges by appending contains, implements, and tested_by relationships @requires Walker parser is initialized for the language @ensures returned nodes always include a file node for filePath @see treesitter.Walker.executeQueries

func (*Walker) ParseWithCommentsAndMetadata

func (w *Walker) ParseWithCommentsAndMetadata(ctx context.Context, filePath string, content []byte) ([]graph.Node, []graph.Edge, []CommentBlock, ParseMetadata, error)

ParseWithCommentsAndMetadata parses a file and returns package-level enrichment metadata too. @intent give build/update paths access to interface method metadata needed for package-wide relationship inference.

func (*Walker) ParseWithContext

func (w *Walker) ParseWithContext(ctx context.Context, filePath string, content []byte) ([]graph.Node, []graph.Edge, error)

ParseWithContext parses filePath with the given context, allowing cancellation. @intent let callers cancel Tree-sitter parsing through context propagation @see treesitter.Walker.ParseWithComments

func (*Walker) Spec

func (w *Walker) Spec() *LangSpec

Spec returns the language specification backing this walker. @intent expose the configured language rules and query paths for this walker instance

type WalkerOption

type WalkerOption func(*Walker)

WalkerOption configures optional Walker behavior during construction. @intent allow caller-supplied dependencies such as logging without expanding constructor arguments

func WithLogger

func WithLogger(l *slog.Logger) WalkerOption

WithLogger installs a logger on a Walker. @intent let callers route parser diagnostics through their preferred slog.Logger @mutates Walker.logger

Jump to

Keyboard shortcuts

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