Documentation
¶
Overview ¶
Package astgraph normalizes language parsers into a shared symbol graph.
Package astgraph extracts Go declarations and supports pluggable Tree-sitter adapters.
Index ¶
- func DefaultTreeSitterAdapters() map[string]TreeSitterAdapter
- type DefEdge
- type FileExtractor
- type GoExtractor
- type Graph
- func FilterSymbol(g Graph, name string) Graph
- func LoadPath(path string) (Graph, error)
- func NewGraph() Graph
- func ParseFiles(files map[string][]byte) (Graph, error)
- func ParseFilesWithAdapters(files map[string][]byte, adapters map[string]TreeSitterAdapter) (Graph, error)
- func ParseSource(path string, source []byte, adapters map[string]TreeSitterAdapter) (Graph, error)
- type ImpactSet
- type NativeTreeSitterAdapter
- type PolyglotExtractor
- type QueryLexicalAdapter
- type RefEdge
- type SourceExtractor
- type SymbolNode
- type TreeSitterAdapter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultTreeSitterAdapters ¶
func DefaultTreeSitterAdapters() map[string]TreeSitterAdapter
DefaultTreeSitterAdapters returns built-in Go, JavaScript/TypeScript, and Python extractors.
Types ¶
type FileExtractor ¶
type FileExtractor struct{}
FileExtractor provides conservative file-level graph coverage for formats without a registered parser.
type GoExtractor ¶
type GoExtractor struct{}
GoExtractor uses go/parser and go/ast to create definition and call-reference edges.
type Graph ¶
type Graph struct {
Nodes map[string]SymbolNode `json:"nodes"`
Definitions []DefEdge `json:"definitions"`
References []RefEdge `json:"references"`
FileHashes map[string]string `json:"-"`
}
Graph is a normalized directed symbol graph.
func FilterSymbol ¶
FilterSymbol returns nodes with an exact or substring name match and their adjacent edges.
func LoadPath ¶
LoadPath parses a supported source file or recursively loads supported files from a directory. Directory traversal is deterministic and skips generated/dependency/cache trees.
func ParseFiles ¶
ParseFiles extracts all files with the native Go parser, then merges them.
func ParseFilesWithAdapters ¶
func ParseFilesWithAdapters(files map[string][]byte, adapters map[string]TreeSitterAdapter) (Graph, error)
ParseFilesWithAdapters extracts a mixed-language file set into one Graph IR.
func ParseSource ¶
ParseSource uses a language parser when available and otherwise preserves text files as file-level nodes. The fallback keeps changes visible without implying that an unknown language received symbol-level analysis.
func (*Graph) AddDefinition ¶
func (g *Graph) AddDefinition(node SymbolNode)
AddDefinition adds a node and its symbol index edge.
func (*Graph) AddReference ¶
AddReference adds a source-symbol reference edge.
type ImpactSet ¶
type ImpactSet struct {
ChangedSymbols []string `json:"changed_symbols"`
ImpactedSymbols []string `json:"impacted_symbols"`
Tests []string `json:"tests"`
}
ImpactSet is the transitive closure of changed definitions and dependent tests.
func BlastRadius ¶
func BlastRadius(graph Graph, changes []ingress.FileChange) ImpactSet
BlastRadius computes reverse-reference closure for symbols intersecting changed lines.
type NativeTreeSitterAdapter ¶
type NativeTreeSitterAdapter struct {
LanguageName string
Language *sitter.Language
QuerySource string
}
NativeTreeSitterAdapter parses Python or TypeScript through the official Go bindings.
func (NativeTreeSitterAdapter) ExtractTreeSitter ¶
func (a NativeTreeSitterAdapter) ExtractTreeSitter(path string, source []byte) (Graph, error)
ExtractTreeSitter normalizes Python or TypeScript definitions and call sites.
type PolyglotExtractor ¶
type PolyglotExtractor struct{ QuerySource string }
PolyglotExtractor is a dependency-free structural fallback for languages for which Astrix does not have a native parser adapter. It tokenizes source while discarding comments and string contents, then recognizes common declaration and call shapes. Its output is intentionally conservative and is not a full language parser.
type QueryLexicalAdapter ¶
type QueryLexicalAdapter struct{ QuerySource string }
QueryLexicalAdapter applies custom Tree-sitter tag capture intent through the dependency-free structural extractor when no grammar is registered.
func (QueryLexicalAdapter) ExtractTreeSitter ¶
func (a QueryLexicalAdapter) ExtractTreeSitter(path string, source []byte) (Graph, error)
type SourceExtractor ¶
SourceExtractor converts one source file into the shared graph IR.
type SymbolNode ¶
type SymbolNode struct {
ID string `json:"id"`
Name string `json:"name"`
File string `json:"file"`
Kind string `json:"kind"`
StartLine int `json:"start_line"`
EndLine int `json:"end_line"`
IsTest bool `json:"is_test,omitempty"`
ContentHash string `json:"content_hash,omitempty"`
}
SymbolNode is a source definition in the language-neutral graph IR.
type TreeSitterAdapter ¶
TreeSitterAdapter lets language-specific Tree-sitter grammars normalize into the IR. Adapters can be backed by github.com/tree-sitter/go-tree-sitter without coupling the graph traversal layer to a particular grammar or query layout.
func PythonTreeSitter ¶
func PythonTreeSitter() TreeSitterAdapter
PythonTreeSitter creates the Python grammar adapter.
func TSXTreeSitter ¶
func TSXTreeSitter() TreeSitterAdapter
TSXTreeSitter creates the TSX grammar adapter.
func TypeScriptTreeSitter ¶
func TypeScriptTreeSitter() TreeSitterAdapter
TypeScriptTreeSitter creates the TypeScript grammar adapter.