indexer

package
v0.9.8-dev.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package indexer runs the full analysis pass that turns registered repositories into semantic facts, and owns the fact cache that pass may reuse -- a cache that must agree with the analysis or be reported diverged.

Index

Constants

View Source
const ProviderDefinitionNotIndexed = "PROVIDER_DEFINITION_NOT_INDEXED"

ProviderDefinitionNotIndexed is the reason of a use whose provider is in the graph and does not publish the declaration the use resolves to. The standard library reaches this through macros: `impl Add for u32` is generated by `add_impl!`, so it exists in no source range and no index defines it.

Variables

View Source
var ErrCacheDiverged = errors.New("fact cache diverged from the analysis")

ErrCacheDiverged reports that a cached entry did not match the facts the analysis produced for the same unit. It aborts the pass on purpose: a cache that answers with facts nobody can reproduce is worse than no cache, because the graph it publishes looks exactly like a correct one.

Functions

func DecodeFactsJSON

func DecodeFactsJSON(data []byte) (facts.Set, error)

DecodeFactsJSON is kept small and explicit for callers that persist a facts set between indexing and rebuilding.

func ValidCacheMode

func ValidCacheMode(mode CacheMode) bool

ValidCacheMode reports whether mode is one this package implements.

Types

type CacheMode

type CacheMode string

CacheMode selects what the fact cache does during a pass.

const (
	// CacheOff analyses every unit. No entry is read and none is written.
	CacheOff CacheMode = "off"
	// CacheOn serves a unit from its entry when every input it recorded
	// still has the same fingerprint.
	CacheOn CacheMode = "on"
	// CacheVerify analyses every unit and, when an entry would have been
	// served, compares it against what the analysis just produced. The
	// fresh facts are always the ones published: verification costs the
	// whole pass and buys the proof that the cache does not lie.
	CacheVerify CacheMode = "verify"
)

type CacheReport

type CacheReport struct {
	Mode     CacheMode
	Hits     int
	Misses   int
	Verified int
}

CacheReport counts what the cache did, for the pass to report.

type FullOptions

type FullOptions struct {
	// Profile distinguishes facts produced for registries that may contain the
	// same repository beside different providers. Empty keeps the historical
	// single-graph behaviour and is treated as the default profile.
	Profile           string
	Repositories      []workspace.Repository
	SyntheticWorkFile string
	IncludeTests      bool
	GoOS              string
	GoARCH            string
	GoCGOEnabled      *bool
	// GoBuildTags are the build constraints the Go loads satisfy. A package
	// guarded by a tag that is absent here declares no file to read and is
	// reported as unresolved instead of indexed.
	GoBuildTags []string
	// GoAllowNetwork lets the Go loads reach a module proxy. Indexing is
	// hermetic by default.
	GoAllowNetwork bool
	// GoMaximumLoads bounds concurrent Go loads. Zero uses the processor
	// count, capped, because every load holds a complete type universe.
	GoMaximumLoads int
	// TypeScriptMaximumWorkers bounds concurrent TypeScript workers. Zero
	// uses the documented default.
	TypeScriptMaximumWorkers int
	TypeScriptWorker         string
	// TypeScriptIncludeUnclaimedSources indexes the TypeScript files no
	// project of a repository claims, through the engine's inferred project.
	// It is off by default: those files are real code with real callers, and
	// the compiler options they are checked under are Kivgraph's choice
	// rather than a declaration of the project that would have owned them.
	TypeScriptIncludeUnclaimedSources bool
	// RustAnalyzer is the command line of the external Rust indexer.
	RustAnalyzer string
	// RustTargetDirectory is where cargo writes the artifacts of the Rust
	// analysis. It lives outside every indexed repository, because
	// rust-analyzer always runs build scripts.
	RustTargetDirectory string
	// RustMaximumWorkspaces bounds concurrent analyzer processes. Zero uses
	// the documented default: each one holds a whole workspace in memory.
	RustMaximumWorkspaces int
	RustFeatures          []string
	RustAllFeatures       bool
	RustNoDefaultFeatures bool
	RustCfgs              []string
	RustBuildScripts      bool
	RustProcMacros        bool
	// RustIncludeTests sets `cfg(test)` for the crates of a workspace.
	RustIncludeTests bool
	// RustAllowNetwork lets cargo reach a registry while a workspace loads.
	RustAllowNetwork bool
	RustSysroot      string
	// RustIndexSysroot puts the standard library of the toolchain in the
	// graph as a synthetic provider. It is off by default: it multiplies the
	// symbol count by an order of magnitude, and its absence leaves the
	// graph exactly as it was, declaring what it lost.
	RustIndexSysroot        bool
	PythonIndexer           string
	PythonAnalyzer          string
	PythonAnalyzerMode      string
	PythonPath              string
	PythonMaximumWorkers    int
	PythonIncludeTests      bool
	PythonIncludeGenerated  bool
	PythonIncludeExternal   bool
	DartAnalyzer            string
	DartSDKPath             string
	DartMaximumWorkers      int
	DartIncludeTests        bool
	DartIncludeGenerated    bool
	DartIncludeExternal     bool
	DartIncludeSDK          bool
	DartPackageConfig       string
	DartWaitForAnalysis     bool
	DartMaximumAnalysisTime time.Duration
	JavaIndexerCommand      string
	JavaBuildTool           string
	JavaMaximumWorkers      int
	JavaIncludeTests        bool
	JavaIncludeGenerated    bool
	// JavaTargetDirectory is where scip-java writes its SemanticDB output and
	// its index. It lives outside every indexed repository for the reason
	// RustTargetDirectory does: the analyzer's output is not the repository's
	// source, and an index that leaves artefacts behind has modified what it
	// came to read.
	JavaTargetDirectory    string
	JavaMaximumIndexTime   time.Duration
	CSharpIndexerCommand   string
	CSharpProject          string
	CSharpMaximumWorkers   int
	CSharpIncludeTests     bool
	CSharpIncludeGenerated bool
	CSharpSkipRestore      bool
	CSharpTargetDirectory  string
	CSharpMaximumIndexTime time.Duration
	WorkingDirectory       string
	// CacheMode selects whether a unit may be served from its stored
	// facts. Empty is CacheOff.
	CacheMode CacheMode
	// CacheDirectory holds one entry per analysis unit. It lives outside
	// every indexed repository, like the rest of the state.
	CacheDirectory string

	// Progress, when set, is called synchronously as each unit of work
	// starts and finishes. It must not block: a slow callback slows the
	// index down.
	Progress func(ProgressEvent)
}

