Documentation ¶
Index ¶
- Constants
- func CommentFromText(orig ast.Node, text string) *ast.CommentGroup
- func ErrorAbsolutePos(err error, pos token.Position) error
- func SplitGunkTag(pkg *GunkPackage, fset *token.FileSet, comment *ast.CommentGroup) (string, []loader.GunkTag, error)
- type Error
- type GunkPackage
- type Loader
- func (l *Loader) AddFile(pkgs []*GunkPackage, path, src string) ([]*GunkPackage, *GunkPackage, error)
- func (l *Loader) CloseFile(pkgs []*GunkPackage, path string) ([]*GunkPackage, error)
- func (l *Loader) Errors(pkgs []*GunkPackage, pkg *GunkPackage) (map[string][]protocol.Diagnostic, error)
- func (l *Loader) Import(path string) (*types.Package, error)
- func (l *Loader) Load(path string) ([]*GunkPackage, error)
- func (l *Loader) ParsePackage(pkg *GunkPackage, checkTypes bool)
- func (l *Loader) UpdateFile(pkgs []*GunkPackage, path, src string) ([]*GunkPackage, error)
- type PackageState
Constants ¶
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 ¶
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 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 ¶
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)