common

package
v0.281.6 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// FtlUnitTypePath is the path to the FTL unit type.
	FtlUnitTypePath   = "github.com/TBD54566975/ftl/go-runtime/ftl.Unit"
	FtlOptionTypePath = "github.com/TBD54566975/ftl/go-runtime/ftl.Option"
)

Functions

func Errorf

func Errorf(pass *analysis.Pass, node ast.Node, format string, args ...interface{})

func ExtractComments

func ExtractComments(doc *ast.CommentGroup) []string

func ExtractType

func ExtractType(pass *analysis.Pass, pos token.Pos, tnode types.Type) optional.Option[schema.Type]

func ExtractTypeForNode

func ExtractTypeForNode(pass *analysis.Pass, obj types.Object, node ast.Node, index types.Type) optional.Option[schema.Type]

func FtlModuleFromGoPackage

func FtlModuleFromGoPackage(pkgPath string) (string, error)

func GetFact

func GetFact[T SchemaFactValue](facts []SchemaFact) optional.Option[T]

func GetFactForObject

func GetFactForObject[T SchemaFactValue](pass *analysis.Pass, obj types.Object) optional.Option[T]

GetFactForObject returns the first fact of the provided type marked on the object.

func GetFacts added in v0.261.0

func GetFacts[T SchemaFactValue](pass *analysis.Pass) map[types.Object]T

func GetFactsForObject

func GetFactsForObject[T SchemaFactValue](pass *analysis.Pass, obj types.Object) []T

GetFactsForObject returns all facts marked on the object.

func GetNativeName added in v0.261.0

func GetNativeName(obj types.Object) string

func GetObjectForNode

func GetObjectForNode(typesInfo *types.Info, node ast.Node) optional.Option[types.Object]

func GetTypeForNode

func GetTypeForNode(node ast.Node, info *types.Info) types.Type

func GoPosToSchemaPos

func GoPosToSchemaPos(fset *token.FileSet, pos token.Pos) schema.Position

func IsPathInPkg

func IsPathInPkg(pkg *types.Package, path string) bool

func IsSelfReference

func IsSelfReference(pass *analysis.Pass, obj types.Object, t schema.Type) bool

func IsType

func IsType[T types.Type](t types.Type) bool

func MarkFailedExtraction

func MarkFailedExtraction(pass *analysis.Pass, obj types.Object)

MarkFailedExtraction marks the given object as having failed extraction.

func MarkMetadata

func MarkMetadata(pass *analysis.Pass, obj types.Object, md *ExtractedMetadata)

func MarkSchemaDecl

func MarkSchemaDecl(pass *analysis.Pass, obj types.Object, decl schema.Decl)

MarkSchemaDecl marks the given object as having been extracted to the given schema node.

func MergeAllFacts

func MergeAllFacts(pass *analysis.Pass) map[types.Object]SchemaFact

MergeAllFacts merges schema facts inclusive of all available results and the present pass facts.

If multiple facts are present for the same object, the facts will be prioritized by type: 1. ExtractedDecl 2. FailedExtraction 4. NeedsExtraction

ExtractedMetadata facts are ignored.

func NewDeclExtractor

func NewDeclExtractor[T schema.Decl, N ast.Node](name string, extractFunc ExtractDeclFunc[T, N]) *analysis.Analyzer

func NewExtractor

func NewExtractor(name string, factType analysis.Fact, run func(*analysis.Pass) (interface{}, error)) *analysis.Analyzer

func NoEndColumnErrorf

func NoEndColumnErrorf(pass *analysis.Pass, pos token.Pos, format string, args ...interface{})

func TokenErrorf

func TokenErrorf(pass *analysis.Pass, pos token.Pos, tokenText string, format string, args ...interface{})

func Wrapf

func Wrapf(pass *analysis.Pass, node ast.Node, err error, format string, args ...interface{})

Types

type DefaultFact added in v0.260.0

type DefaultFact[T any] struct {
	// contains filtered or unexported fields
}

DefaultFact should be used as the base type for all schema facts. Each Analyzer needs a uniuqe Fact type that is otherwise identical, and this type simply reduces that boilerplate.

Usage:

type Fact = common.DefaultFact[struct{}]

func (*DefaultFact[T]) AFact added in v0.260.0

func (*DefaultFact[T]) AFact()

func (*DefaultFact[T]) Get added in v0.260.0

func (t *DefaultFact[T]) Get() SchemaFactValue

func (*DefaultFact[T]) Set added in v0.260.0

func (t *DefaultFact[T]) Set(v SchemaFactValue)

type DiagnosticCategory

type DiagnosticCategory string
const (
	Info  DiagnosticCategory = "info"
	Warn  DiagnosticCategory = "warn"
	Error DiagnosticCategory = "error"
)

func (DiagnosticCategory) ToErrorLevel

func (e DiagnosticCategory) ToErrorLevel() schema.ErrorLevel