FullOptions configures one clean semantic indexing pass. The pass never writes inside a registered repository: Go's synthetic workspace and the temporary TypeScript facts payloads live outside the sources.

type FullReport

type FullReport struct {
	// Cache reports what the fact cache did, so a pass says how much of
	// itself it skipped and on whose authority.
	Cache CacheReport
	// TypeScriptWithoutPackages names the repositories registered as
	// TypeScript that declare no named package with a project. A manifest
	// alone is not one: a repository of loose .mjs files beside a
	// package.json has no project for a program to be built from. They
	// contribute nothing, and a registry entry that contributes nothing
	// looks like coverage.
	TypeScriptWithoutPackages []string
	// GoDiagnostics carries what the Go loader reported without blocking
	// the pass. The count alone said something happened and nothing said
	// what, and a diagnostic nobody can read is a diagnostic nobody has.
	GoDiagnostics []string

	GoRepositories int
	GoModules      int
	GoLoads        int
	GoLoadErrors   int
	// GoLoadDiagnostics counts the diagnostics that did not block the pass:
	// a directory with no file to select, and the advisory the loader
	// attaches to it.
	GoLoadDiagnostics int
	// GoModulesNotLoaded counts the modules the loader could not read. Their
	// facts are absent and declared; the pass still publishes the rest.
	GoModulesNotLoaded int
	// GoModulesNotRead names each of those modules and why, one line each.
	//
	// It is not GoDiagnostics: that field is what the loader said about a
	// module it nevertheless read, and this is the class that produced no
	// facts at all. Keeping them apart is what lets a reader see
	// "not_loaded=4 diagnostics=1" and still learn what the four were --
	// the count travels today and the reason was reachable only by
	// querying the published graph for its MODULE_NOT_LOADED rows, which
	// no command exposes. A hollow graph nobody can explain is how an
	// index passes and answers about nothing.
	GoModulesNotRead []string
	// GoWorkspaces counts the synthetic go.work files this pass installed.
	// A module that reaches no other registered module loads without one.
	GoWorkspaces           int
	GoDefinitions          int
	GoReferences           int
	GoUnresolved           int
	TypeScriptRepositories int
	TypeScriptSymbols      int
	TypeScriptReferences   int
	TypeScriptUnresolved   int
	// TypeScriptAmbiguous counts the package names several manifests of one
	// repository declare. No manifest provides them.
	TypeScriptAmbiguous int
	// TypeScriptUnclaimedSources counts the source files no project of a
	// repository claims and that this pass indexed anyway, through the
	// inferred project. It is zero unless
	// TypeScriptIncludeUnclaimedSources is on.
	TypeScriptUnclaimedSources int
	// TypeScriptUnclaimedWithoutPackage names the unclaimed files that no
	// package unit encloses. Nothing can index them -- a file needs a
	// package to belong to and a project to be analysed beside -- so the
	// pass names them instead of dropping them in silence.
	TypeScriptUnclaimedWithoutPackage []string
	RustRepositories                  int
	RustWorkspaces                    int
	RustCrates                        int
	RustSymbols                       int
	RustReferences                    int
	RustUnresolved                    int
	// RustWorkspacesNotLoaded counts the workspaces the analyzer could not
	// read. Their facts are absent and declared; the pass publishes the rest.
	RustWorkspacesNotLoaded int
	// RustDiagnostics carries what the analyzer reported without blocking
	// the pass, which is where a degraded load says so.
	RustDiagnostics []string
	// RustWithoutWorkspaces names the repositories registered as Rust that
	// declare no Cargo manifest. They contribute nothing, and a registry
	// entry that contributes nothing looks like coverage.
	RustWithoutWorkspaces []string
	PythonRepositories    int
	PythonSymbols         int
	PythonReferences      int
	PythonUnresolved      int
	// PythonRepositoriesNotLoaded and DartRepositoriesNotLoaded count the
	// repositories whose analyzer is not installed on this machine. Their
	// facts are absent and the pass says so, rather than one absent toolchain
	// deciding whether every other repository gets a graph.
	PythonRepositoriesNotLoaded int
	DartRepositories            int
	DartSymbols                 int
	DartReferences              int
	DartUnresolved              int
	DartRepositoriesNotLoaded   int
	JavaRepositories            int
	JavaSymbols                 int
	JavaReferences              int
	JavaUnresolved              int
	JavaRepositoriesNotLoaded   int
	CSharpRepositories          int
	CSharpSymbols               int
	CSharpReferences            int
	CSharpUnresolved            int
	CSharpRepositoriesNotLoaded int
	// EdgesWithoutProvider counts the edges the merge dropped because the
	// repository that provides the target does not publish its declaration.
	// Each one is declared as an unresolved reference with the position that
	// was observed.
	EdgesWithoutProvider int
	// RustSysroot names the synthetic repository the standard library was
	// published under, empty when it is not in this graph.
	RustSysroot string
	// RustSysrootReason says why the standard library is absent. It is set
	// whenever RustSysroot is empty, because a reader cannot tell a machine
	// without a toolchain from a configuration that asked for nothing.
	RustSysrootReason string
	SyntheticWorkFile string
}

