visitor

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddGraph added in v1.2.7

func AddGraph(fset *token.FileSet, f *ast.File, spec GraphSpec) error

AddGraph appends a loom.Graph declaration for a generated command.

The injector name is preserved with loom.Name so call sites keep using cmd_app.<Name>Cmd() unchanged, and the graph variable is derived from it (<name>CmdGraph) because a Go package cannot hold a variable and a function with the same name.

The declaration is inserted into the existing var (...) block when the file already declares a graph, so repeated generation keeps one readable block instead of a pile of separate var statements.

func AppendProvider added in v1.2.7

func AppendProvider(f *ast.File, setName, ctor string) bool

AppendProvider appends a constructor to the named provider set declaration, returning false when the set already contains it.

The set may be either a Loom module or a legacy Wire set, and the entry is rendered to match:

var ProviderBizSet = loom.Module(loom.Provide(NewUserBiz))     // appended as loom.Provide(NewOrderBiz)
var ProviderBizSet = wire.NewSet(NewUserBiz)                   // appended as NewOrderBiz

Supporting both keeps `nr gen` working on projects that have not run `nr loom convert` yet.

func RefExpr added in v1.2.7

func RefExpr(text string) (ast.Expr, error)

RefExpr builds an expression from the small references the generators emit, such as "NewUserBiz", "v1.NewUserRoute", "*cmd.MainApp" or "Repository[User]".

Every node is created without position information. That matters: a node carrying offsets from a different file makes go/format break selectors and arguments apart at seemingly random places (loom.Graph[*App](loom.

Provide(NewApp)) ), because the printer trusts those offsets.

Types

type CmdWireVisitor

type CmdWireVisitor struct {
	CmdName      string
	UpperCmdName string
	AppName      string
	// contains filtered or unexported fields
}

func NewCmdWireVisitor

func NewCmdWireVisitor(cmdName string, upperCmdName string, appName string) *CmdWireVisitor

func (*CmdWireVisitor) InsertInitCmdFunc

func (v *CmdWireVisitor) InsertInitCmdFunc(file *ast.File)

func (*CmdWireVisitor) Visit

func (v *CmdWireVisitor) Visit(node ast.Node) ast.Visitor

type FormatLine

type FormatLine struct {
}

func NewFormatLine

func NewFormatLine() *FormatLine

func (*FormatLine) FormatHttpEngine

func (v *FormatLine) FormatHttpEngine(src any) ([]byte, error)

func (*FormatLine) FormatProvider

func (v *FormatLine) FormatProvider(src any) ([]byte, error)

FormatProvider puts one entry per line inside a dependency declaration: provider sets and loom.Graph literals alike.

go/format only reflows whitespace it is given, so the multi-line layout of a generated provider.go has to be established here, otherwise appending a single constructor would reformat the whole set onto one long line.

type GraphSpec added in v1.2.7

type GraphSpec struct {
	// VarName is the package level variable holding the graph, such as
	// migrateAppGraph. It must not collide with an existing declaration.
	VarName string
	// Injector is the name of the generated constructor, such as MigrateCmd.
	// It is passed to loom.Name so call sites keep the name they already use.
	Injector string
	// Target is the graph's result type, such as *MigrateApp.
	Target string
	// Providers are the constructor references listed in the graph, such as
	// NewMigrateApp or seed.NewRegistry.
	Providers []string
	// Imports are added to the file when missing.
	Imports []string
}

GraphSpec describes one loom.Graph declaration to add to a file.

type UpdateRoot

type UpdateRoot struct {
	// contains filtered or unexported fields
}

func NewUpdateRoot

func NewUpdateRoot(varName string, varType string) *UpdateRoot

func (*UpdateRoot) Visit

func (v *UpdateRoot) Visit(node ast.Node) ast.Visitor

Jump to

Keyboard shortcuts

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