type Directive

type Directive interface {
	SetPosition(pos token.Pos)
	GetPosition() token.Pos
	GetTypeName() string
	// MustAnnotate returns the AST nodes that can be annotated by this directive.
	MustAnnotate() []ast.Node
	// contains filtered or unexported methods
}

Directive is a directive in a Go FTL module, e.g. //ftl:ingress http GET /foo/bar

func ParseDirectives

func ParseDirectives(pass *analysis.Pass, node ast.Node, docs *ast.CommentGroup) []Directive

type DirectiveCronJob

type DirectiveCronJob struct {
	Pos token.Pos

	Cron cron.Pattern `parser:"'cron' @@"`
}

func (*DirectiveCronJob) GetPosition

func (d *DirectiveCronJob) GetPosition() token.Pos

func (*DirectiveCronJob) GetTypeName

func (*DirectiveCronJob) GetTypeName() string

func (*DirectiveCronJob) IsExported

func (d *DirectiveCronJob) IsExported() bool

func (*DirectiveCronJob) MustAnnotate

func (*DirectiveCronJob) MustAnnotate() []ast.Node

func (*DirectiveCronJob) SetPosition

func (d *DirectiveCronJob) SetPosition(pos token.Pos)

func (*DirectiveCronJob) String

func (d *DirectiveCronJob) String() string

type DirectiveData

type DirectiveData struct {
	Pos token.Pos

	Data   bool `parser:"@'data'"`
	Export bool `parser:"@'export'?"`
}

func (*DirectiveData) GetPosition

func (d *DirectiveData) GetPosition() token.Pos

func (*DirectiveData) GetTypeName

func (*DirectiveData) GetTypeName() string

func (*DirectiveData) IsExported

func (d *DirectiveData) IsExported() bool

func (*DirectiveData) MustAnnotate

func (*DirectiveData) MustAnnotate() []ast.Node

func (*DirectiveData) SetPosition

func (d *DirectiveData) SetPosition(pos token.Pos)

func (*DirectiveData) String

func (d *DirectiveData) String() string

type DirectiveEnum

type DirectiveEnum struct {
	Pos token.Pos

	Enum   bool `parser:"@'enum'"`
	Export bool `parser:"@'export'?"`
}

func (*DirectiveEnum) GetPosition

func (d *DirectiveEnum) GetPosition() token.Pos

func (*DirectiveEnum) GetTypeName

func (*DirectiveEnum) GetTypeName() string

func (*DirectiveEnum) IsExported

func (d *DirectiveEnum) IsExported() bool

func (*DirectiveEnum) MustAnnotate

func (*DirectiveEnum) MustAnnotate() []ast.Node

func (*DirectiveEnum) SetPosition

func (d *DirectiveEnum) SetPosition(pos token.Pos)

func (*DirectiveEnum) String

func (d *DirectiveEnum) String() string

type DirectiveExport

type DirectiveExport struct {
	Pos token.Pos

	Export bool `parser:"@'export'"`
}

DirectiveExport is used on declarations that don't include export in other directives.

func (*DirectiveExport) GetPosition

func (d *DirectiveExport) GetPosition() token.Pos

func (*DirectiveExport) GetTypeName

func (*DirectiveExport) GetTypeName() string

func (*DirectiveExport) MustAnnotate

func (*DirectiveExport) MustAnnotate() []ast.Node

func (*DirectiveExport) SetPosition

func (d *DirectiveExport) SetPosition(pos token.Pos)

func (*DirectiveExport) String

func (d *DirectiveExport) String() string

type DirectiveIngress

type DirectiveIngress struct {
	Pos token.Pos

	Type   string                        `parser:"'ingress' @('http')?"`
	Method string                        `parser:"@('GET' | 'POST' | 'PUT' | 'DELETE')"`
	Path   []schema.IngressPathComponent `parser:"('/' @@)+"`
}

func (*DirectiveIngress) GetPosition

func (d *DirectiveIngress) GetPosition() token.Pos

func (*DirectiveIngress) GetTypeName

func (*DirectiveIngress) GetTypeName() string

func (*DirectiveIngress) IsExported

func (d *DirectiveIngress) IsExported() bool

func (*DirectiveIngress) MustAnnotate

func (*DirectiveIngress) MustAnnotate() []ast.Node

func (*DirectiveIngress) SetPosition

func (d *DirectiveIngress) SetPosition(pos token.Pos)

func (*DirectiveIngress) String

func (d *DirectiveIngress) String() string

type DirectiveRetry

type DirectiveRetry struct {
	Pos token.Pos

	Count      *int   `parser:"'retry' (@Number Whitespace)?"`
	MinBackoff string `parser:"@(Number (?! Whitespace) Ident)?"`
	MaxBackoff string `parser:"@(Number (?! Whitespace) Ident)?"`
}

func (*DirectiveRetry) GetPosition

