graph

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AffectedFile

type AffectedFile struct {
	File  string     `json:"file"`
	Kind  ChangeKind `json:"kind"`
	Nodes []*Node    `json:"nodes"`
}

type Arch

type Arch struct {
	Languages   []LangStat   `json:"languages"`
	TotalFiles  int          `json:"total_files"`
	TotalNodes  int          `json:"total_nodes"`
	TotalEdges  int          `json:"total_edges"`
	Layers      []ModuleStat `json:"layers"`
	Modules     []ModuleStat `json:"modules"`
	ModuleDeps  []ModuleDep  `json:"module_deps"`
	EntryPoints []*Node      `json:"entry_points"`
	Hotspots    []Hotspot    `json:"hotspots"`
}

type CallResolver

type CallResolver interface {
	ResolveCall(ctx context.Context, file string, line, column int) (defFile string, defLine int, ok bool)
}

type ChangeKind

type ChangeKind string
const (
	ChangeAdded    ChangeKind = "added"
	ChangeModified ChangeKind = "modified"
	ChangeDeleted  ChangeKind = "deleted"
)

type Changes

type Changes struct {
	Files  []AffectedFile `json:"files"`
	Impact []Impact       `json:"impact,omitempty"`
}

type CoChange

type CoChange struct {
	File  string `json:"file"`
	Count int    `json:"count"`
}

type CoChangesResult

type CoChangesResult struct {
	File    string     `json:"file"`
	Commits int        `json:"commits"`
	Related []CoChange `json:"related"`
}

type ContentHit added in v0.12.7

type ContentHit struct {
	Node       *Node `json:"node"`
	MatchLines []int `json:"match_lines"`
	Callers    int   `json:"callers"`
	Callees    int   `json:"callees"`
	Score      int   `json:"score"`
}

type ContentSearchOpts added in v0.12.7

type ContentSearchOpts struct {
	Pattern    string
	Regex      bool
	IgnoreCase bool
	File       string
	Glob       string
	Limit      int
	Offset     int
}

type ContentSearchResult added in v0.12.7

type ContentSearchResult struct {
	Hits            []ContentHit    `json:"hits"`
	Raw             []RawContentHit `json:"raw,omitempty"`
	TotalLineHits   int             `json:"total_line_hits"`
	TotalResults    int             `json:"total_results"`
	TotalRawResults int             `json:"total_raw_results"`
	Offset          int             `json:"offset"`
	HasMore         bool            `json:"has_more"`
	RawHasMore      bool            `json:"raw_has_more"`
}

type CoverageIssue added in v0.12.7

type CoverageIssue struct {
	File   string `json:"file"`
	Reason string `json:"reason"`
}

CoverageIssue records a source file that discovery found but the structural index could not fully process. Content search still scans these files and returns their hits as raw matches.

type DepsResult

type DepsResult struct {
	Module     string   `json:"module"`
	DependsOn  []string `json:"depends_on"`
	DependedBy []string `json:"depended_by"`
	External   []string `json:"external"`
	Transitive []string `json:"transitive,omitempty"`
}

type Edge

type Edge struct {
	From string     `json:"from"`
	To   string     `json:"to"`
	Kind EdgeKind   `json:"kind"`
	Via  Provenance `json:"via,omitempty"`
}

type EdgeKind

type EdgeKind string
const (
	EdgeCalls      EdgeKind = "calls"
	EdgeInherits   EdgeKind = "inherits"
	EdgeImplements EdgeKind = "implements"
)

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func New

func New(root, cachePath string, opts ...Option) *Engine

func (*Engine) Architecture

func (e *Engine) Architecture(ctx context.Context) (Arch, error)

func (*Engine) CoChanges

func (e *Engine) CoChanges(ctx context.Context, file string, limit int) (CoChangesResult, error)

func (*Engine) DeadCode

func (e *Engine) DeadCode(ctx context.Context, limit int) ([]*Node, error)

func (*Engine) Definitions added in v0.12.21

func (e *Engine) Definitions(ctx context.Context, file string, src []byte, line, col int) ([]Location, error)

Definitions finds declaration sites for the identifier at the given position. src overrides the on-disk content when non-nil.

func (*Engine) Deps

func (e *Engine) Deps(ctx context.Context, target string, depth int) (DepsResult, error)

func (*Engine) DetectChanges

func (e *Engine) DetectChanges(ctx context.Context, since string) (Changes, error)

func (*Engine) EdgeStats

func (e *Engine) EdgeStats() map[Provenance]int

func (*Engine) Hierarchy

