ast

package
v0.0.0-...-4a73956 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinTemplateMethods = generateBuiltinTemplateMethods()

BuiltinTemplateMethods contains all the built-in Go template methods

Functions

func Extras

func Extras() template.FuncMap

Types

type FieldInfo

type FieldInfo struct {
	Name string
	Type FieldVarOrFunc
	// Reflect  reflect.Type
	FormattedTypeString string
	Parent              *TypeHintDefinition
}

FieldInfo represents information about a struct field

func GenerateFieldInfoFromPosition

func GenerateFieldInfoFromPosition(ctx context.Context, typeInfo *TypeHintDefinition, pos position.RawPosition) (*FieldInfo, error)

ValidateField validates a field access on a type

func (*FieldInfo) NestedMultiLineTypeString

func (f *FieldInfo) NestedMultiLineTypeString() string

NestedMultiLineTypeString returns a multi-line string representation of the type hierarchy

func (*FieldInfo) TypeName

func (f *FieldInfo) TypeName() string

type FieldVarOrFunc

type FieldVarOrFunc struct {
	Var  *types.Var
	Func *types.Func
}

func (FieldVarOrFunc) Obj

func (f FieldVarOrFunc) Obj() types.Object

func (FieldVarOrFunc) String

func (f FieldVarOrFunc) String() string

func (FieldVarOrFunc) Type

func (f FieldVarOrFunc) Type() types.Type

func (FieldVarOrFunc) Underlying

func (f FieldVarOrFunc) Underlying() types.Type

type FunctionCallInfo

type FunctionCallInfo struct {
	Name    string
	Args    []*types.Var
	Results []*types.Var
}

type InMemoryPackageOpts

type InMemoryPackageOpts struct {
	PackagePath   string
	PackageName   string
	TemplateFiles map[string]string
	Types         []*types.TypeName
}

type PackageWithTemplateFiles

type PackageWithTemplateFiles struct {
	Package       *packages.Package
	TemplateFiles map[string]string
}

func LoadPackageTypesFromFs

func LoadPackageTypesFromFs(ctx context.Context, dir string, overlay map[string][]byte) ([]*PackageWithTemplateFiles, error)

func (*PackageWithTemplateFiles) AddStruct

func (r *PackageWithTemplateFiles) AddStruct(name string, fieldMap map[string]types.Type) *types.Named

func (*PackageWithTemplateFiles) AddTemplateFile

func (r *PackageWithTemplateFiles) AddTemplateFile(name string, content string)

func (*PackageWithTemplateFiles) AddTypes

func (r *PackageWithTemplateFiles) AddTypes(types []*types.TypeName)

func (*PackageWithTemplateFiles) LoadTypeByPath

func (me *PackageWithTemplateFiles) LoadTypeByPath(ctx context.Context, path string) (types.Object, error)

type Registry

type Registry struct {
	// Types maps fully qualified type paths to their package information
	Packages []*PackageWithTemplateFiles
	// Error encountered during type resolution, if any
	Err error
}

Registry manages Go package and type information

func AnalyzePackage

func AnalyzePackage(ctx context.Context, dir string, overlay map[string][]byte) (*Registry, error)

AnalyzePackage implements PackageAnalyzer

func NewEmptyRegistry

func NewEmptyRegistry() *Registry

func NewRegistry

func NewRegistry(pkgWithTemplateFilesList []*PackageWithTemplateFiles) *Registry

NewRegistry creates a new Registry

func (*Registry) AddInMemoryPackageForTesting

func (r *Registry) AddInMemoryPackageForTesting(ctx context.Context, path string) *PackageWithTemplateFiles

func (*Registry) AddPackage

func (r *Registry) AddPackage(pkg *PackageWithTemplateFiles)

func (*Registry) GetFieldType

func (r *Registry) GetFieldType(structType *types.Struct, fieldName string) (types.Type, error)

GetFieldType returns the type of a field in a struct type

func (*Registry) GetPackage

func (r *Registry) GetPackage(ctx context.Context, packageName string) (*types.Package, error)

GetPackage returns a package by name

func (*Registry) GetTemplateFile

func (r *Registry) GetTemplateFile(name string) (string, *PackageWithTemplateFiles, bool)

func (*Registry) GetTypes

func (r *Registry) GetTypes(ctx context.Context, pkgPath string) (map[string]types.Object, error)

GetTypes retrieves all types from a package

func (*Registry) TypeExists

func (r *Registry) TypeExists(typePath string) bool

TypeExists checks if a type exists in the registry

type TemplateMethodInfo

type TemplateMethodInfo struct {
	Name       string
	Parameters []types.Type
	Results    []types.Type
}

TemplateMethodInfo represents information about a template method

func GenerateFunctionCallInfoFromPosition

func GenerateFunctionCallInfoFromPosition(ctx context.Context, pos position.RawPosition) (*TemplateMethodInfo, error)

func GenerateFunctionCallInfoFromSignature

func GenerateFunctionCallInfoFromSignature(ctx context.Context, signature *types.Signature) (*TemplateMethodInfo, error)

func GetBuiltinMethod

func GetBuiltinMethod(name string) *TemplateMethodInfo

GetBuiltinMethod returns a built-in template method by name

type TypeHintDefinition

type TypeHintDefinition struct {

	// Reflect reflect.Type
	Fields      map[string]*FieldInfo
	MyFieldInfo FieldInfo
	MyType      *types.Named
}

TypeHintDefinition represents information about a Go type

func BuildTypeHintDefinitionFromRegistry

func BuildTypeHintDefinitionFromRegistry(ctx context.Context, typePath string, r *Registry) (*TypeHintDefinition, error)

Jump to

Keyboard shortcuts

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