depgraph

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjacencyList

func AdjacencyList(g DependencyGraph) (map[string][]string, error)

AdjacencyList returns a plain adjacency list for the given graph.

func AnnotateModule added in v0.25.0

func AnnotateModule(fg *FileDependencyGraph, moduleNode string, members []string, fileStats map[string]vcs.FileStats)

AnnotateModule marks a collapsed module node and records its file count and aggregated churn, summed from the per-file stats of its members. Members without a stats entry (unchanged files) still count toward the file total.

It is a free function rather than a method so the core FileDependencyGraph type does not gain module-specific API from this file (which would couple the core graph back to the module feature).

func AnnotateRustPhantomsShow added in v0.25.0

func AnnotateRustPhantomsShow(g *FileDependencyGraph, contentReader vcs.ContentReader)

AnnotateRustPhantomsShow populates PhantomMetadata for every .rs file in the graph whose contents include a `#[cfg(test)]` region. Intended for `clarity show` (point-in-time) usage where the presence of an in-file test region is enough to render the phantom node.

A free function rather than a method, so the core FileDependencyGraph type does not accrete phantom-specific API from this file.

func AnnotateRustPhantomsWatch added in v0.25.0

func AnnotateRustPhantomsWatch(
	g *FileDependencyGraph,
	diffs map[string]vcs.FileDiff,
	oldContent vcs.ContentReader,
	newContent vcs.ContentReader,
)

AnnotateRustPhantomsWatch populates PhantomMetadata for .rs files in the graph using watch-mode rules: the phantom is added only when the file's test region has additions or deletions in the supplied diff. The file's own Stats are also rewritten to reflect the prod-side split.

func CollapseModules added in v0.25.0

func CollapseModules(g DependencyGraph, modules []Module) (DependencyGraph, Collapse, error)

CollapseModules contracts each module's member files into a single synthetic node named after the module. It is a config-driven post-processing transform applied to the built graph: edges touching a member are redirected to the module node, edges internal to a module (including self-loops) are dropped, and duplicate edges are deduplicated. Members absent from the graph are ignored; a module with no members in the graph contributes nothing.

Running the transform on the dependency graph (before metadata is computed) lets cycles, edges, and stats recompute naturally against the collapsed shape, so a module reads as a single opaque node in the rendered graph.

It returns the collapsed graph and a Collapse describing the created module nodes (their members) and the provenance of every collapsed edge, so the caller can annotate module nodes and preserve edge labels.

func ContainsNode

func ContainsNode(g DependencyGraph, node string) bool

ContainsNode reports whether node exists in the graph.

func DependenciesOf

func DependenciesOf(g DependencyGraph, node string) ([]string, bool, error)

DependenciesOf returns outgoing dependencies for a node.

Types

type Collapse added in v0.25.0

type Collapse struct {
	// Members maps each created module node to the sorted member files it
	// collapsed, for annotating the node with its file count and churn.
	Members map[string][]string
	// EdgeOrigins maps each collapsed edge that touches a module node to the
	// original file→file edges it represents, so renderers can label it by the
	// underlying dependencies instead of the collapsed endpoints.
	EdgeOrigins map[FileEdge][]FileEdge
}

Collapse describes the result of collapsing modules into a graph.

type DependencyGraph

type DependencyGraph = graphlib.Graph[string, string]

DependencyGraph is the shared graph type used across the codebase.

func BuildDependencyGraph

func BuildDependencyGraph(filePaths []string, contentReader vcs.ContentReader) (DependencyGraph, error)

BuildDependencyGraph analyzes a list of files and builds a dependency graph containing only project imports (excluding package:/dart: imports for Dart, and standard library/external imports for Go). Only dependencies that are in the supplied file list are included in the graph. The contentReader function is used to read file contents (from filesystem, git commit, etc.)

func BuildDependencyGraphWithResolver

func BuildDependencyGraphWithResolver(
	filePaths []string,
	dependencyResolver DependencyResolver,
) (DependencyGraph, error)

BuildDependencyGraphWithResolver builds a graph using the provided DependencyResolver implementation.

