load

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package load wraps go/packages so that the rest of Loom works with a single, consistent go/types universe.

A single packages.Load call is essential: types from two different loads are never types.Identical, so graph resolution would silently fail across package boundaries. Build constraints are handled by the go toolchain; Loom never parses //go:build lines itself.

Index

Constants

View Source
const GeneratedFile = "loom_gen.go"

GeneratedFile is the base name of the file Loom writes. Loom owns this file outright: it is always rewritten in full, so diagnostics inside it never describe a real problem in the input.

Mode requests everything Loom needs: syntax, imports, types, and type info for the roots and every transitive dependency.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generated

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

Generated records the functions Loom is about to emit.

Loom has no stub file: the initializer only comes into existence when the generated file is written. On a first run every call site of that initializer is therefore reported by the type checker as "undefined", which must not stop generation. Generated is used by Loader.CheckErrors to tell those expected errors apart from real ones.

func NewGenerated

func NewGenerated() *Generated

NewGenerated returns an empty set.

func (*Generated) Add

func (g *Generated) Add(pkg *packages.Package, name string)

Add records that name will be generated in pkg.

type Loader

type Loader struct {
	Fset  *token.FileSet
	Roots []*packages.Package
	// contains filtered or unexported fields
}

Loader holds the loaded package graph.

func Load

func Load(dir string, patterns ...string) (*Loader, error)

Load loads the packages matched by patterns, relative to dir.

func (*Loader) CheckErrors

func (l *Loader) CheckErrors(gen *Generated) error

CheckErrors returns an error if any root package reported a type error other than a reference to a function Loom is about to generate. Generated may be nil, in which case every type error is reported.

func (*Loader) Package

func (l *Loader) Package(path string) (*packages.Package, bool)

Package returns a loaded package by import path. Every transitive dependency of the roots is available.

func (*Loader) Type

func (l *Loader) Type(path, name string) types.Type

Type returns the named type decl in the package at path, or nil.

Jump to

Keyboard shortcuts

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