func (d *DirectiveRetry) GetPosition() token.Pos

func (*DirectiveRetry) GetTypeName

func (*DirectiveRetry) GetTypeName() string

func (*DirectiveRetry) MustAnnotate

func (*DirectiveRetry) MustAnnotate() []ast.Node

func (*DirectiveRetry) SetPosition

func (d *DirectiveRetry) SetPosition(pos token.Pos)

func (*DirectiveRetry) String

func (d *DirectiveRetry) String() string

type DirectiveSubscriber

type DirectiveSubscriber struct {
	Pos token.Pos

	Name string `parser:"'subscribe' @Ident"`
}

DirectiveSubscriber is used to subscribe a sink to a subscription

func (*DirectiveSubscriber) GetPosition

func (d *DirectiveSubscriber) GetPosition() token.Pos

func (*DirectiveSubscriber) GetTypeName

func (*DirectiveSubscriber) GetTypeName() string

func (*DirectiveSubscriber) MustAnnotate

func (*DirectiveSubscriber) MustAnnotate() []ast.Node

func (*DirectiveSubscriber) SetPosition

func (d *DirectiveSubscriber) SetPosition(pos token.Pos)

func (*DirectiveSubscriber) String

func (d *DirectiveSubscriber) String() string

type DirectiveTypeAlias

type DirectiveTypeAlias struct {
	Pos token.Pos

	TypeAlias bool `parser:"@'typealias'"`
	Export    bool `parser:"@'export'?"`
}

func (*DirectiveTypeAlias) GetPosition

func (d *DirectiveTypeAlias) GetPosition() token.Pos

func (*DirectiveTypeAlias) GetTypeName

func (*DirectiveTypeAlias) GetTypeName() string

func (*DirectiveTypeAlias) IsExported

func (d *DirectiveTypeAlias) IsExported() bool

func (*DirectiveTypeAlias) MustAnnotate

func (*DirectiveTypeAlias) MustAnnotate() []ast.Node

func (*DirectiveTypeAlias) SetPosition

func (d *DirectiveTypeAlias) SetPosition(pos token.Pos)

func (*DirectiveTypeAlias) String

func (d *DirectiveTypeAlias) String() string

type DirectiveVerb

type DirectiveVerb struct {
	Pos token.Pos

	Verb   bool `parser:"@'verb'"`
	Export bool `parser:"@'export'?"`
}

func (*DirectiveVerb) GetPosition

func (d *DirectiveVerb) GetPosition() token.Pos

func (*DirectiveVerb) GetTypeName

func (*DirectiveVerb) GetTypeName() string

func (*DirectiveVerb) IsExported

func (d *DirectiveVerb) IsExported() bool

func (*DirectiveVerb) MustAnnotate

func (*DirectiveVerb) MustAnnotate() []ast.Node

func (*DirectiveVerb) SetPosition

func (d *DirectiveVerb) SetPosition(pos token.Pos)

func (*DirectiveVerb) String

func (d *DirectiveVerb) String() string

type Exportable

type Exportable interface {
	IsExported() bool
}

type ExtractDeclFunc

type ExtractDeclFunc[T schema.Decl, N ast.Node] func(pass *analysis.Pass, node N, object types.Object) optional.Option[T]

func ExtractFuncForDecl

func ExtractFuncForDecl(t schema.Decl) (ExtractDeclFunc[schema.Decl, ast.Node], error)

type ExtractedDecl

type ExtractedDecl struct {
	Decl schema.Decl
	// ShouldInclude is true if the object should be included in the schema.
	// We extract all objects by default, but some objects may not actually be referenced in the schema.
	ShouldInclude bool
	// Refs is a list of objects that the object references.
	Refs sets.Set[types.Object]
}

ExtractedDecl is a fact for associating an object with an extracted schema decl.

type ExtractedMetadata

type ExtractedMetadata struct {
	Type       schema.Decl
	IsExported bool
	Metadata   []schema.Metadata
	Comments   []string
}

ExtractedMetadata is a fact for associating an object with extracted schema metadata.

type ExtractorResult

type ExtractorResult struct {
	Facts []analysis.ObjectFact
}

func NewExtractorResult

func NewExtractorResult(pass *analysis.Pass) ExtractorResult

type FailedExtraction

type FailedExtraction struct{}

FailedExtraction is a fact for marking a type that failed to be extracted by another extractor.

type NeedsExtraction

type NeedsExtraction struct{}

NeedsExtraction is a fact for marking a type that needs to be extracted by another extractor.

type SchemaFact

type SchemaFact interface {
	analysis.Fact
	Set(v SchemaFactValue)
	Get() SchemaFactValue
}

SchemaFact is a fact that associates a schema node with a Go object.

type SchemaFactValue

type SchemaFactValue interface {
	// contains filtered or unexported methods
}

SchemaFactValue is the value of a SchemaFact.

Jump to

Keyboard shortcuts

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