func (e *Engine) Hierarchy(ctx context.Context, name, file string) (HierarchyResult, error)

func (*Engine) Hover added in v0.12.21

func (e *Engine) Hover(ctx context.Context, file string, src []byte, line, col int) (*HoverInfo, error)

Hover returns the best-ranked definition for the identifier at the given position with a snippet of its source, or nil when nothing matches.

func (*Engine) Implementations added in v0.12.21

func (e *Engine) Implementations(ctx context.Context, file string, src []byte, line, col int) ([]Location, error)

Implementations returns implementers and subtypes of the type named at the given position — only relations stated syntactically (extends/implements clauses, superclasses), so structurally-typed languages yield nothing.

func (*Engine) Index

func (e *Engine) Index(ctx context.Context) (Status, error)

func (*Engine) IsStale added in v0.12.7

func (e *Engine) IsStale(ctx context.Context) bool

IsStale reports whether the cached graph's discovered source-file set or any file's size/mtime differs from the workspace. A false result when no graph exists means "not indexed", not "fresh".

func (*Engine) References added in v0.12.21

func (e *Engine) References(ctx context.Context, file string, src []byte, line, col int) ([]Location, error)

References finds declaration and usage sites for the identifier at the given position. src overrides the on-disk content when non-nil.

func (*Engine) Search

func (e *Engine) Search(ctx context.Context, opts SearchOpts) ([]*Node, error)

func (*Engine) SearchContent added in v0.12.7

func (e *Engine) SearchContent(ctx context.Context, opts ContentSearchOpts) (ContentSearchResult, error)

SearchContent scans the graph's discovered source-file set, maps each matching line to the tightest containing definition, and deduplicates the result by definition. Matches outside graph coverage remain in Raw.

func (*Engine) SearchPage added in v0.12.7

func (e *Engine) SearchPage(ctx context.Context, opts SearchOpts) (SearchResult, error)

func (*Engine) Similar

func (e *Engine) Similar(ctx context.Context, name, file string, limit int) (SimilarResult, error)

func (*Engine) Snippet

func (e *Engine) Snippet(ctx context.Context, name, file string) (Snippet, error)

func (*Engine) Status

func (e *Engine) Status() Status

func (*Engine) StatusOrLoad

func (e *Engine) StatusOrLoad() Status

func (*Engine) Tests

func (e *Engine) Tests(ctx context.Context, name, file string) (TestsResult, error)

func (*Engine) Trace

func (e *Engine) Trace(ctx context.Context, from, to, file string, callers bool, maxDepth int) (TraceResult, error)

type Graph

type Graph struct {
	Nodes   []*Node   `json:"nodes"`
	Edges   []*Edge   `json:"edges"`
	Imports []*Import `json:"imports,omitempty"`
	Refs    []*Ref    `json:"refs,omitempty"`
	// contains filtered or unexported fields
}

type HierarchyResult

type HierarchyResult struct {
	Type         *Node   `json:"type"`
	Extends      []*Node `json:"extends"`
	Subtypes     []*Node `json:"subtypes"`
	Implements   []*Node `json:"implements"`
	Implementers []*Node `json:"implementers"`
	Others       []*Node `json:"others,omitempty"`
}

type Hotspot

type Hotspot struct {
	Node    *Node `json:"node"`
	Callers int   `json:"callers"`
	Callees int   `json:"callees"`
}

type HoverInfo added in v0.12.21

type HoverInfo struct {
	Node      *Node
	Code      string
	Truncated bool
	Others    int
}

type Impact added in v0.9.3

type Impact struct {
	Caller *Node   `json:"caller"`
	Calls  []*Node `json:"calls"`
}

type Import

type Import struct {
	FromFile string `json:"from"`
	Path     string `json:"path"`
	ToModule string `json:"to,omitempty"`
}

type Kind

type Kind string
const (
	KindFunction    Kind = "function"
	KindMethod      Kind = "method"
	KindClass       Kind = "class"
	KindInterface   Kind = "interface"
	KindType        Kind = "type"
	KindConstructor Kind = "constructor"
	KindModule      Kind = "module"
	KindConstant    Kind = "constant"
	KindVariable    Kind = "variable"
)

type LangStat

type LangStat struct {
	Lang  string `json:"lang"`
	Files int    `json:"files"`
	Nodes int    `json:"nodes"`
}

type Location added in v0.12.21

type Location struct {
	File string
	Line int
	Col  int
}

Location is an LSP-style position: zero-based line and UTF-16 column in a slash-separated workspace-relative file.

type ModuleDep

