loader

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: May 18, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownError = packages.UnknownError
	ListError    = packages.ListError
	ParseError   = packages.ParseError
	TypeError    = packages.TypeError
	// Our kinds of errors. Add a gap of 10 to be sure we won't conflict
	// with previous enum values.
	ValidateError = packages.TypeError + 10 + iota
)

Variables

This section is empty.

Functions

func CommentFromText

func CommentFromText(orig ast.Node, text string) *ast.CommentGroup

TODO(mvdan): both loader and format use CommentFromText, but it feels awkward to have it here. CommentFromText creates a multi-line comment from the given text, with its start and end positions matching the given node's.

func ErrorAbsolutePos

func ErrorAbsolutePos(err error, pos token.Position) error

ErrorAbsolutePos modifies all positions in err, considered to be relative to pos. This is useful so that the position information of syntax tree nodes parsed from a comment are relative to the entire file, and not only relative to the comment containing the source.

func SplitGunkTag

func SplitGunkTag(pkg *GunkPackage, fset *token.FileSet, comment *ast.CommentGroup) (string, []loader.GunkTag, error)

SplitGunkTag splits '+gunk' tags from a comment group, returning the leading documentation and the tags Go expressions.

If pkg is not nil, the tag is also type-checked using the package's type information.

Types

type Error

type Error struct {
	File string

	FromLine int
	FromCol  int

	ToLine int
	ToCol  int

	Msg  string
	Kind packages.ErrorKind
}

type GunkPackage

type GunkPackage struct {
	*loader.GunkPackage

	Errors []Error

	State PackageState
}

func NewGunkPackage

func NewGunkPackage(pkg packages.Package, state PackageState) *GunkPackage

type Loader

type Loader struct {
	Dir  string
	Fset *token.FileSet
	// If Types is true, we parse and type-check the given packages and all
	// transitive dependencies, including gunk tags. Otherwise, we only
	// parse the given packages.
	Types bool

	// InMemoryFiles is a list of files that are are managed by the language
	// server, that may be in memory. This may not be synced with the contents
	// on disk.
	InMemoryFiles map[string]string
	// contains filtered or unexported fields
}

func (*Loader) AddFile

func (l *Loader) AddFile(pkgs []*GunkPackage, path, src string) ([]*GunkPackage, *GunkPackage, error)

AddFile adds a gunk file to the gunk package, and removes all cached entries and imports that directly or indirectly import the package of the file.

func (*Loader) CloseFile

func (l *Loader) CloseFile(pkgs []*GunkPackage, path string) ([]*GunkPackage, error)

func (*Loader) Errors

func (l *Loader) Errors(pkgs []*GunkPackage, pkg *GunkPackage) (map[string][]protocol.Diagnostic, error)

func (*Loader) Import

func (l *Loader) Import(path string) (*types.Package, error)

Import satisfies the go/types.Importer interface.

Unlike standard Go ones like go/importer and x/tools/go/packages, this one is adapted to load Gunk packages.

Aside from that, it is very similar to standard Go importers that load from source.

func (*Loader) Load

func (l *Loader) Load(path string) ([]*GunkPackage, error)

Loader finds all of the gunk files in path. Cached files are not loaded again. No type checking or parsing is done.

func (*Loader) ParsePackage

func (l *Loader) ParsePackage(pkg *GunkPackage, checkTypes bool)

ParsePackage parses the package's GunkFiles, and type-checks the package if l.Types is set.

func (*Loader) UpdateFile

func (l *Loader) UpdateFile(pkgs []*GunkPackage, path, src string) ([]*GunkPackage, error)

type PackageState

type PackageState int
const (
	Untracked PackageState = iota
	Dirty
	Open
)

Jump to

Keyboard shortcuts

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