generator

package
v3.0.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 19 Imported by: 0

README

Generator

This package contains the static analyser used for parsing Wails projects so that we may:

  • Generate the bindings for the frontend
  • Generate Typescript definitions for the structs used by the bindings

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadApplicationPackage = errors.New("package " + config.WailsAppPkgPath + ": function NewService has wrong signature: is the Wails v3 module properly installed?")

ErrBadApplicationPackage indicates that the Wails application package has invalid content.

View Source
var ErrNoApplicationPackage = errors.New("Wails application package not found at canonical import path ('" + config.WailsAppPkgPath + "'): is the Wails v3 module properly installed?")

ErrNoApplicationPackage indicates that the canonical path for the Wails application package did not match any actual package.

View Source
var ErrNoContextPackage = errors.New("standard context package not found at canonical import path ('context'): is the Wails v3 module properly installed?")

ErrNoContextPackage indicates that the canonical path for the standard context package did not match any actual package.

View Source
var ErrNoPackages = errors.New("the given patterns matched no packages")

ErrNoPackages is returned by Generator.Generate when LoadPackages returns no error and no packages.

Functions

func FindServices

func FindServices(pkgs []*packages.Package, systemPaths *config.SystemPaths, logger config.Logger, yield func(*types.TypeName) bool) error

FindServices scans the given packages for invocations of the NewService function from the Wails application package.

Whenever one is found and the type of its unique argument is a valid service type, the corresponding named type object is passed to yield.

Results are deduplicated, i.e. yield is called at most once per object.

If yield returns false, FindBoundTypes returns immediately.

func GenerateConstants

func GenerateConstants(goData []byte) (string, error)

func LoadPackages

func LoadPackages(buildFlags []string, patterns ...string) (pkgs []*packages.Package, err error)

LoadPackages loads the packages specified by the given patterns and their whole dependency tree. It returns a slice containing all packages that match the given patterns and all of their direct and indirect dependencies.

The returned slice is in post-order w.r.t. the dependency relation, i.e. if package A depends on package B, then package B precedes package A.

All returned package instances include syntax trees and full type information.

Syntax is loaded in the context of a global token.FileSet, which is available through the field packages.Package.Fset on each returned package. Therefore, source positions are canonical across all loaded packages.

func ResolvePatterns

func ResolvePatterns(buildFlags []string, patterns ...string) (paths []string, err error)

ResolvePatterns returns a slice containing all package paths that match the given patterns, according to the underlying build tool and within the context of the current working directory.

func ResolveSystemPaths

func ResolveSystemPaths(buildFlags []string) (paths *config.SystemPaths, err error)

ResolveSystemPaths resolves paths for the Wails system

Types

type ErrorReport

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

ErrorReport accumulates and logs error and warning messages, with deduplication.

It implements the error interface; the Error method returns a report counting messages emitted so far.

It also implements the interface config.Logger for convenience.

func NewErrorReport

func NewErrorReport(logger config.Logger) *ErrorReport

NewError report initialises an ErrorReport instance with the provided Logger implementation.

If logger is nil, messages will be accumulated but not logged.

func (*ErrorReport) Debugf

func (report *ErrorReport) Debugf(format string, a ...any)

Debugf forwards the given informational message to the logger instance provided during initialisation.

This method is here just for convenience and performs no deduplication.

func (*ErrorReport) Error

func (report *ErrorReport) Error() string

Error returns a string reporting the number of errors and warnings emitted so far.

func (*ErrorReport) Errorf

func (report *ErrorReport) Errorf(format string, a ...any)

Errorf formats an error message and adds it to the report. If not already present, the message is forwarded to the logger instance provided during initialisation.

func (*ErrorReport) Errors

func (report *ErrorReport) Errors() []string

Errors returns the list of error messages that have been added to the report. The order is randomised.

func (*ErrorReport) HasErrors

func (report *ErrorReport) HasErrors() bool

HasErrors returns true if at least one error has been added to the report.

func (*ErrorReport) HasWarnings

func (report *ErrorReport) HasWarnings() bool

HasWarnings returns true if at least one warning has been added to the report.

func (*ErrorReport) Infof

func (report *ErrorReport) Infof(format string, a ...any)

Infof forwards the given informational message to the logger instance provided during initialisation.

This method is here just for convenience and performs no deduplication.

func (*ErrorReport) Statusf

func (report *ErrorReport) Statusf(format string, a ...any)

Statusf forwards the given status message to the logger instance provided during initialisation.

This method is here just for convenience and performs no deduplication.

func (*ErrorReport) Warningf

func (report *ErrorReport) Warningf(format string, a ...any)

Warningf formats an error message and adds it to the report. If not already present, the message is forwarded to the logger instance provided during initialisation.

func (*ErrorReport) Warnings

func (report *ErrorReport) Warnings() []string

Warnings returns the list of warning messages that have been added to the report. The order is randomised.

type Generator

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

Generator wraps all bookkeeping data structures that are needed to generate bindings for a set of packages.

func NewGenerator

func NewGenerator(options *flags.GenerateBindingsOptions, creator config.FileCreator, logger config.Logger) *Generator

NewGenerator configures a new generator instance. The options argument must not be nil. If creator is nil, no output file will be created. If logger is not nil, it is used to report messages interactively.

func (*Generator) Generate

func (generator *Generator) Generate(patterns ...string) (stats *collect.Stats, err error)

Generate runs the binding generation process for the packages specified by the given patterns.

Concurrent or repeated calls to Generate with the same receiver are not allowed.

The stats result field is never nil.

The error result field is nil in case of complete success (no warning). Otherwise, it may either report errors that occured while loading the initial set of packages, or errors returned by the static analyser, or be an ErrorReport instance.

If error is an ErrorReport, it may have accumulated no errors, just warnings. When this is the case, all bindings have been generated successfully.

Parsing/type-checking errors or errors encountered while writing individual files will be printed directly to the config.Logger instance provided during initialisation.

Jump to

Keyboard shortcuts

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