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

astgraph

package
v0.3.2-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package astgraph normalizes language parsers into a shared symbol graph.

Package astgraph extracts Go declarations and supports pluggable Tree-sitter adapters.

Index

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 DefEdge

type DefEdge struct {
	Symbol string `json:"symbol"`
	NodeID string `json:"node_id"`
}

DefEdge associates a source-level symbol name with one definition node.

type FileExtractor

type FileExtractor struct{}

FileExtractor provides conservative file-level graph coverage for formats without a registered parser.

func (FileExtractor) Extract

func (FileExtractor) Extract(path string, source []byte) (Graph, error)

type GoExtractor

type GoExtractor struct{}

GoExtractor uses go/parser and go/ast to create definition and call-reference edges.

func (GoExtractor) Extract

func (GoExtractor) Extract(path string, source []byte) (Graph, error)

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

func FilterSymbol(g Graph, name string) Graph

FilterSymbol returns nodes with an exact or substring name match and their adjacent edges.

func LoadPath

func LoadPath(path string) (Graph, error)

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 NewGraph

func NewGraph() Graph

NewGraph constructs an initialized graph.

func ParseFiles

func ParseFiles(files map[string][]byte) (Graph, error)

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

func ParseSource(path string, source []byte, adapters map[string]TreeSitterAdapter) (Graph, error)

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

func (g *Graph) AddReference(from, to string)

AddReference adds a source-symbol reference edge.

func (*Graph) Merge

func (g *Graph) Merge(other Graph)

Merge adds all graph nodes and edges to the receiver.

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.

func (PolyglotExtractor) Extract

func (e PolyglotExtractor) Extract(path string, source []byte) (Graph, error)

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 RefEdge

type RefEdge struct {
	From string `json:"from"`
	To   string `json:"to"`
}

RefEdge means From references the source-level symbol named by To.

type SourceExtractor

type SourceExtractor interface {
	Extract(path string, source []byte) (Graph, error)
}

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

type TreeSitterAdapter interface {
	ExtractTreeSitter(path string, source []byte) (Graph, error)
}

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.

Jump to

Keyboard shortcuts

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