Documentation
¶
Overview ¶
Package typresolve provides shared infrastructure for in-process language-specific type resolution. It includes type representation, a type registry, scope chains, and the Resolver interface that per-language resolvers implement.
This package replaces external LSP servers for type resolution, running inside the same process as tree-sitter extraction and sharing the parsed AST directly.
Package typresolve defines the Resolver interface for per-language in-process type resolution and the ResolverEnricher orchestrator that dispatches resolution concurrently across files. Language-specific resolvers (Go, Python, TypeScript, etc.) implement the Resolver interface; the enricher groups files by language, initializes each resolver's workspace, and fans out file resolution with bounded concurrency.
Index ¶
- Constants
- func RouteEnrichment(ctx context.Context, store types.GraphStore, workspaceRoot string, ...) error
- func TypesEqual(a, b *Type) bool
- type ChanDir
- type Field
- type FileResult
- type LanguageStats
- type LspEnricher
- type Method
- type Param
- type RegisteredFunc
- type RegisteredType
- type Registry
- func (r *Registry) AddFunc(f RegisteredFunc)
- func (r *Registry) AddType(t RegisteredType)
- func (r *Registry) FuncCount() int
- func (r *Registry) IterFuncsByShortName(shortName string, fn func(*RegisteredFunc) bool)
- func (r *Registry) LookupFunc(qualifiedName string) *RegisteredFunc
- func (r *Registry) LookupMethod(receiverQN, methodName string) *RegisteredFunc
- func (r *Registry) LookupSymbol(packageQN, name string) *RegisteredFunc
- func (r *Registry) LookupType(qualifiedName string) *RegisteredType
- func (r *Registry) ResolveAlias(typeQN string) *RegisteredType
- func (r *Registry) SetFallback(parent *Registry)
- func (r *Registry) TypeCount() int
- type ResolveFileOpts
- type Resolver
- type ResolverDef
- type ResolverEnricher
- type Scope
- type Type
- func Alias(name string, underlying *Type) *Type
- func Array(elem *Type) *Type
- func Builtin(name string) *Type
- func Channel(elem *Type, dir ChanDir) *Type
- func Func(params []Param, returns []*Type) *Type
- func Interface(methods []Method) *Type
- func Map(key, value *Type) *Type
- func Named(qualifiedName string) *Type
- func Optional(elem *Type) *Type
- func Pointer(elem *Type) *Type
- func Ref(elem *Type) *Type
- func Slice(elem *Type) *Type
- func Struct(fields []Field) *Type
- func Tuple(elems []*Type) *Type
- func TypeParamType(name string) *Type
- func Unknown() *Type
- type TypeKind
- type TypeParam
Constants ¶
const ProvenanceResolverResolved = "resolver_resolved"
ProvenanceResolverResolved is the provenance string for edges produced by in-process type resolution, distinct from "lsp_resolved" edges produced by the external LSP enricher.
const ResolverConfidence = 0.9
ResolverConfidence is the default confidence for resolver-produced edges.
Variables ¶
This section is empty.
Functions ¶
func RouteEnrichment ¶
func RouteEnrichment(ctx context.Context, store types.GraphStore, workspaceRoot string, repoHash types.Hash, resolverEnricher *ResolverEnricher, lspEnricher LspEnricher, fileResults []FileResult) error
RouteEnrichment dispatches file results to either the in-process resolver or the external LSP enricher based on which languages have registered resolvers. Languages with a resolver go through resolverEnricher.Run; languages without one fall back to lspEnricher.Run (if non-nil).
Resolver errors do not prevent the LSP fallback from running. The first error encountered (resolver or LSP) is returned.
func TypesEqual ¶
TypesEqual performs structural equality comparison of two types. Two types are equal if their kinds match and all structural members match recursively. Both nil returns true; one nil returns false.
Types ¶
type FileResult ¶
type FileResult struct {
Path string
FileHash types.Hash
Content []byte
ParsedTree types.ParsedTree
Edges []types.Edge
Language string
}
FileResult wraps extraction output for a single file, used as input to the ResolverEnricher.
type LanguageStats ¶
LanguageStats reports the routing decision for a single language.
func RouteStats ¶
func RouteStats(resolverEnricher *ResolverEnricher, fileResults []FileResult) []LanguageStats
RouteStats returns per-language routing decisions without executing. Useful for logging and testing.
type LspEnricher ¶
LspEnricher is the interface the existing enrichment.Enricher satisfies. Defined here rather than importing internal/enrichment to avoid circular dependencies. The enricher's Run method has the signature:
Run(ctx context.Context, repoHash types.Hash) error
type RegisteredFunc ¶
type RegisteredFunc struct {
QualifiedName string
ReceiverType string // empty for free functions
ShortName string
Signature *Type // KindFunc
TypeParams []string // generic type param names
MinParams int // -1 = unknown
}
RegisteredFunc represents a function or method registered in the type registry. For methods, ReceiverType holds the qualified name of the receiver type.
type RegisteredType ¶
type RegisteredType struct {
QualifiedName string
ShortName string
Fields []Field
MethodNames []string // parallel with MethodQNs
MethodQNs []string // parallel with MethodNames
EmbeddedTypes []string
AliasOf string // empty if not alias
TypeParams []string
IsInterface bool
}
RegisteredType represents a type registered in the type registry. MethodNames and MethodQNs are parallel arrays: MethodNames[i] is the short name and MethodQNs[i] is the qualified name of the same method.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry provides hash-indexed lookup tables for functions and types by qualified name. It supports fallback chaining for two-level lookup (e.g. local workspace registry falling back to a stdlib registry).
Registry is NOT thread-safe for writes. Build it single-threaded during InitWorkspace, then use it read-only for concurrent ResolveFile calls.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates an empty registry with initialized maps.
func (*Registry) AddFunc ¶
func (r *Registry) AddFunc(f RegisteredFunc)
AddFunc registers a function by its qualified name. If the function has a ReceiverType, it is also indexed under "ReceiverType.ShortName" in the methods map for method lookup.
func (*Registry) AddType ¶
func (r *Registry) AddType(t RegisteredType)
AddType registers a type by its qualified name.
func (*Registry) FuncCount ¶
FuncCount returns the number of functions registered locally (not including fallback).
func (*Registry) IterFuncsByShortName ¶
func (r *Registry) IterFuncsByShortName(shortName string, fn func(*RegisteredFunc) bool)
IterFuncsByShortName calls fn for every registered function whose ShortName matches shortName. Searches this registry and all fallbacks. Used as a last-resort resolution strategy when qualified-name lookup fails.
func (*Registry) LookupFunc ¶
func (r *Registry) LookupFunc(qualifiedName string) *RegisteredFunc
LookupFunc looks up a function by qualified name. Returns nil if not found in this registry or any fallback.
func (*Registry) LookupMethod ¶
func (r *Registry) LookupMethod(receiverQN, methodName string) *RegisteredFunc
LookupMethod looks up a method by receiver qualified name and method name. The key is "receiverQN.methodName". Returns nil if not found.
func (*Registry) LookupSymbol ¶
func (r *Registry) LookupSymbol(packageQN, name string) *RegisteredFunc
LookupSymbol looks up a function by constructing "packageQN.name" and searching the funcs map. Returns nil if not found.
func (*Registry) LookupType ¶
func (r *Registry) LookupType(qualifiedName string) *RegisteredType
LookupType looks up a type by qualified name. Returns nil if not found in this registry or any fallback.
func (*Registry) ResolveAlias ¶
func (r *Registry) ResolveAlias(typeQN string) *RegisteredType
ResolveAlias follows the AliasOf chain on types up to 16 levels deep. Returns the concrete (non-alias) type at the end of the chain, or nil if the type is not found or the chain exceeds 16 levels (cycle detection).
func (*Registry) SetFallback ¶
SetFallback sets the fallback (parent) registry for chained lookups. When a lookup misses in this registry, it falls through to the fallback.
type ResolveFileOpts ¶
type ResolveFileOpts struct {
FilePath string
FileHash types.Hash
Content []byte
ParsedTree types.ParsedTree
Edges []types.Edge
}
ResolveFileOpts contains all inputs for resolving a single file.
type Resolver ¶
type Resolver interface {
// Language returns the language identifier (e.g. "go", "python").
Language() string
// InitWorkspace builds the cross-file type registry from all extracted
// definitions. Called once before any ResolveFile calls. The registry
// must be read-only after this returns.
InitWorkspace(ctx context.Context, defs []ResolverDef) error
// ResolveFile resolves type references in a single file. Thread-safe;
// called concurrently across files. Returns edges with provenance
// ProvenanceResolverResolved and confidence ResolverConfidence.
ResolveFile(ctx context.Context, opts ResolveFileOpts) ([]types.Edge, error)
}
Resolver is the contract that per-language in-process type resolvers implement. Language() identifies the resolver; InitWorkspace builds a cross-file type registry from extracted definitions (called once, after which the registry is read-only); ResolveFile resolves a single file and is safe for concurrent use.
type ResolverDef ¶
type ResolverDef struct {
QualifiedName string
Kind string // "function", "type", "method", etc.
Signature string
FilePath string
PackagePath string
}
ResolverDef contains definition metadata collected from extraction, used to build the per-language type registry in InitWorkspace.
type ResolverEnricher ¶
type ResolverEnricher struct {
// contains filtered or unexported fields
}
ResolverEnricher orchestrates per-language type resolution. It groups files by language, initializes each registered resolver, and resolves files concurrently using bounded concurrency with a single DB-writer goroutine.
func NewResolverEnricher ¶
func NewResolverEnricher(store types.GraphStore, concurrency int) *ResolverEnricher
NewResolverEnricher creates a ResolverEnricher backed by the given store. If concurrency is 0 or negative, it defaults to 8.
func (*ResolverEnricher) HasResolver ¶
func (re *ResolverEnricher) HasResolver(language string) bool
HasResolver reports whether a resolver is registered for the given language.
func (*ResolverEnricher) Register ¶
func (re *ResolverEnricher) Register(r Resolver)
Register adds a language-specific resolver. Subsequent calls with the same Language() value overwrite the previous registration.
func (*ResolverEnricher) Run ¶
func (re *ResolverEnricher) Run(ctx context.Context, repoHash types.Hash, fileResults []FileResult) error
Run executes type resolution for all file results. It groups files by language, then for each language with a registered resolver:
- Collects ResolverDef entries from the file results
- Calls InitWorkspace with the collected definitions
- Resolves files concurrently via a channel semaphore
- Writes edges through a single writer goroutine calling store.PutEdge
Errors in individual files or languages are logged but do not abort the entire run.
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope is a linked-list scope chain for variable-to-type bindings during AST walk. Each scope level holds its own bindings map and a pointer to the enclosing (parent) scope. Scope is NOT thread-safe; it is used within a single ResolveFile call (one goroutine per file).
This is the Go equivalent of CBMScope from codebase-memory's scope.c, simplified to use map[string]*Type per level instead of arena-allocated linked chunks.
func (*Scope) Bind ¶
Bind binds a variable name to a type in the current scope. If the name already exists in the current scope, it is overwritten.
type Type ¶
type Type struct {
Kind TypeKind
Name string // qualified name for Named/Builtin/TypeParam/Alias
Elem *Type // element for Pointer/Slice/Array/Channel/Optional/Reference
Key *Type // key for Map
Value *Type // value for Map
Params []Param // parameters for Func
Returns []*Type // return types for Func
Fields []Field // fields for Struct
Methods []Method // methods for Interface
Elements []*Type // elements for Tuple
TypeParams []TypeParam // generic type parameters
Underlying *Type // underlying type for Alias
ChanDir ChanDir // direction for Channel
}
Type is the core type representation struct with kind discrimination. Different fields are populated based on Kind, analogous to the tagged union approach in the C reference implementation (CBMType).
func TypeParamType ¶
TypeParamType returns a new generic type parameter.
func (*Type) Deref ¶
Deref removes one pointer level: returns the element type if Pointer, or the type itself otherwise.
func (*Type) GetElem ¶
GetElem returns the element type for Pointer, Slice, Array, Channel, Optional, and Reference kinds. Returns nil for other kinds.
func (*Type) IsInterface ¶
IsInterface returns true if the type has KindInterface.
type TypeKind ¶
type TypeKind int
TypeKind enumerates the language-agnostic type representation kinds.
const ( KindUnknown TypeKind = iota KindNamed // named type: "Database", "http.Request" KindPointer // *T KindSlice // []T KindMap // map[K]V KindChannel // chan T (with direction) KindFunc // func(params) returns KindInterface // interface{...} KindStruct // struct{...} KindBuiltin // int, string, bool, error, etc. KindTuple // multi-return (T1, T2) KindTypeParam // generic type parameter: T, K, V KindArray // [N]T KindOptional // *T or Option<T> language-agnostic optional KindReference // &T (Rust/C++ reference) KindAlias // type alias )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package csresolve implements the C# language in-process type resolver.
|
Package csresolve implements the C# language in-process type resolver. |
|
Package goresolve implements the Go language in-process type resolver.
|
Package goresolve implements the Go language in-process type resolver. |
|
Package javaresolve implements the Java language in-process type resolver.
|
Package javaresolve implements the Java language in-process type resolver. |
|
Package pyresolve implements the Python language in-process type resolver.
|
Package pyresolve implements the Python language in-process type resolver. |
|
Package rubyresolve implements the Ruby language in-process type resolver.
|
Package rubyresolve implements the Ruby language in-process type resolver. |
|
Package rustresolve implements the Rust language in-process type resolver.
|
Package rustresolve implements the Rust language in-process type resolver. |
|
Package tsresolve implements the TypeScript/JavaScript in-process type resolver.
|
Package tsresolve implements the TypeScript/JavaScript in-process type resolver. |