Documentation
¶
Index ¶
- Variables
- func ReadWalkPackage(pkg Package, fn PackageReadWalkFunc) error
- type FSResolver
- type Package
- type PackageHandler
- type PackageReadWalkFunc
- type Processor
- func (p *Processor) FormatFile(file string) ([]byte, error)
- func (p *Processor) FormatImportFromSource(filename string, src any) ([]byte, error)
- func (p *Processor) FormatPackageFile(pkg Package, filename string) ([]byte, error)
- func (p *Processor) FormatSource(filename string, src any) ([]byte, error)
- type Resolver
Constants ¶
This section is empty.
Variables ¶
var ErrPackageConflict = errors.New("package name conflict")
ErrPackageConflict is returned when a directory contains non-test .gno files with different package names (e.g. filetest directories).
Functions ¶
func ReadWalkPackage ¶
func ReadWalkPackage(pkg Package, fn PackageReadWalkFunc) error
Types ¶
type FSResolver ¶
type FSResolver struct {
// contains filtered or unexported fields
}
func NewFSResolver ¶
func NewFSResolver() *FSResolver
func (*FSResolver) LoadPackages ¶
func (r *FSResolver) LoadPackages(root string, pkgHandler PackageHandler) error
LoadPackages lists all packages in the directory (excluding those which can't be processed).
func (*FSResolver) ResolveName ¶
func (r *FSResolver) ResolveName(pkgname string) []Package
func (*FSResolver) ResolvePath ¶
func (r *FSResolver) ResolvePath(pkgpath string) Package
type Package ¶
type Package interface {
// Should return the package path
Path() string
// Should return the name of the package as defined at the top level of each file
Name() string
// Should return all gno filenames inside the package
Files() []string
// Should return a content reader for the given filename within the package
Read(filename string) (io.ReadCloser, error)
}
func ParsePackage ¶
ParsePackage parses package from the given directory. It will return a nil package if no gno files are found. If a gnomod.toml is found, it will be used to determine the pkg path. If root is specified, it will be trimmed from the actual given dir to create the pkgpath if no gnomod.toml is found.
type PackageHandler ¶
PackageHandler is a callback passed to the resolver during package loading. PackageHandler will be called on each package. If no error is passed, that means that the package has been fully loaded. If any handled error is returned from the handler, the package process will immediately stop.
type PackageReadWalkFunc ¶
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
func NewProcessor ¶
func (*Processor) FormatFile ¶
FormatFile processes a single Gno file from the given file path, resolving its imports against the other .gno files in the same directory (parsed as a single package).
If those files declare conflicting package names — as filetest directories such as gnovm/tests/files/ do by design — they cannot be parsed as one package and FormatFile returns ErrPackageConflict (wrapped). Callers that format such independent files must detect them up front, by path or suffix, and call FormatImportFromSource (or FormatSource, to leave imports untouched) directly instead (see cmd/gno/fmt.go).
Known limitation: directories whose files share a consistent package name but are semantically independent (e.g. a directory of `package main` filetests, each with its own func main) parse cleanly as a single package and so are not caught here. Import resolution then pools top-level declarations across every file: a symbol used in file A but declared in (unrelated) file B is treated as already resolved, so the import A needs may be dropped (and imports A already had may be pruned). Layout is still formatted correctly per file; only the import list can be wrong. Such directories must be routed to per-file formatting by the caller too.
func (*Processor) FormatImportFromSource ¶
FormatImportFromSource parse and format the source from src. The type of the argument for the src parameter must be string, []byte, or io.Reader.
func (*Processor) FormatPackageFile ¶
FormatPackageFile processes a single Gno file from the given Package and filename.
func (*Processor) FormatSource ¶
FormatSource parses and formats the source from src for layout only: it reformats the code and sorts existing import groups, but never resolves, adds, or prunes imports. The type of the argument for the src parameter must be string, []byte, or io.Reader.
Use this when a file's imports are intentional and must be preserved verbatim — e.g. a filetest that expects a compile error and deliberately leaves a symbol unimported. FormatImportFromSource, by contrast, resolves imports against the resolver.