index

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const BuildingSuffix = ".building"

BuildingSuffix is the suffix RunAtomic uses for in-progress index files.

Variables

This section is empty.

Functions

func ExtractDefinitions

func ExtractDefinitions(project string, f SourceFile) ([]graph.Node, []graph.Edge)

ExtractDefinitions reads a file from disk and extracts its definitions.

func IsTestFile

func IsTestFile(p string) bool

IsTestFile reports whether a repo-relative path is a test file, by the naming conventions of the supported stacks (Go `_test.go`, JS/TS `.test.`/`.spec.`, and `__tests__` dirs). Exported so the query layer can exclude test functions from the dead-code hint — they're invoked by the test runner, not by code.

func ProjectName

func ProjectName(root string) string

ProjectName derives a stable project key from the repo root (matches the upstream convention of slugging the absolute path).

func ResolveImports

func ResolveImports(project string, files []SourceFile) []graph.Edge

ResolveImports reads the files and emits IMPORTS edges. It is the disk-reading wrapper around resolveImports. Prefer resolveImportsStreaming during indexing — it holds one file at a time instead of the whole codebase.

func ResolveSimilar

func ResolveSimilar(project, root string, nodes []graph.Node) []graph.Edge

ResolveSimilar emits SIMILAR_TO edges between near-clone functions/methods. It reads each file once, tokenizes every function body, and runs the MinHash + LSH pass (internal/similar). Cross-file by nature, so it always runs on the full node set. Prefer resolveSimilarFromSpans during indexing — reuses CALLS spans and keeps only MinHash signatures in RAM, not tokenized bodies for every function.

Types

type Changes

type Changes struct {
	Changed []string // indexed, but content hash differs now
	Added   []string // on disk, absent from the index
	Deleted []string // in the index, gone from disk
}

Changes is the set of files that differ from the indexed snapshot.

func DetectChanges

func DetectChanges(store *graph.Store, project, root string) (Changes, error)

DetectChanges compares the source files currently under root against the per-file content hashes recorded at the last index (Store.FileHashes). It is the basis for skipping a re-index when nothing changed, and later for re-resolving only the scopes whose files moved. A never-indexed project reports every file as Added.

func (Changes) Any

func (c Changes) Any() bool

Any reports whether anything changed since the last index.

func (Changes) Summary

func (c Changes) Summary() string

Summary renders the change set as the compact wire format the detect_changes tool returns: one `status<TAB>path` line per file (changed, then added, then deleted).

type Lang

type Lang string

Lang is a detected source language for a file.

const (
	LangGo  Lang = "go"
	LangTS  Lang = "ts"
	LangTSX Lang = "tsx"
	LangJS  Lang = "js"
)

type Result

type Result struct {
	Project       string
	Files         int
	Nodes         int
	EdgesKept     int
	EdgesDropped  int
	Reused        bool // nothing changed since the last index; the pipeline was skipped
	ScipScopes    int
	ScipPeakRSS   uint64
	ScipHeapCapMB int
}

Result summarizes an indexing run.

func Run

func Run(store *graph.Store, root string) (Result, error)

Run indexes root into an already-open store (tests/temp dirs). Prefer RunAtomic for CLI/MCP so a failed re-index does not wipe the previous graph.

func RunAtomic added in v0.2.0

func RunAtomic(dbPath, root string) (Result, error)

RunAtomic builds into dbPath+BuildingSuffix and renames on success, leaving the previous graph at dbPath intact when indexing fails. Do not run `codegraph index` on the same repo while an MCP server is auto-indexing it — both use this path and can race on the store file.

type ScipReport added in v0.2.0

type ScipReport struct {
	ScopesRun int
	PeakRSS   uint64
	HeapCapMB int
}

ScipReport summarizes scip-typescript resource use across all TS scopes in one index run. PeakRSS is the max child RSS observed (Linux/WSL); zero elsewhere.

type SourceFile

type SourceFile struct {
	AbsPath string
	RelPath string
	Lang    Lang
}

SourceFile is a discovered file worth indexing.

func Discover

func Discover(root string) ([]SourceFile, error)

Discover walks root and returns indexable source files. It honors directory hard-ignores plus the repo's .gitignore and .cbmignore — so a repo's vendored deps and build artifacts (e.g. a Go module cache under tmp/) don't flood the graph. Common-case ignore semantics only: directory/name patterns, globs, and root-anchored paths; negation (`!`) and nested .gitignore files are not honored.

Jump to

Keyboard shortcuts

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