extract

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package extract turns a source file into graph fragments using tree-sitter. Each extractor emits definition nodes (file, function, type, method) plus the structural edges it can see locally (contains, imports). Calls and imports that cross files are recorded raw and stitched together by Resolve, which has the whole-corpus view needed to point a call at the right definition.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Resolve

func Resolve(results []Result, files []string) model.Extraction

Resolve stitches per-file results into one extraction. It adds the call edges and import edges that need a whole-corpus view: calls resolve to definitions by name, and relative imports resolve to the file they point at.

Types

type Call

type Call struct {
	CallerID, Callee, File, Loc string
}

Call is an unresolved call site: CallerID invoked a symbol named Callee.

type Def

type Def struct {
	ID, Name, File string
}

Def records a named definition so cross-file calls can resolve to it by name.

type Imp

type Imp struct {
	FileID, File, Spec, Loc string
}

Imp is an unresolved import: File imported the module named Spec.

type ModInvoke added in v0.5.0

type ModInvoke struct {
	NodeID, Dir string
	Args        map[string]segVal
	ArgVarRefs  map[string]string
}

ModInvoke carries one `module` block's arguments so Resolve can follow a local wrapper chain. Dir is the invoking directory (its dirScope). Args holds literal scalar/list arguments by name; ArgVarRefs maps an argument name to the bare variable it passes through (`arg = var.<name>`).

type ModRef added in v0.4.0

type ModRef struct {
	FromID, Source, File, Loc string
}

ModRef is a Terraform module block's source before resolution: the module node FromID declared `source = Source` in File. Resolve turns a local source into an edge to the target directory node, and a registry/private-registry source into an external concept node.

type NullLabelRef added in v0.5.0

type NullLabelRef struct {
	NodeID, Scope string
	Inputs        labelInputs
}

NullLabelRef carries a captured cloudposse null-label module so Resolve can fill in segments that come from input variables or an inherited context. NodeID is the module node; Scope is its directory (used to find the caller); Inputs are the locally-captured label fields.

type Result

type Result struct {
	Nodes      []model.Node
	Edges      []model.Edge
	Defs       []Def
	Calls      []Call
	Imps       []Imp
	ModRefs    []ModRef
	NullLabels []NullLabelRef
	ModInvokes []ModInvoke
}

Result is one file's extraction before cross-file resolution.

func File

func File(root, rel string) (Result, error)

File extracts rel (a path relative to root). Unsupported extensions return an empty result, not an error, so the caller can skip them silently.

func FileFromBytes added in v0.3.0

func FileFromBytes(rel string, src []byte) Result

FileFromBytes extracts rel from already-read source bytes. It lets callers that have hashed the file (e.g. the incremental cache) avoid a second read. Unsupported extensions return an empty result.

Jump to

Keyboard shortcuts

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