Documentation
¶
Overview ¶
Package facts defines the canonical semantic facts every language produces.
TypeScript and Go resolve code with different engines and different vocabularies. This package is where both converge: after normalisation a fact carries no trace of the engine that produced it beyond its declared provenance, so the graph can store one model instead of two.
Index ¶
- Constants
- Variables
- func EvidenceKey(fileKey string, start, end int) string
- func FileKey(repository, path string) string
- func IsSyntheticRepository(name string) bool
- func NormalizeGo(ctx context.Context, input GoInput) (Set, GoReport, error)
- func NormalizeRust(ctx context.Context, input RustInput) (Set, RustReport, error)
- func NormalizeTypeScript(ctx context.Context, payload TypeScriptPayload, ...) (Set, TypeScriptReport, error)
- func PackageKey(language Language, repository, name string) string
- func RepositoryKey(name string) string
- func RepositoryNameFromKey(value string) string
- func SemanticTargetKey(language Language, target SemanticTarget) (string, error)
- func UnresolvedKey(reference UnresolvedReference) string
- type Confidence
- type Edge
- type EdgeKind
- type Evidence
- type File
- type GoInput
- type GoReport
- type Language
- type Package
- type Position
- type Provenance
- type Repository
- type RustInput
- type RustReport
- type SemanticDiagnostic
- type SemanticFile
- type SemanticImport
- type SemanticPackage
- type SemanticPart
- type SemanticPayload
- type SemanticReference
- type SemanticSymbol
- type SemanticTarget
- type SemanticUnresolved
- type Set
- type Symbol
- type TypeScriptDependency
- type TypeScriptExport
- type TypeScriptExtends
- type TypeScriptImport
- type TypeScriptImportTarget
- type TypeScriptPackage
- type TypeScriptPayload
- type TypeScriptReference
- type TypeScriptReport
- type TypeScriptRepository
- type TypeScriptSymbol
- type TypeScriptUnresolved
- type UnresolvedReference
Constants ¶
const ( CodeContainsPackage uint8 = iota + 1 CodeContainsFile CodeDefines CodePackageDependsOn CodeModuleDependsOn CodeImportsSymbol CodeExports CodeReexports CodeReferences CodeCallsDirect CodePassesAsCallback CodeAssignsFunction CodeReturnsFunction CodeTypeUses CodeImplements CodeExtends CodeEmbeds CodeOverrides CodePartOf CodeMethodOf )
Edge kind codes. Frozen: append only.
const ( CodeExactTypechecked uint8 = iota + 1 CodeExactDeclarationMapped CodeExactPackageMapped CodeStructuralCertain CodeCandidate CodeUnresolved )
Confidence codes. Frozen: append only. The order matches the strength ordering of the model, strongest first, so a comparison on the code is a comparison on strength.
const ( CodeTypeScriptChecker uint8 = iota + 1 CodeTypeScriptModuleResolution CodeTypeScriptDeclarationMap CodeTypeScriptProjectReference CodeGoTypesDefinition CodeGoTypesUse CodeGoTypesSelection CodeGoASTCall CodeGoASTCallback CodeGoObjectPath CodeTreeSitterSyntax CodePackageManifest // Appended for Rust. Never inserted above: a snapshot stores these // numbers, and renumbering one rewrites the meaning of every edge that // carries it. CodeRustAnalyzerDefinition CodeRustAnalyzerUse CodeRustAnalyzerMoniker CodeRustSyntaxCall CodeRustSyntaxType CodeRustSyntaxImplementation CodeRustSyntaxCallback CodePythonIndexerDefinition CodePythonIndexerUse CodePythonSyntaxCall CodeDartAnalyzerDefinition CodeDartAnalyzerUse CodeDartSyntaxCall CodeJavaScipDefinition CodeJavaScipUse CodeCSharpScipDefinition CodeCSharpScipUse )
Provenance codes. Frozen: append only.
const ( // TypeScriptIdentityDeclarationMap marks a target the artifact's own // `.d.ts.map` placed inside the provider's source. TypeScriptIdentityDeclarationMap = "DECLARATION_MAP" // TypeScriptIdentityProviderExport marks a target the provider's own // checker named, as the export of a source file the provider's project // roots mapped its declaration artifact to. The position is exact and // comes from the compiler that owns the code, but the artifact-to-source // step rests on the provider's build configuration rather than on a map // it emitted, so the edge is graded ExactPackageMapped. See ADR 0038. TypeScriptIdentityProviderExport = "PROVIDER_EXPORT" )
const CodeFormatVersion uint16 = 1
CodeFormatVersion is the version of the numbering below. The HotSnapshot stores kinds, confidences and provenances as bare uint8 codes and filters traversals by them, so a snapshot is only readable by code that agrees on this numbering. Reordering or reusing a code is a format break: bump this version instead, and never renumber an existing constant.
const ModuleSymbolKind = "module"
ModuleSymbolKind is the kind of the synthetic symbol that stands for a file's own top level scope.
A use needs a declaration on both ends to become an edge, and some uses have none: a call in a top level statement, and a call inside an anonymous function passed as an argument -- the body of `it(...)` or `beforeEach(...)` in a test, a callback handed to a router, a closure in an initialiser. The checker resolves those targets perfectly well; what is missing is a source.
Dropping them is not a small loss. Measured on `packages/core` of the workspace monorepo: 98 of 14100 uses in ordinary source, all of them top level statements in bootstrap files, and 38 of 38 uses in a test file -- every call a `vitest` file makes, because the idiom puts all of them inside a callback.
So the file's own scope is a declaration like any other. The symbol covers the whole file, which is what makes it the loosest possible owner: anything narrower wins, and it is only reached when nothing else contains the use. The convention is the one `internal/dartloader` already established for a Dart library, extended to the languages that had no name for it.
const RepositoryKeyPrefix = "repository:"
RepositoryKeyPrefix opens the durable key of a repository. It is exported because the read surface filters by that key, so a caller's value has to be read back as a name in one place rather than by matching the literal in several.
const TypeScriptWireVersion = 4
TypeScriptWireVersion is the version of the `ts-facts-v4` payload.
const UnresolvedFileOutsideRepository = "FILE_OUTSIDE_REPOSITORY"
UnresolvedFileOutsideRepository is retained when a payload reports a file whose repository-relative path climbs out of its own repository. A consumer resolving an import into a workspace sibling's built declarations gets `../../libraries/library-shared/dist/...`, and that names a file the sibling owns.
The relation between the two repositories does not depend on this file and is not affected: an import binding's target identity is built from the provider's own repository and package, so the edge is byte identical to the key the provider assigns its own declaration. What is retired here are the uses whose **source** file is the provider's output -- facts about the provider, which the provider's own pass is the one to report.
Variables ¶
var ErrInvalidFacts = errors.New("invalid fact set")
ErrInvalidFacts reports a fact set that cannot be stored.
var ErrUnknownCode = errors.New("unknown canonical code")
ErrUnknownCode reports a code outside the canonical numbering.
Functions ¶
func EvidenceKey ¶
EvidenceKey builds the durable key of one observation.
func IsSyntheticRepository ¶
IsSyntheticRepository reports whether a repository is one Kivgraph derives from the machine -- today the standard library of a Rust toolchain -- rather than one a user registered. The reserved namespace is enforced when a name is registered, so the name is the answer and no row carries a second copy of it.
func NormalizeGo ¶
NormalizeGo converts the facts of one Go load into the canonical model.
Only facts with a durable identity on both ends become edges. A reference whose target is not indexed is not downgraded to a name: it is dropped and counted, because a graph edge without identity is a wrong edge.
func NormalizeRust ¶
NormalizeRust converts the analysis of one Cargo workspace into the canonical model.
Only facts with a durable identity on both ends become edges. A target in another repository is named by the key its provider publishes, so this Set alone fails Validate with a dangling edge until the caller merges the provider's Set in -- the same contract the TypeScript and Go paths keep.
func NormalizeTypeScript ¶
func NormalizeTypeScript( ctx context.Context, payload TypeScriptPayload, repository workspace.Repository, ) (Set, TypeScriptReport, error)
NormalizeTypeScript converts a worker payload into the canonical model.
repository is the registered repository the payload was produced from. The payload carries only repository-relative paths, and the worker cannot observe the git state of the tree it read: both come from the caller, the same way NormalizeGo and NormalizeRust take them.
func PackageKey ¶
PackageKey builds the durable key of a package or module.
func RepositoryKey ¶
RepositoryKey builds the durable key of a repository.
func RepositoryNameFromKey ¶
RepositoryNameFromKey reads the name out of a repository key, and returns its argument unchanged when it is already a name.
func SemanticTargetKey ¶ added in v0.3.3
func SemanticTargetKey(language Language, target SemanticTarget) (string, error)
SemanticTargetKey derives the same durable key a provider declaration will receive when its own payload is normalised. It is shared by the consumer normaliser and the merge bridge so cross-repository edges cannot drift.
func UnresolvedKey ¶
func UnresolvedKey(reference UnresolvedReference) string
UnresolvedKey derives the durable key of an unresolved reference from the same identity Merge deduplicates on.
The file key already carries the repository, so it is the scope whenever there is one. An entry without a file -- a class a provider declares, a module that would not load -- is scoped by the repository instead: two repositories declaring the same class are two facts, and sharing one key made them one row and then a duplicate primary key when they did not.
Types ¶
type Confidence ¶
type Confidence string
Confidence is the trust level of an edge, as defined by the plan.
const ( // ExactTypechecked is backed by a type checker resolution. ExactTypechecked Confidence = "EXACT_TYPECHECKED" // ExactDeclarationMapped is backed by a declaration map. ExactDeclarationMapped Confidence = "EXACT_DECLARATION_MAPPED" // ExactPackageMapped is backed by a registered package provider. ExactPackageMapped Confidence = "EXACT_PACKAGE_MAPPED" // StructuralCertain is backed by an unambiguous structural rule. StructuralCertain Confidence = "STRUCTURAL_CERTAIN" // Candidate is plausible but not proven. Candidate Confidence = "CANDIDATE" // Unresolved carries no target identity. Unresolved Confidence = "UNRESOLVED" )
func ConfidenceFromCode ¶
func ConfidenceFromCode(code uint8) (Confidence, error)
ConfidenceFromCode decodes a stored confidence.
func (Confidence) Code ¶
func (confidence Confidence) Code() (uint8, error)
Code returns the frozen numeric code of the confidence.
func (Confidence) Exact ¶
func (confidence Confidence) Exact() bool
Exact reports whether a confidence level may take part in exact results.
type Edge ¶
type Edge struct {
Kind EdgeKind `json:"kind"`
SourceKey string `json:"source_key"`
TargetKey string `json:"target_key"`
Confidence Confidence `json:"confidence"`
Provenance Provenance `json:"provenance"`
// EvidenceKey links the edge to its observation, when it has one.
EvidenceKey string `json:"evidence_key,omitempty"`
}
Edge is one relation between two symbols or containers.
type EdgeKind ¶
type EdgeKind string
EdgeKind is the relation vocabulary of the graph.
const ( ContainsPackage EdgeKind = "CONTAINS_PACKAGE" ContainsFile EdgeKind = "CONTAINS_FILE" Defines EdgeKind = "DEFINES" PackageDependsOn EdgeKind = "PACKAGE_DEPENDS_ON" ModuleDependsOn EdgeKind = "MODULE_DEPENDS_ON" ImportsSymbol EdgeKind = "IMPORTS_SYMBOL" Exports EdgeKind = "EXPORTS" Reexports EdgeKind = "REEXPORTS" References EdgeKind = "REFERENCES" CallsDirect EdgeKind = "CALLS_DIRECT" PassesAsCallback EdgeKind = "PASSES_AS_CALLBACK" AssignsFunction EdgeKind = "ASSIGNS_FUNCTION" ReturnsFunction EdgeKind = "RETURNS_FUNCTION" TypeUses EdgeKind = "TYPE_USES" Implements EdgeKind = "IMPLEMENTS" Extends EdgeKind = "EXTENDS" Embeds EdgeKind = "EMBEDS" Overrides EdgeKind = "OVERRIDES" // PartOf links the synthetic module symbol for a Dart part to the // synthetic module symbol for its library. It is a Symbol relation so it // remains available through the compact snapshot and normal graph queries. PartOf EdgeKind = "PART_OF" // MethodOf links a method to the type that declares it, and it exists // because a line range cannot express that pairing in every language. // ADR 0059 derives containment from the span, which covers a TypeScript // class -- its methods sit between its braces -- and misses both a Go // method, declared outside its struct as `func (h *T) M()`, and a Rust // one, declared inside an `impl` block that LUQUE-2008 does not publish. // Without this the reach of a Go or Rust type excluded the reach of its // methods while a TypeScript answer looked identical and was complete. // // The pairing is observed, never spelled: Go reads the receiver // `go/types` resolved, and Rust reads the type parameter of the `impl` // descriptor rust-analyzer emits. The dotted qualified name is a // convention of the name generator and is not evidence, which is the // same ground ADR 0059 refused to build on. // // It is containment and not a use, so it stays out of the reference // vocabulary: a type is not referenced by its own methods. MethodOf EdgeKind = "METHOD_OF" )
func EdgeKindFromCode ¶
EdgeKindFromCode decodes a stored edge kind.
type Evidence ¶
type Evidence struct {
Key string `json:"key"`
RepositoryKey string `json:"repository_key"`
FileKey string `json:"file_key"`
Start Position `json:"start"`
End Position `json:"end"`
// Text is the source excerpt when it is small enough to retain.
Text string `json:"text,omitempty"`
}
Evidence is the observation that supports one edge.
type File ¶
type File struct {
Key string `json:"key"`
RepositoryKey string `json:"repository_key"`
PackageKey string `json:"package_key,omitempty"`
Path string `json:"path"`
Language Language `json:"language"`
ContentHash string `json:"content_hash,omitempty"`
Generated bool `json:"generated,omitempty"`
}
File is one indexed source file.
type GoInput ¶
type GoInput struct {
Repository workspace.Repository
// Definitions carry the durable identity assigned by LUQUE-0804.
Definitions []goloader.KeyedDefinition
// References are the classified uses of LUQUE-0806, 0807 and 0814.
References []goloader.Reference
// CrossRepository attributes targets to their provider repository.
CrossRepository []goloader.CrossRepositoryReference
// PackageDependencies are the deduplicated (source, target) package
// pairs a package-boundary use belongs to. Each one may become
// PACKAGE_DEPENDS_ON and, when it also crosses a Go module boundary,
// MODULE_DEPENDS_ON.
PackageDependencies []goloader.PackageDependency
// TypeRelations are the IMPLEMENTS, EMBEDS and OVERRIDES facts: structural
// relations the type checker decides on its own, with no source
// occurrence of their own to anchor them.
TypeRelations []goloader.TypeRelation
// Unresolved are the classified failures of LUQUE-0810.
Unresolved []goloader.UnresolvedReference
}
GoInput is one normalisation request: the facts of a single Go load.
type GoReport ¶
type GoReport struct {
// EdgesWithoutSource counts references, type relations and package
// dependencies whose source has no durable identity in this pass,
// typically a use at file scope or a package with no definitions.
EdgesWithoutSource int
// EdgesWithoutTarget counts references, type relations and package
// dependencies whose target is not indexed in this pass and was not
// attributed to a provider repository.
EdgesWithoutTarget int
// UnresolvedWithoutFile counts module-level failures with no file.
UnresolvedWithoutFile int
// FactsOutsideRepository counts facts dropped because the file holding
// them is not inside the repository being indexed. Asking the Go loader
// for compiled files means a cgo or generated package reports positions
// inside the build cache; those are retained as unresolved, never as
// evidence.
FactsOutsideRepository int
// EdgesOwnedByModule counts uses whose owner is the file's own scope: a
// use at file level, with no declaration enclosing it. They were dropped
// before the module symbol gave them a source.
EdgesOwnedByModule int
}
GoReport records what normalisation could not keep, so a dropped fact is visible instead of silently missing.
type Language ¶
type Language string
Language identifies the engine domain a fact belongs to.
const ( // LanguageTypeScript marks facts produced by the TypeScript worker. LanguageTypeScript Language = "typescript" // LanguageGo marks facts produced by the Go loader. LanguageGo Language = "go" // LanguageRust marks facts produced by the Rust loader over the index // rust-analyzer emits. LanguageRust Language = "rust" // LanguagePython marks facts produced by the configured Python semantic indexer. LanguagePython Language = "python" // LanguageDart marks facts produced by the Dart analysis-server loader. LanguageDart Language = "dart" // LanguageJava marks facts produced by the SCIP loader over the index // scip-java emits. LanguageJava Language = "java" // LanguageCSharp marks facts produced by the SCIP loader over the index // scip-dotnet emits. LanguageCSharp Language = "csharp" )
type Package ¶
type Package struct {
Key string `json:"key"`
RepositoryKey string `json:"repository_key"`
Language Language `json:"language"`
Name string `json:"name"`
Version string `json:"version,omitempty"`
RootPath string `json:"root_path"`
ManifestPath string `json:"manifest_path,omitempty"`
// Container is the module a Go package belongs to, empty otherwise.
Container string `json:"container,omitempty"`
}
Package is one package or module of a repository.
type Position ¶
type Position struct {
Line int `json:"line"`
Column int `json:"column"`
Offset int `json:"offset"`
}
Position is a source location. Lines are one based, columns zero based.
type Provenance ¶
type Provenance string
Provenance names the mechanism that produced a fact.
const ( TypeScriptChecker Provenance = "TYPESCRIPT_CHECKER" TypeScriptModuleResolution Provenance = "TYPESCRIPT_MODULE_RESOLUTION" TypeScriptDeclarationMap Provenance = "TYPESCRIPT_DECLARATION_MAP" TypeScriptProjectReference Provenance = "TYPESCRIPT_PROJECT_REFERENCE" GoTypesDefinition Provenance = "GO_TYPES_DEF" GoTypesUse Provenance = "GO_TYPES_USE" GoTypesSelection Provenance = "GO_TYPES_SELECTION" GoASTCall Provenance = "GO_AST_CALL" GoASTCallback Provenance = "GO_AST_CALLBACK" GoObjectPath Provenance = "GO_OBJECT_PATH" // RustAnalyzerDefinition marks a declaration the analyzer indexed. RustAnalyzerDefinition Provenance = "RUST_ANALYZER_DEF" // RustAnalyzerUse marks a use the analyzer resolved to a symbol. RustAnalyzerUse Provenance = "RUST_ANALYZER_USE" // RustAnalyzerMoniker marks a target reached through the crate registry, // where consumer and provider carry the same analyzer symbol. RustAnalyzerMoniker Provenance = "RUST_ANALYZER_MONIKER" // RustSyntaxCall and RustSyntaxType mark relations whose ends the // analyzer resolved and whose class the grammar decided, exactly as // GoASTCall does over a go/types resolution. RustSyntaxCall Provenance = "RUST_SYNTAX_CALL" RustSyntaxType Provenance = "RUST_SYNTAX_TYPE" // RustSyntaxImplementation marks an implementation, a supertrait or an // override: the grammar says which token of the header is the trait and // which is the type, and the analyzer resolved both. RustSyntaxImplementation Provenance = "RUST_SYNTAX_IMPL" // RustSyntaxCallback marks a function named as the argument of a call, // the Rust half of GoASTCallback. Binding a function to a name or // returning it carries no provenance of its own: the class is in the // edge kind and the target came from the analyzer, as Go does. RustSyntaxCallback Provenance = "RUST_SYNTAX_CALLBACK" PythonIndexerDefinition Provenance = "PYTHON_INDEXER_DEF" PythonIndexerUse Provenance = "PYTHON_INDEXER_USE" PythonSyntaxCall Provenance = "PYTHON_SYNTAX_CALL" DartAnalyzerDefinition Provenance = "DART_ANALYZER_DEF" DartAnalyzerUse Provenance = "DART_ANALYZER_USE" DartSyntaxCall Provenance = "DART_SYNTAX_CALL" // JavaScipDefinition and JavaScipUse mark facts read from the SCIP index // scip-java produces. The index is emitted by the SemanticDB javac // plugin, so its targets are resolved by the compiler itself. JavaScipDefinition Provenance = "JAVA_SCIP_DEF" JavaScipUse Provenance = "JAVA_SCIP_USE" // CSharpScipDefinition and CSharpScipUse mark facts read from the SCIP // index scip-dotnet produces with Roslyn. CSharpScipDefinition Provenance = "CSHARP_SCIP_DEF" CSharpScipUse Provenance = "CSHARP_SCIP_USE" TreeSitterSyntax Provenance = "TREE_SITTER_SYNTAX" PackageManifest Provenance = "PACKAGE_MANIFEST" )
func ProvenanceFromCode ¶
func ProvenanceFromCode(code uint8) (Provenance, error)
ProvenanceFromCode decodes a stored provenance.
func (Provenance) Code ¶
func (provenance Provenance) Code() (uint8, error)
Code returns the frozen numeric code of the provenance.
func (Provenance) Exact ¶
func (provenance Provenance) Exact() bool
Exact reports whether a provenance can support an exact edge. A relation produced only by Tree-sitter never is, as the plan requires.
type Repository ¶
type Repository struct {
Key string `json:"key"`
Name string `json:"name"`
RootPath string `json:"root_path"`
Commit string `json:"commit,omitempty"`
Branch string `json:"branch,omitempty"`
Dirty bool `json:"dirty,omitempty"`
Languages []Language `json:"languages,omitempty"`
}
Repository is one indexed repository.
type RustInput ¶
type RustInput struct {
Repository workspace.Repository
Analysis rustloader.Analysis
}
RustInput is one normalisation request: the facts of a single Cargo workspace, as the analyzer indexed it.
type RustReport ¶
type RustReport struct {
// EdgesWithoutSource counts uses with no enclosing declaration.
EdgesWithoutSource int
// EdgesWithoutTarget counts edges this Set could not close: an end it
// could not place in a file or a crate of its own, or a target of this
// repository that the pass decided not to publish. No merge resolves
// either, so the edge is dropped here instead of dangling in the graph.
EdgesWithoutTarget int
// FilesWithoutPackage counts indexed files whose crate no manifest of this
// workspace declares. They are dropped: a file belongs to exactly one
// package, and a row without one is rejected when the generation is built.
FilesWithoutPackage int
// DefinitionsWithoutCrate counts symbols whose crate no manifest of this
// workspace declares, which is a discovery and an index that disagree.
DefinitionsWithoutCrate int
// UnresolvedWithoutFile counts workspace level failures with no file.
UnresolvedWithoutFile int
}
RustReport records what normalisation could not keep, so a dropped fact is visible instead of silently missing.
type SemanticDiagnostic ¶ added in v0.3.3
type SemanticDiagnostic struct {
File string `json:"file,omitempty"`
Reason string `json:"reason"`
Detail string `json:"detail,omitempty"`
StartLine int `json:"startLine,omitempty"`
StartColumn int `json:"startColumn,omitempty"`
}
SemanticDiagnostic records a limitation observed by an external producer. Diagnostics are facts about coverage, not graph edges, and are preserved in payload tooling even when the canonical graph only stores unresolved rows.
type SemanticFile ¶ added in v0.3.3
type SemanticImport ¶ added in v0.3.3
type SemanticImport struct {
File string `json:"file"`
SourceID string `json:"sourceId"`
// Kind is an optional canonical edge kind. Empty preserves the historical
// IMPORTS_SYMBOL meaning for payloads produced before Dart exports existed.
Kind string `json:"kind,omitempty"`
RequestedPackage string `json:"requestedPackage"`
RequestedSymbol string `json:"requestedSymbol"`
Alternatives []string `json:"alternatives,omitempty"`
Prefix string `json:"prefix,omitempty"`
Deferred bool `json:"deferred,omitempty"`
TargetID string `json:"targetId,omitempty"`
StartLine int `json:"startLine"`
StartColumn int `json:"startColumn"`
Start int `json:"start"`
EndLine int `json:"endLine,omitempty"`
EndColumn int `json:"endColumn,omitempty"`
End int `json:"end,omitempty"`
Detail string `json:"detail,omitempty"`
Target *SemanticTarget `json:"target,omitempty"`
}
type SemanticPackage ¶ added in v0.3.3
type SemanticPart ¶ added in v0.3.3
type SemanticPart struct {
File string `json:"file,omitempty"`
LibraryFile string `json:"libraryFile"`
PartFile string `json:"partFile"`
StartLine int `json:"startLine"`
StartColumn int `json:"startColumn"`
Start int `json:"start"`
EndLine int `json:"endLine,omitempty"`
EndColumn int `json:"endColumn,omitempty"`
End int `json:"end,omitempty"`
Detail string `json:"detail,omitempty"`
}
SemanticPart records Dart's library/part relationship. A part contributes declarations to its library, so it is deliberately kept separate from an import/export symbol edge; the canonical graph still exposes both files and their definitions independently.
File is where the directive was observed, which LibraryFile and PartFile do not say: they name the two ends of the relation. Dart declares it from both -- `part 'piece.dart';` and `part of 'feature.dart';` -- so one relation arrives as two rows that differ only in where they were seen.
type SemanticPayload ¶ added in v0.3.3
type SemanticPayload struct {
Version int `json:"version"`
// Authoritative is true only when the producer resolved references with a
// language type analyzer. Syntax-only fallbacks may still provide useful
// candidate edges, but they must never be published as exact knowledge.
Authoritative bool `json:"authoritative,omitempty"`
Analyzer string `json:"analyzer,omitempty"`
AnalyzerVersion string `json:"analyzerVersion,omitempty"`
Variant string `json:"variant,omitempty"`
Repository string `json:"repository"`
Language Language `json:"language"`
Package SemanticPackage `json:"package"`
Files []SemanticFile `json:"files"`
Symbols []SemanticSymbol `json:"symbols"`
References []SemanticReference `json:"references"`
Imports []SemanticImport `json:"imports"`
Parts []SemanticPart `json:"parts,omitempty"`
Unresolved []SemanticUnresolved `json:"unresolved"`
Diagnostics []SemanticDiagnostic `json:"diagnostics,omitempty"`
}
SemanticPayload is the deliberately small boundary shared by external semantic loaders. The producer owns resolution; this package owns durable identities and the canonical graph model.
type SemanticReference ¶ added in v0.3.3
type SemanticReference struct {
File string `json:"file"`
SourceID string `json:"sourceId"`
TargetID string `json:"targetId"`
Kind string `json:"kind"`
StartLine int `json:"startLine"`
StartColumn int `json:"startColumn"`
Start int `json:"start"`
EndLine int `json:"endLine"`
EndColumn int `json:"endColumn"`
End int `json:"end"`
Text string `json:"text,omitempty"`
Target *SemanticTarget `json:"target,omitempty"`
}
type SemanticSymbol ¶ added in v0.3.3
type SemanticSymbol struct {
ID string `json:"id"`
File string `json:"file"`
Name string `json:"name"`
QualifiedName string `json:"qualifiedName"`
Kind string `json:"kind"`
Exported bool `json:"exported"`
Signature string `json:"signature,omitempty"`
StartLine int `json:"startLine"`
StartColumn int `json:"startColumn"`
Start int `json:"start"`
EndLine int `json:"endLine"`
EndColumn int `json:"endColumn"`
End int `json:"end"`
}
type SemanticTarget ¶ added in v0.3.3
type SemanticTarget struct {
Repository string `json:"repository"`
Package string `json:"package"`
File string `json:"file"`
QualifiedName string `json:"qualifiedName"`
Kind string `json:"kind"`
Signature string `json:"signature"`
Source string `json:"source,omitempty"`
}
SemanticTarget is the provider identity of a declaration outside the payload's repository. The full index resolves this identity after all language units have been merged; a loader must never invent a local symbol for an external target it could not inspect.
type SemanticUnresolved ¶ added in v0.3.3
type SemanticUnresolved struct {
File string `json:"file"`
SourceID string `json:"sourceId,omitempty"`
RequestedPackage string `json:"requestedPackage,omitempty"`
RequestedSymbol string `json:"requestedSymbol,omitempty"`
Reason string `json:"reason"`
Detail string `json:"detail,omitempty"`
StartLine int `json:"startLine"`
StartColumn int `json:"startColumn"`
Start int `json:"start"`
}
type Set ¶
type Set struct {
Repositories []Repository `json:"repositories"`
Packages []Package `json:"packages"`
Files []File `json:"files"`
Symbols []Symbol `json:"symbols"`
Evidence []Evidence `json:"evidence"`
Edges []Edge `json:"edges"`
Unresolved []UnresolvedReference `json:"unresolved"`
}
Set is the normalised output of one indexing pass.
func MergeAll ¶
MergeAll merges every set at once, deduplicated by durable key and sorted a single time.
Merging pairwise costs the whole accumulated set on every step: a thirty-three unit pass rebuilt and re-sorted two hundred thousand edges thirty-three times, which is quadratic in the size of the graph and was the largest single source of garbage in a full index.
func NormalizeSemantic ¶ added in v0.3.3
func NormalizeSemantic(ctx context.Context, repository workspace.Repository, payload SemanticPayload) (Set, error)
NormalizeSemantic converts one external payload into canonical facts. A target outside this payload is allowed to dangle until the full pass merges the provider set; an unproven target is still published as unresolved.
func (*Set) Merge ¶
Merge appends another set, keeping the result deduplicated by durable key.
Two repositories indexed in the same pass share provider symbols; merging by key is what keeps one symbol from becoming two nodes.
type Symbol ¶
type Symbol struct {
// Key is the durable stable key of LUQUE-0303.
Key string `json:"key"`
// CanonicalIdentity is the auditable text the key derives from.
CanonicalIdentity string `json:"canonical_identity"`
RepositoryKey string `json:"repository_key"`
PackageKey string `json:"package_key"`
FileKey string `json:"file_key"`
Language Language `json:"language"`
Name string `json:"name"`
QualifiedName string `json:"qualified_name"`
Kind string `json:"kind"`
Exported bool `json:"exported"`
Signature string `json:"signature,omitempty"`
Start Position `json:"start"`
End Position `json:"end"`
}
Symbol is one addressable declaration.
type TypeScriptDependency ¶
type TypeScriptDependency struct {
// Repository and Package name the provider exactly as PackageKey derives
// it: the repository Kivgraph indexes it under, and its own package name.
Repository string `json:"repository"`
Package string `json:"package"`
// File, Specifier, Start, End and StartLine are one deterministic import
// occurrence proving the dependency — never every occurrence, since a
// single edge needs only one witness.
File string `json:"file"`
Specifier string `json:"specifier"`
Start int `json:"start"`
End int `json:"end"`
StartLine int `json:"startLine"`
}
TypeScriptDependency is one real dependency from this repository's own package to another package the checker proved this repository imports from — never a nominal `package.json` entry, which may list a package nothing actually imports. TypeScript has no module concept distinct from its package, so this alone never becomes MODULE_DEPENDS_ON; only a Go package crossing a module boundary does.
type TypeScriptExport ¶
type TypeScriptExport struct {
File string `json:"file"`
Kind string `json:"kind"`
QualifiedName string `json:"qualifiedName"`
Start int `json:"start"`
End int `json:"end"`
StartLine int `json:"startLine"`
Text string `json:"text"`
TargetQualifiedName string `json:"targetQualifiedName"`
TargetFile string `json:"targetFile"`
Target *TypeScriptImportTarget `json:"target"`
RequestedPackage string `json:"requestedPackage"`
RequestedSymbol string `json:"requestedSymbol"`
Reason string `json:"reason"`
Detail string `json:"detail"`
}
TypeScriptExport is one export or re-export binding of the file: the worker turns the public name itself into an "export" kind TypeScriptSymbol, so QualifiedName here names an entry already present in Symbols. It resolves exactly one of two ways:
- TargetQualifiedName/TargetFile name a declaration already present in this same payload's Symbols — a direct export, or a re-export whose `from` clause stays inside this repository.
- Target carries the provider-source identity of a declaration in another repository — a re-export whose `from` clause names a package. Target is nil when that identity is not exactly known, exactly like an import without one: the binding still becomes an UnresolvedReference, never a guessed edge.
type TypeScriptExtends ¶
type TypeScriptExtends struct {
File string `json:"file"`
QualifiedName string `json:"qualifiedName"`
Start int `json:"start"`
End int `json:"end"`
StartLine int `json:"startLine"`
Text string `json:"text"`
TargetQualifiedName string `json:"targetQualifiedName"`
TargetFile string `json:"targetFile"`
Target *TypeScriptImportTarget `json:"target"`
RequestedPackage string `json:"requestedPackage"`
RequestedSymbol string `json:"requestedSymbol"`
Reason string `json:"reason"`
Detail string `json:"detail"`
}
TypeScriptExtends is one base of a `class ... extends` or `interface ... extends` clause: QualifiedName names the class or interface declaring the clause, already present in Symbols — a heritage clause introduces no binding of its own, unlike an import or an export. It resolves exactly one of two ways, exactly like TypeScriptExport:
- TargetQualifiedName/TargetFile name a declaration already present in this same payload's Symbols — a base declared in this repository.
- Target carries the provider-source identity of a declaration in another repository — a base introduced by an import whose module specifier names a package. Target is nil when that identity is not exactly known, exactly like an import without one: the base still becomes an UnresolvedReference, never a guessed edge.
TypeScript's `implements` never produces one of these: see the worker's extends-resolver.ts for why.
type TypeScriptImport ¶
type TypeScriptImport struct {
File string `json:"file"`
QualifiedName string `json:"qualifiedName"`
Start int `json:"start"`
End int `json:"end"`
StartLine int `json:"startLine"`
Text string `json:"text"`
RequestedPackage string `json:"requestedPackage"`
RequestedSymbol string `json:"requestedSymbol"`
Target *TypeScriptImportTarget `json:"target"`
Reason string `json:"reason"`
Detail string `json:"detail"`
}
TypeScriptImport is one import binding of the consumer. The worker already turns the binding itself into an "import" kind TypeScriptSymbol, so QualifiedName here names an entry already present in Symbols; Target is the provider declaration it reaches, or nil when that declaration is not exactly known.
type TypeScriptImportTarget ¶
type TypeScriptImportTarget struct {
Repository string `json:"repository"`
Package string `json:"package"`
QualifiedName string `json:"qualifiedName"`
Kind string `json:"kind"`
Signature string `json:"signature"`
File string `json:"file"`
StartLine int `json:"startLine"`
// Source names how the provider source position was reached. An empty
// value means a declaration map, which is what every payload recorded
// before the provider-export path existed carries.
Source string `json:"source,omitempty"`
}
TypeScriptImportTarget is the provider declaration an import binding reaches, described exactly as the provider indexes it when it normalises itself: computed from the provider's own source, at the position the provider-source bridge resolved. Never derived from the consumer's `.d.ts` text, which is not guaranteed to restate the source.
A `TypeScriptExport` that crosses into another repository reuses this exact shape: a re-exported symbol needs the same provider-source proof an imported one does.
type TypeScriptPackage ¶
type TypeScriptPackage struct {
Name string `json:"name"`
Version string `json:"version"`
RootPath string `json:"rootPath"`
ManifestPath string `json:"manifestPath"`
}
TypeScriptPackage is the npm package of the repository, with repository relative paths so a recorded payload stays portable.
type TypeScriptPayload ¶
type TypeScriptPayload struct {
Version int `json:"version"`
Repository TypeScriptRepository `json:"repository"`
Package *TypeScriptPackage `json:"package"`
Files []string `json:"files"`
Symbols []TypeScriptSymbol `json:"symbols"`
References []TypeScriptReference `json:"references"`
Imports []TypeScriptImport `json:"imports"`
Exports []TypeScriptExport `json:"exports"`
Extends []TypeScriptExtends `json:"extends"`
Dependencies []TypeScriptDependency `json:"dependencies"`
Unresolved []TypeScriptUnresolved `json:"unresolved"`
}
TypeScriptPayload is the fact payload the worker emits for one repository.
The worker reports identity components and positions; it never computes a key. Deriving keys on a single side is what keeps one symbol from getting two identities when a consumer and its provider are indexed separately.
func DecodeTypeScriptPayload ¶
func DecodeTypeScriptPayload(data []byte) (TypeScriptPayload, error)
DecodeTypeScriptPayload parses a `ts-facts-v4` document.
type TypeScriptReference ¶
type TypeScriptReference struct {
File string `json:"file"`
Kind string `json:"kind"`
SourceQualifiedName string `json:"sourceQualifiedName"`
TargetQualifiedName string `json:"targetQualifiedName"`
TargetFile string `json:"targetFile"`
StartLine int `json:"startLine"`
Start int `json:"start"`
End int `json:"end"`
Text string `json:"text"`
}
TypeScriptReference is one classified local use.
type TypeScriptReport ¶
type TypeScriptReport struct {
// EdgesWithoutSource counts uses whose enclosing symbol is named but not
// in this payload. A use with no enclosing declaration at all is owned by
// its module instead, and counted below.
EdgesWithoutSource int
// EdgesOwnedByModule counts uses whose owner is the file's own scope: a
// top level statement, or a call inside an anonymous function passed as an
// argument. Before the module symbol existed these were dropped, which
// erased every call a test file makes.
EdgesOwnedByModule int
// EdgesWithoutTarget counts uses whose target is not in this payload.
EdgesWithoutTarget int
// ImportsWithoutTarget counts import bindings whose provider declaration
// is not exactly known: no declaration map reached it, or the reached
// declaration carries no class or no signature.
ImportsWithoutTarget int
// ExportsWithoutTarget counts export/re-export bindings whose declaration
// is not exactly known: neither a local declaration in this payload nor a
// provider declaration reached with a class and a signature.
ExportsWithoutTarget int
// ExtendsWithoutTarget counts extends bases whose declaration is not
// exactly known: neither a local declaration in this payload nor a
// provider declaration reached with a class and a signature.
ExtendsWithoutTarget int
// FactsOutsideRepository counts facts dropped because the file holding
// them is not inside the repository being indexed. A consumer resolves an
// import to a provider's built declaration, so the worker reports a path
// that leaves the consumer's tree -- `../../libraries/library-shared/dist`
// and the like. Keying such a file under the consumer produced a row
// whose path escapes its own repository and which therefore cannot be
// handed back to any tool, which is LUQUE-2011.
//
// The fact is retired rather than re-attributed. Naming the owning
// repository is not enough to build a complete row: a File belongs to a
// Package, and this payload never says which package of the provider
// holds the file. An incomplete row would also be dangerous, because
// MergeAll keeps the first row for a key and drops later ones without
// comparing, so a package-less row could silently beat a complete one.
FactsOutsideRepository int
}
TypeScriptReport records what normalisation could not keep.
type TypeScriptRepository ¶
type TypeScriptRepository struct {
Name string `json:"name"`
}
TypeScriptRepository names the repository the payload belongs to.
type TypeScriptSymbol ¶
type TypeScriptSymbol struct {
File string `json:"file"`
Name string `json:"name"`
QualifiedName string `json:"qualifiedName"`
Kind string `json:"kind"`
Exported bool `json:"exported"`
Signature string `json:"signature"`
StartLine int `json:"startLine"`
EndLine int `json:"endLine"`
Start int `json:"start"`
End int `json:"end"`
}
TypeScriptSymbol is one local declaration reported by the worker.
type TypeScriptUnresolved ¶
type TypeScriptUnresolved struct {
File string `json:"file"`
Reason string `json:"reason"`
RequestedPackage string `json:"requestedPackage"`
RequestedSymbol string `json:"requestedSymbol"`
Detail string `json:"detail"`
Start int `json:"start"`
}
TypeScriptUnresolved is one classified failure of the worker.
type UnresolvedReference ¶
type UnresolvedReference struct {
RepositoryKey string `json:"repository_key"`
FileKey string `json:"file_key,omitempty"`
Language Language `json:"language"`
// SourceSymbolKey is the declaration that contains the reference.
SourceSymbolKey string `json:"source_symbol_key,omitempty"`
RequestedPackage string `json:"requested_package,omitempty"`
RequestedSymbol string `json:"requested_symbol,omitempty"`
Reason string `json:"reason"`
Detail string `json:"detail,omitempty"`
Start Position `json:"start"`
}
UnresolvedReference is a fact that could not become an exact edge.