FullReport records the work performed before the caller publishes the resulting facts. Counts are informational; an error is never hidden in a successful report.

func Full

func Full(ctx context.Context, options FullOptions) (facts.Set, FullReport, error)

Full loads every configured repository and normalises the authoritative Go and TypeScript facts into one validated set. A loader diagnostic aborts the pass instead of publishing a graph that is known to be incomplete.

type ProgressEvent

type ProgressEvent struct {
	Phase      ProgressPhase
	Repository string
	Detail     string
	Started    bool
	Completed  int
	Total      int
}

ProgressEvent reports that one unit of indexing work started or finished. Completed counts finished units of the phase and is 0 on a start event; Total is 0 when the phase has no countable units.

type ProgressPhase

type ProgressPhase string

ProgressPhase names the unit of work a progress event belongs to.

const (
	// PhaseGo is one Go module of one repository.
	PhaseGo ProgressPhase = "go"
	// PhaseTypeScript is one TypeScript repository.
	PhaseTypeScript ProgressPhase = "typescript"
	// PhaseRust is one Cargo workspace.
	PhaseRust ProgressPhase = "rust"
	// PhasePython is one Python repository.
	PhasePython ProgressPhase = "python"
	// PhaseDart is one Dart package repository.
	PhaseDart ProgressPhase = "dart"
	// PhaseJava is one Java repository.
	PhaseJava ProgressPhase = "java"
	// PhaseCSharp is one C# repository.
	PhaseCSharp ProgressPhase = "csharp"
	// PhaseSemantic names a semantic unit whose language has no phase of its
	// own. Nothing reaches it today; it exists so an unnamed language reports
	// progress under a truthful label instead of another language's.
	PhaseSemantic ProgressPhase = "semantic"
	// PhaseMerge is the final sort and validation of the merged fact set.
	PhaseMerge ProgressPhase = "merge"
)

Jump to

Keyboard shortcuts

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