func FindPathNodes

func FindPathNodes(graph DependencyGraph, targetFiles []string) DependencyGraph

FindPathNodes returns all nodes on any path between specified files. Treats the graph bidirectionally (paths from A to B OR from B to A). A node X is included if it lies on any directed path between any pair of target files. If a file isn't in the graph, it's skipped.

func MustDependencyGraph

func MustDependencyGraph(adjacency map[string][]string) DependencyGraph

MustDependencyGraph builds a graph from adjacency data and panics on errors. Intended for tests.

func NewDependencyGraph

func NewDependencyGraph() DependencyGraph

NewDependencyGraph creates an empty directed dependency graph.

func NewDependencyGraphFromAdjacency

func NewDependencyGraphFromAdjacency(adjacency map[string][]string) (DependencyGraph, error)

NewDependencyGraphFromAdjacency builds a graph from adjacency data.

type DependencyResolver

type DependencyResolver interface {
	SupportsFileExtension(ext string) bool
	ResolveProjectImports(absPath, filePath, ext string) ([]string, error)
	FinalizeGraph(graph DependencyGraph) error
}

DependencyResolver resolves project imports per file and can finalize graph-wide dependencies.

func NewDefaultDependencyResolver

func NewDefaultDependencyResolver(ctx *dependencyGraphContext, contentReader vcs.ContentReader) DependencyResolver

NewDefaultDependencyResolver creates the built-in language-aware dependency resolver.

type EdgeMetadata

type EdgeMetadata struct {
	InCycle bool
}

EdgeMetadata holds metadata for a graph edge.

type FileCycle

type FileCycle struct {
	Path []string
}

FileCycle describes a representative cycle path for a cyclic SCC.

type FileDependencyGraph

type FileDependencyGraph struct {
	Graph DependencyGraph
	Meta  FileGraphMetadata
}

FileDependencyGraph wraps a dependency graph with file-level metadata.

func NewFileDependencyGraph

func NewFileDependencyGraph(g DependencyGraph, fileStats map[string]vcs.FileStats, contentReader vcs.ContentReader) (FileDependencyGraph, error)

NewFileDependencyGraph creates a file-annotated graph from a dependency graph, optional file stats, and an optional content reader used for richer test detection.

type FileEdge

type FileEdge struct {
	From string
	To   string
}

FileEdge identifies a directed edge between two files.

type FileGraphMetadata

type FileGraphMetadata struct {
	Files  map[string]FileMetadata
	Edges  map[FileEdge]EdgeMetadata
	Cycles []FileCycle
	// EdgeOrigins maps a collapsed edge (an edge in the rendered graph that
	// touches a module node) to the original file→file edges it represents.
	// It lets renderers label a collapsed edge by its underlying dependencies
	// so labels stay stable whether or not modules are applied.
	EdgeOrigins map[FileEdge][]FileEdge
}

FileGraphMetadata contains metadata keyed by file and edge.

type FileMetadata

type FileMetadata struct {
	Stats           *vcs.FileStats
	IsTest          bool
	IsPruned        bool
	IsModule        bool
	ModuleFileCount int
	Extension       string
	Phantom         *PhantomMetadata
}

FileMetadata holds metadata for a single file node.

type Module added in v0.25.0

type Module struct {
	Name  string
	Files []string
}

Module is a user-named set of files projected onto the dependency graph. Files holds graph node keys (the same absolute paths used as graph vertices).

type PhantomMetadata added in v0.22.0

type PhantomMetadata struct {
	Kind        string
	Stats       *vcs.FileStats
	ProdChanged bool
}

PhantomMetadata describes a sibling "phantom" node attached to a file to represent in-file test code as a distinct visual node. Kind identifies the language-specific source of the phantom (e.g. "rust-test"). Stats carries any per-line attribution for watch mode; nil in show mode. ProdChanged is true when the prod side of the file also has changes (watch mode only).

Directories

Path Synopsis
languages
c
cpp
zig

Jump to

Keyboard shortcuts

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