Documentation
¶
Overview ¶
Package codemap builds a compact, read-only structural index of a workspace. The first slice is outline-first: directory, file, and symbol nodes. Dependency and call edges can layer onto the same stable node IDs later.
Index ¶
- Constants
- func FormatCycles(cycles [][]Node, max int) string
- func FormatDependencies(title string, nodes []Node, max int) string
- func FormatImpact(result ImpactResult, max int) string
- func FormatNodes(nodes []Node, max int) string
- func FormatTree(idx *CodeIndex, max int) string
- func MermaidDiagram(idx *CodeIndex, focus string, maxEdges int) string
- func Projection(idx *CodeIndex, max int) string
- type BuildOptions
- type BuilderProvider
- type CachedProvider
- type CodeIndex
- func (i *CodeIndex) Children(id NodeID) []NodeID
- func (i *CodeIndex) Count() int
- func (i *CodeIndex) Cycles(pathOrQuery string, max int) [][]Node
- func (i *CodeIndex) Dependencies(pathOrQuery string, max int) []Node
- func (i *CodeIndex) Dependents(pathOrQuery string, max int) []Node
- func (i *CodeIndex) Edges(kind EdgeKind) []Edge
- func (i *CodeIndex) Filter(query string, max int) []Node
- func (i *CodeIndex) Impact(pathOrQuery string, depth, max int) ImpactResult
- func (i *CodeIndex) Node(id NodeID) (Node, bool)
- func (i *CodeIndex) Nodes() []Node
- func (i *CodeIndex) Root() NodeID
- func (i *CodeIndex) RootPath() string
- func (i *CodeIndex) SymbolsForFile(path string) []Node
- type Edge
- type EdgeKind
- type FallbackSource
- type ImpactResult
- type LSPSource
- type Node
- type NodeID
- type NodeKind
- type Position
- type Provider
- type Range
- type StaticProvider
- type Stats
- type SymbolInfo
- type SymbolSource
Constants ¶
const MaxDepthAll = -1
MaxDepthAll means dependency traversal should continue until exhausted.
Variables ¶
This section is empty.
Functions ¶
func FormatCycles ¶
FormatCycles renders import cycles for humans and agents.
func FormatDependencies ¶
FormatDependencies renders dependency query results.
func FormatImpact ¶
func FormatImpact(result ImpactResult, max int) string
FormatImpact renders a dependency blast-radius query with direction labels.
func FormatNodes ¶
FormatNodes renders a bounded flat list of nodes, usually filter results.
func FormatTree ¶
FormatTree renders a bounded outline suitable for humans and model context.
func MermaidDiagram ¶
MermaidDiagram renders a bounded import graph. When focus is non-empty, the graph is narrowed to direct dependencies/dependents of the matching file.
func Projection ¶
Projection returns a compact structure summary for agent context injection.
Types ¶
type BuildOptions ¶
type BuildOptions struct {
Root string
MaxFiles int
Source SymbolSource
}
BuildOptions controls a CodeIndex rebuild.
type BuilderProvider ¶
type BuilderProvider struct{ Options BuildOptions }
BuilderProvider rebuilds the index on demand.
type CachedProvider ¶
type CachedProvider struct {
Options BuildOptions
// contains filtered or unexported fields
}
CachedProvider reuses the last index until supported source file paths, mtimes, sizes, or counts change. This is not a file watcher yet, but it avoids rebuilding the map on every /map render or agent query while still reflecting normal edits on the next request.
type CodeIndex ¶
type CodeIndex struct {
// contains filtered or unexported fields
}
CodeIndex is an immutable structural snapshot. Mutating rebuilds publish a new instance instead of editing this one in place.
func Build ¶
func Build(ctx context.Context, opts BuildOptions) (*CodeIndex, error)
Build walks the workspace and returns an immutable structure snapshot.
func NewIndex ¶
func NewIndex(root string, rootID NodeID, nodes map[NodeID]Node, children map[NodeID][]NodeID, edges ...[]Edge) *CodeIndex
NewIndex constructs an immutable snapshot from prebuilt nodes and edges.
func (*CodeIndex) Cycles ¶
Cycles returns import cycles, optionally narrowed to cycles involving a matching file/path query. The result is capped and deterministic for the same indexed graph.
func (*CodeIndex) Dependencies ¶
Dependencies returns outgoing import edges for a matching file node.
func (*CodeIndex) Dependents ¶
Dependents returns incoming import edges for a matching file node.
func (*CodeIndex) Edges ¶
Edges returns a copy of all edges, filtered by kind when kind is non-empty.
func (*CodeIndex) Filter ¶
Filter returns nodes whose path, name, kind, or container matches query. It is intentionally simple and deterministic; TUI fuzzy ranking can layer on later.
func (*CodeIndex) Impact ¶
func (i *CodeIndex) Impact(pathOrQuery string, depth, max int) ImpactResult
Impact returns direct dependencies, direct dependents, transitive dependents, and import cycles involving the target file. Depth limits only the transitive reverse traversal; use MaxDepthAll for an unbounded walk.
func (*CodeIndex) RootPath ¶
RootPath returns the absolute workspace root captured by this snapshot.
func (*CodeIndex) SymbolsForFile ¶
SymbolsForFile returns symbol children for one repo-relative or absolute path.
type FallbackSource ¶
type FallbackSource struct{}
FallbackSource uses yottacode's offline syntax layer when available, then the conservative regex scanner. It keeps /map useful without requiring users to install language servers first.
type ImpactResult ¶
type ImpactResult struct {
Target Node
DirectDependencies []Node
DirectDependents []Node
TransitiveDependents []Node
Cycles [][]Node
}
ImpactResult is a bounded blast-radius query over import edges.
type LSPSource ¶
LSPSource tries a live language server first and falls back to approximate regex symbols when the server is unavailable or lacks document symbols.
type Node ¶
type Node struct {
ID NodeID
Parent NodeID
Kind NodeKind
Name string
Path string
RelPath string
Language string
Symbol SymbolInfo
Stats Stats
}
Node is one immutable item in a CodeIndex snapshot.
type NodeID ¶
type NodeID string
NodeID is stable within one workspace snapshot. IDs are repo-relative where possible so TUI state and agent output remain readable and deterministic.
type Position ¶
Position is a zero-based source position. It mirrors LSP coordinates but keeps the codemap package independent from a specific symbol provider.
type Provider ¶
Provider returns the latest code-map snapshot. TUI rebuilds can swap the snapshot while agent tools keep depending on this tiny read-only surface.
type StaticProvider ¶
type StaticProvider struct{ Snapshot *CodeIndex }
StaticProvider returns one immutable index, useful in tests and one-shot runs.
type SymbolInfo ¶
SymbolInfo stores metadata only symbol nodes need.