goload

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeclNames

func DeclNames(node *ast.File) (funcs, all []string)

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

func FindFileInPackages(pkgs []*packages.Package, absFile string) (*packages.Package, *ast.File)

FindFileInPackages returns the package and AST for absFile across pkgs.

func LoadTypedPackages

func LoadTypedPackages(file string, includeTests bool) ([]*packages.Package, string, error)

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

func LookupNamedType(pkg *packages.Package, name string) (*types.Named, error)

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

func PackagesErrors(pkgs []*packages.Package) []string

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

func ParseLocatorParts(s string) (funcName, methodName, receiverType string)

ParseLocatorParts splits a "Func" or "Receiver:Method" locator into its parts.

func QualifierFor

func QualifierFor(target *types.Package) types.Qualifier

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

func ReceiverTypeName(expr ast.Expr) string

ReceiverTypeName returns the receiver type name of a method receiver expression (dropping any leading pointer).

func SignatureText

func SignatureText(sig *types.Signature, qual types.Qualifier) (params, results string)

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

func ValidateGoSnippet(content string) error

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

func ZeroValueExpr(t types.Type, typeStr string) string

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.

Jump to

Keyboard shortcuts

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