Documentation
¶
Index ¶
- func AdjacencyList(g DependencyGraph) (map[string][]string, error)
- func AnnotateModule(fg *FileDependencyGraph, moduleNode string, members []string, ...)
- func AnnotateRustPhantomsShow(g *FileDependencyGraph, contentReader vcs.ContentReader)
- func AnnotateRustPhantomsWatch(g *FileDependencyGraph, diffs map[string]vcs.FileDiff, ...)
- func CollapseModules(g DependencyGraph, modules []Module) (DependencyGraph, Collapse, error)
- func ContainsNode(g DependencyGraph, node string) bool
- func DependenciesOf(g DependencyGraph, node string) ([]string, bool, error)
- func MarkDeletedFiles(fg *FileDependencyGraph, deletedFiles []string)
- func MarkRenamedFiles(fg *FileDependencyGraph, renames map[string]string, ...)
- type Collapse
- type DependencyGraph
- func BuildDependencyGraph(filePaths []string, contentReader vcs.ContentReader) (DependencyGraph, error)
- func BuildDependencyGraphWithResolver(filePaths []string, dependencyResolver DependencyResolver) (DependencyGraph, error)
- func CollapseRenames(graph DependencyGraph, renames map[string]string) (DependencyGraph, error)
- func FindPathNodes(graph DependencyGraph, targetFiles []string) DependencyGraph
- func MergeDeletedNeighborhood(graph DependencyGraph, candidateFiles []string, deletedFiles []string, ...) (DependencyGraph, error)
- func MustDependencyGraph(adjacency map[string][]string) DependencyGraph
- func NewDependencyGraph() DependencyGraph
- func NewDependencyGraphFromAdjacency(adjacency map[string][]string) (DependencyGraph, error)
- type DependencyResolver
- type EdgeMetadata
- type EdgeState
- type FileCycle
- type FileDependencyGraph
- type FileEdge
- type FileGraphMetadata
- type FileMetadata
- type FileState
- type Module
- type ModuleCluster
- type PhantomMetadata
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.
func MarkDeletedFiles ¶ added in v0.27.0
func MarkDeletedFiles(fg *FileDependencyGraph, deletedFiles []string)
MarkDeletedFiles marks file nodes and any incident edges as deleted context.
func MarkRenamedFiles ¶ added in v0.27.0
func MarkRenamedFiles(fg *FileDependencyGraph, renames map[string]string, oldContent map[string][]byte, reader vcs.ContentReader)
MarkRenamedFiles collapses each rename onto its new-path node: the new node records the old path it came from and takes churn computed from the old vs new content (a pure move reads as +0 -0). The old path is expected to have been removed from the graph by CollapseRenames, so a rename renders as a single node rather than an old->new pair. oldContent maps each old path to its pre-rename bytes; reader yields the new node's current content.
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 ¶
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 CollapseRenames ¶ added in v0.27.0
func CollapseRenames(graph DependencyGraph, renames map[string]string) (DependencyGraph, error)
CollapseRenames removes each rename source (old path) from the graph, redirecting any edge that pointed at the old path to the new path. The new path keeps its own dependencies (parsed from its current content), so a rename renders as a single node rather than an old->new pair.
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 MergeDeletedNeighborhood ¶ added in v0.27.0
func MergeDeletedNeighborhood( graph DependencyGraph, candidateFiles []string, deletedFiles []string, parentReader vcs.ContentReader, ) (DependencyGraph, error)
MergeDeletedNeighborhood reconstructs each deleted file's pre-deletion edges and merges them into graph. A deleted file no longer exists in the viewed snapshot, so the files that imported it have dropped the reference and it imports nothing resolvable — leaving the node floating. We rebuild the parent snapshot (via parentReader) over the candidate files that still existed there and copy every edge touching a deleted file, both incoming and outgoing, into graph. Callers run MarkDeletedFiles afterward to style these as removed edges.
candidateFiles is the full node set (present + deleted); files absent from the parent (e.g. newly added ones) are skipped automatically.
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 ¶
EdgeMetadata holds metadata for a graph edge.
type EdgeState ¶ added in v0.27.0
type EdgeState string
EdgeState describes whether a rendered dependency exists in the current tree or is shown as historical context for a deleted node.
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 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
// ModuleCluster, when set, names a module whose Members render inside a drawn
// boundary box. It is populated only for the single-module boundary view
// (show --module <name>) and only when the module has external dependents or
// dependencies worth framing; an isolated module leaves this nil so its files
// render exactly as they would without a box.
ModuleCluster *ModuleCluster
}
FileGraphMetadata contains metadata keyed by file and edge.
type FileMetadata ¶
type FileMetadata struct {
Stats *vcs.FileStats
State FileState
// RenamedFrom is the old path when this node is a rename target (the rename
// is collapsed onto this single node; the old path is removed from the graph).
RenamedFrom string
IsTest bool
IsPruned bool
IsModule bool
ModuleFileCount int
Extension string
Phantom *PhantomMetadata
}
FileMetadata holds metadata for a single file node.
type FileState ¶ added in v0.27.0
type FileState string
FileState describes whether a rendered file node exists in the current tree or is historical context for a deleted file.
type Module ¶ added in v0.25.0
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 ModuleCluster ¶ added in v0.27.0
ModuleCluster groups a module's member file nodes so a renderer can draw a labeled boundary around them.
type PhantomMetadata ¶ added in v0.22.0
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).