Documentation
¶
Overview ¶
Package rustresolve implements the Rust language in-process type resolver. It implements the typresolve.Resolver interface, resolving Rust call expressions, method calls, and type references using tree-sitter AST walking and a shared type registry built from extracted definitions.
Index ¶
- func BuildGlobImports(root *sitter.Node, content []byte, filePath string) []string
- func BuildRegistry(defs []typresolve.ResolverDef) *typresolve.Registry
- func BuildUseMap(root *sitter.Node, content []byte, filePath string) map[string]string
- func DerefToBase(t *typresolve.Type) *typresolve.Type
- func EvalExprType(ctx *ResolveContext, node *sitter.Node) *typresolve.Type
- func EvalMacroReturnType(macroName string) *typresolve.Type
- func InferModuleQN(filePath string) string
- func IsBuiltinFunc(name string) bool
- func IsBuiltinType(name string) bool
- func KnownDeriveTraitQN(deriveName string) string
- func LookupField(reg *typresolve.Registry, typeQN string, fieldName string) *typresolve.Type
- func LookupMethod(reg *typresolve.Registry, typeQN string, methodName string) *typresolve.RegisteredFunc
- func ParseTypeNode(node *sitter.Node, content []byte, moduleQN string, uses map[string]string) *typresolve.Type
- func ProcessStatement(ctx *ResolveContext, node *sitter.Node)
- func RegisterStdlib(reg *typresolve.Registry)
- func ResolveBuiltinType(name string) *typresolve.Type
- func ResolveCallsInFile(ctx *ResolveContext, root *sitter.Node, fileHash types.Hash, repoURL string, ...) []types.Edge
- func ResolveModulePath(prefix string, currentFile string) string
- func ResolveUsePath(usePath string, currentFile string) (modulePath string, isExternal bool)
- type ResolveContext
- type RustResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildGlobImports ¶
BuildGlobImports walks top-level use_declaration nodes and collects glob import prefixes (use module::*). Returns module path prefixes that should be expanded during resolution.
func BuildRegistry ¶
func BuildRegistry(defs []typresolve.ResolverDef) *typresolve.Registry
BuildRegistry builds a typresolve.Registry from ResolverDef entries. Registers structs, enums, traits (as IsInterface=true), functions, and methods (with ReceiverType from impl block). Processes "implements" edges to populate EmbeddedTypes for trait-based method dispatch. Also registers stdlib types/methods as a fallback and processes derive macro annotations.
func BuildUseMap ¶
BuildUseMap walks top-level use_declaration nodes in the AST and builds a map from imported short name to the resolved module path. For example, `use crate::core::Config;` yields map["Config"] = "crate::core".
func DerefToBase ¶
func DerefToBase(t *typresolve.Type) *typresolve.Type
DerefToBase strips ownership/reference wrappers for method resolution. Applies iteratively (max 4 levels) to handle nested wrappers like &Box<T>.
func EvalExprType ¶
func EvalExprType(ctx *ResolveContext, node *sitter.Node) *typresolve.Type
EvalExprType evaluates the type of a Rust expression AST node.
func EvalMacroReturnType ¶
func EvalMacroReturnType(macroName string) *typresolve.Type
EvalMacroReturnType returns the known return type of common Rust macros. Returns Unknown for unrecognized macros or macros whose return type cannot be statically determined.
func InferModuleQN ¶
InferModuleQN converts a file path to a Rust module qualified name. Examples:
- src/foo/bar.rs -> crate::foo::bar
- src/foo/mod.rs -> crate::foo
- src/lib.rs -> crate
- src/main.rs -> crate
- src/resolver/types.rs -> crate::resolver::types
func IsBuiltinFunc ¶
IsBuiltinFunc returns true if name is a Rust builtin macro or function.
func IsBuiltinType ¶
IsBuiltinType returns true if name is a Rust primitive, core type, or core trait.
func KnownDeriveTraitQN ¶
KnownDeriveTraitQN returns the trait QN for a known derive macro name, or empty string if not recognized.
func LookupField ¶
func LookupField(reg *typresolve.Registry, typeQN string, fieldName string) *typresolve.Type
LookupField looks up a struct field on a named type. Returns the field's type if found, nil otherwise.
func LookupMethod ¶
func LookupMethod(reg *typresolve.Registry, typeQN string, methodName string) *typresolve.RegisteredFunc
LookupMethod looks up a method on a named type, following impl block resolution and trait implementations (via EmbeddedTypes). Searches up to 8 levels deep.
func ParseTypeNode ¶
func ParseTypeNode(node *sitter.Node, content []byte, moduleQN string, uses map[string]string) *typresolve.Type
ParseTypeNode converts a tree-sitter Rust type AST node to a typresolve.Type.
func ProcessStatement ¶
func ProcessStatement(ctx *ResolveContext, node *sitter.Node)
ProcessStatement processes a Rust statement node to bind variables into the current scope. Handles let bindings, assignments, for loops, if-let, while-let, and match arm bindings.
func RegisterStdlib ¶
func RegisterStdlib(reg *typresolve.Registry)
RegisterStdlib populates a registry with Rust standard library types and their common methods. This provides method resolution for std types (Vec, HashMap, String, Option, Result, Box, Arc, Rc, etc.) without requiring LSP enrichment.
func ResolveBuiltinType ¶
func ResolveBuiltinType(name string) *typresolve.Type
ResolveBuiltinType returns the typresolve.Type for a Rust builtin type. Primitives return Builtin, core types return Named with "std::" prefix. Returns nil for non-builtins.
func ResolveCallsInFile ¶
func ResolveCallsInFile(ctx *ResolveContext, root *sitter.Node, fileHash types.Hash, repoURL string, filePath string) []types.Edge
ResolveCallsInFile walks a Rust file's AST resolving call expressions, method calls, macro invocations, and path expressions, then emitting call edges.
func ResolveModulePath ¶
ResolveModulePath converts a Rust module path prefix to a resolved module path. It handles crate::, self::, super::, and external crate resolution.
func ResolveUsePath ¶
ResolveUsePath resolves a Rust use path to a module path and external flag. It handles crate::, self::, super::, and external crate prefixes. The modulePath is the path without the final name segment (the imported symbol).
Types ¶
type ResolveContext ¶
type ResolveContext struct {
Registry *typresolve.Registry
Scope *typresolve.Scope
Uses map[string]string // short name -> module path
GlobImports []string // module prefixes from `use module::*`
ModuleQN string // current module qualified name
ImplType string // current impl block type QN (empty if not in impl)
Content []byte // source file content
EnclosingFuncQN string // QN of the current function being resolved
TraitBounds map[string]string // type param name -> trait QN (for generic trait bounds)
}
ResolveContext holds per-file state for type resolution.
type RustResolver ¶
type RustResolver struct {
// contains filtered or unexported fields
}
RustResolver implements typresolve.Resolver for Rust. It uses tree-sitter AST walking and a shared type registry to resolve call expressions and type references without requiring an external LSP server.
func NewRustResolver ¶
func NewRustResolver() *RustResolver
NewRustResolver creates a new RustResolver.
func (*RustResolver) InitWorkspace ¶
func (r *RustResolver) InitWorkspace(ctx context.Context, defs []typresolve.ResolverDef) error
InitWorkspace builds the cross-file type registry from extracted definitions. Called once before any ResolveFile calls.
func (*RustResolver) ResolveFile ¶
func (r *RustResolver) ResolveFile(ctx context.Context, opts typresolve.ResolveFileOpts) ([]types.Edge, error)
ResolveFile resolves type references in a single Rust file. Thread-safe after InitWorkspace completes (registry is read-only, all mutable state is stack-local).