type ModuleDep struct {
	Module     string `json:"module"`
	DependsOn  int    `json:"depends_on"`
	DependedBy int    `json:"depended_by"`
}

type ModuleStat

type ModuleStat struct {
	Path  string `json:"path"`
	Files int    `json:"files"`
	Nodes int    `json:"nodes"`
}

type Node

type Node struct {
	ID        string `json:"id"`
	Kind      Kind   `json:"kind"`
	Name      string `json:"name"`
	File      string `json:"file"`
	StartLine int    `json:"start_line"`
	EndLine   int    `json:"end_line"`
	NameLine  int    `json:"name_line,omitempty"`
	NameCol   int    `json:"name_col,omitempty"`
	Lang      string `json:"lang"`
}

type Option

type Option func(*Engine)

func WithResolver

func WithResolver(r CallResolver) Option

type Path

type Path struct {
	Nodes []*Node
	Via   []Provenance
}

type Provenance

type Provenance string
const (
	ViaName      Provenance = "name"
	ViaLSP       Provenance = "lsp"
	ViaAmbiguous Provenance = "ambiguous"
)

type RawContentHit added in v0.12.7

type RawContentHit struct {
	File    string `json:"file"`
	Line    int    `json:"line"`
	Content string `json:"content"`
}

type Ref added in v0.12.21

type Ref struct {
	Name string   `json:"name"`
	File string   `json:"file"`
	Line int      `json:"line"`
	Col  int      `json:"col"`
	Kind EdgeKind `json:"kind"`
	Lang string   `json:"lang"`
}

Ref is a name usage site (call, inherits or implements clause) with an LSP-style zero-based line and UTF-16 column.

type SearchOpts

type SearchOpts struct {
	Query  string
	Kind   Kind
	File   string
	Limit  int
	Offset int
}

type SearchResult added in v0.12.7

type SearchResult struct {
	Nodes   []*Node `json:"nodes"`
	Total   int     `json:"total"`
	Offset  int     `json:"offset"`
	HasMore bool    `json:"has_more"`
}

type SemanticToken added in v0.14.0

type SemanticToken struct {
	Range     SymRange
	Type      string
	Modifiers []string
}

func SemanticTokens added in v0.14.0

func SemanticTokens(filename string, src []byte) []SemanticToken

SemanticTokens classifies a buffer with the grammar's highlight query. It is syntactic rather than type-aware, but considerably richer and more accurate than lexical colorization when an LSP server is absent.

type Similar

type Similar struct {
	Node  *Node   `json:"node"`
	Score float64 `json:"score"`
}

type SimilarResult

type SimilarResult struct {
	Target  *Node     `json:"target"`
	Matches []Similar `json:"matches"`
	Others  []*Node   `json:"others,omitempty"`
}

type Snippet

type Snippet struct {
	Node   *Node
	Code   string
	Others []*Node
}

type Status

type Status struct {
	Indexed   bool
	IndexedAt time.Time
	Files     int
	Nodes     int
	Edges     int
	Skipped   []CoverageIssue
}

type SymRange added in v0.12.21

type SymRange struct {
	StartLine int
	StartCol  int
	EndLine   int
	EndCol    int
}

func DocumentHighlights added in v0.14.0

func DocumentHighlights(filename string, src []byte, line, col int) []SymRange

DocumentHighlights returns syntax-tree identifier occurrences matching the token at the cursor. It deliberately stays file-local: without type and scope information, highlighting same-spelled identifiers in other files would imply a certainty Tree-sitter does not provide.

func FoldingRanges added in v0.14.0

func FoldingRanges(filename string, src []byte) []SymRange

FoldingRanges returns conservative declaration-level folds. These are less exhaustive than a language server's ranges but stable across all grammars with tags support and never invent folds from indentation alone.

type Symbol added in v0.12.21

type Symbol struct {
	Name      string
	Kind      Kind
	Range     SymRange
	NameRange SymRange
	Children  []*Symbol
}

func FileSymbols added in v0.12.21

func FileSymbols(filename string, src []byte) []*Symbol

FileSymbols extracts a nested outline from a single buffer without touching the index, so unsaved editor content stays accurate.

type TestsResult

type TestsResult struct {
	Symbol   *Node   `json:"symbol"`
	TestedBy []*Node `json:"tested_by"`
	Covers   []*Node `json:"covers"`
	Others   []*Node `json:"others,omitempty"`
}

type TraceResult

type TraceResult struct {
	Roots []*Node
	Paths []Path
}

Jump to

Keyboard shortcuts

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