Documentation
¶
Overview ¶
Package goload holds the AST / type / package-loading helpers shared by the gorefactor CLI and its importable refactoring engines (refactor/extract, refactor/changesig). Keeping them here lets the engines load and inspect Go source without importing package main.
Index ¶
- func DeclNames(node *ast.File) (funcs, all []string)
- func FindFileInPackages(pkgs []*packages.Package, absFile string) (*packages.Package, *ast.File)
- func LoadTypedPackages(file string, includeTests bool) ([]*packages.Package, string, error)
- func LookupNamedType(pkg *packages.Package, name string) (*types.Named, error)
- func PackagesErrors(pkgs []*packages.Package) []string
- func ParseFuncLocator(s string) (*orchestrator.InsertionLocation, error)
- func ParseLocatorParts(s string) (funcName, methodName, receiverType string)
- func QualifierFor(target *types.Package) types.Qualifier
- func ReceiverTypeName(expr ast.Expr) string
- func SignatureText(sig *types.Signature, qual types.Qualifier) (params, results string)
- func ValidateFuncTarget(file string, loc *orchestrator.InsertionLocation) error
- func ValidateGoSnippet(content string) error
- func ZeroValueExpr(t types.Type, typeStr string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeclNames ¶
DeclNames returns the names of a file's top-level declarations: funcs lists functions ("Foo") and methods ("Recv:Method"); all additionally includes type, var, and const names.
func FindFileInPackages ¶
FindFileInPackages returns the package and AST for absFile across pkgs.
func LoadTypedPackages ¶
LoadTypedPackages loads the module containing file with full syntax and type information. includeTests additionally loads _test.go package variants so callers can see and rewrite test files.
func LookupNamedType ¶
LookupNamedType finds a defined (named) type in the package scope. Returns an exit-2 error listing the package's type names when missing.
func PackagesErrors ¶
PackagesErrors collects load/parse/type errors across packages, capped so error messages stay readable.
func ParseFuncLocator ¶
func ParseFuncLocator(s string) (*orchestrator.InsertionLocation, error)
ParseFuncLocator splits a "Func" or "Receiver:Method" locator into an InsertionLocation.
func ParseLocatorParts ¶
ParseLocatorParts splits a "Func" or "Receiver:Method" locator into its parts.
func QualifierFor ¶
QualifierFor qualifies types relative to target by package path, which is stable across separate type-check universes (e.g. an interface loaded by its own packages.Load call).
func ReceiverTypeName ¶
ReceiverTypeName returns the receiver type name of a method receiver expression (dropping any leading pointer).
func SignatureText ¶
SignatureText renders "(a int, b ...string)" and " (int, error)" parts of a method signature with named parameters.
func ValidateFuncTarget ¶
func ValidateFuncTarget(file string, loc *orchestrator.InsertionLocation) error
ValidateFuncTarget checks that the function/method referenced by loc exists in file. Returns an exit-3 error when the file does not parse and an exit-2 error (with candidates and a did-you-mean hint) when missing.
func ValidateGoSnippet ¶
ValidateGoSnippet checks that content parses as a complete Go file, as top-level declarations, or as statements. Returns an exit-3 error when none of the forms parse.
func ZeroValueExpr ¶
ZeroValueExpr returns a Go expression producing the zero value of t, rendered with typeStr (the type as the user/source spelled it). context.Context gets context.TODO(). Returns "" when no safe zero value is known and the caller must require an explicit value.
Types ¶
This section is empty.