Documentation
¶
Overview ¶
Package analysisinternal provides gopls' internal analyses with a number of helper functions that operate on typed syntax trees.
Index ¶
- func CanImport(from, to string) bool
- func CheckReadable(pass *analysis.Pass, filename string) error
- func ExtractDoc(content, name string) (string, error)
- func IsStdPackage(path string) bool
- func MatchingIdents(typs []types.Type, node ast.Node, pos token.Pos, info *types.Info, ...) map[types.Type][]string
- func MustExtractDoc(content, name string) string
- func Range(pos, end token.Pos) analysis.Range
- func ValidateFixes(fset *token.FileSet, a *analysis.Analyzer, fixes []analysis.SuggestedFix) error
- type ReadFileFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanImport ¶ added in v0.31.0
CanImport reports whether one package is allowed to import another.
TODO(adonovan): allow customization of the accessibility relation (e.g. for Bazel).
func CheckReadable ¶ added in v0.22.0
CheckReadable enforces the access policy defined by the ReadFile field of analysis.Pass.
func ExtractDoc ¶ added in v0.16.1
ExtractDoc extracts a section of a package doc comment from the provided contents of an analyzer package's doc.go file.
A section is a portion of the comment between one heading and the next, using this form:
# Analyzer NAME NAME: SUMMARY Full description...
where NAME matches the name argument, and SUMMARY is a brief verb-phrase that describes the analyzer. The following lines, up until the next heading or the end of the comment, contain the full description. ExtractDoc returns the portion following the colon, which is the form expected by Analyzer.Doc.
Example:
# Analyzer printf printf: checks consistency of calls to printf The printf analyzer checks consistency of calls to printf. Here is the complete description...
This notation allows a single doc comment to provide documentation for multiple analyzers, each in its own section. The HTML anchors generated for each heading are predictable.
It returns an error if the content was not a valid Go source file containing a package doc comment with a heading of the required form.
This machinery enables the package documentation (typically accessible via the web at https://pkg.go.dev/) and the command documentation (typically printed to a terminal) to be derived from the same source and formatted appropriately.
func IsStdPackage ¶ added in v0.33.0
IsStdPackage reports whether the specified package path belongs to a package in the standard library (including internal dependencies).
func MatchingIdents ¶ added in v0.2.0
func MatchingIdents(typs []types.Type, node ast.Node, pos token.Pos, info *types.Info, pkg *types.Package) map[types.Type][]string
MatchingIdents finds the names of all identifiers in 'node' that match any of the given types. 'pos' represents the position at which the identifiers may be inserted. 'pos' must be within the scope of each of identifier we select. Otherwise, we will insert a variable at 'pos' that is unrecognized.
TODO(adonovan): this is only used by gopls/internal/analysis/fill{returns,struct}. Move closer.
func MustExtractDoc ¶ added in v0.16.1
MustExtractDoc is like ExtractDoc but it panics on error.
To use, define a doc.go file such as:
// Package halting defines an analyzer of program termination. // // # Analyzer halting // // halting: reports whether execution will halt. // // The halting analyzer reports a diagnostic for functions // that run forever. To suppress the diagnostics, try inserting // a 'break' statement into each loop. package halting import _ "embed" //go:embed doc.go var doc string
And declare your analyzer as:
var Analyzer = &analysis.Analyzer{ Name: "halting", Doc: analysisutil.MustExtractDoc(doc, "halting"), ... }
func Range ¶ added in v0.34.0
Range returns an analysis.Range for the specified start and end positions.
func ValidateFixes ¶ added in v0.30.0
ValidateFixes validates the set of fixes for a single diagnostic. Any error indicates a bug in the originating analyzer.
It updates fixes so that fixes[*].End.IsValid().
It may be used as part of an analysis driver implementation.
Types ¶
type ReadFileFunc ¶ added in v0.30.0
A ReadFileFunc is a function that returns the contents of a file, such as os.ReadFile.
func CheckedReadFile ¶ added in v0.30.0
func CheckedReadFile(pass *analysis.Pass, readFile ReadFileFunc) ReadFileFunc
CheckedReadFile returns a wrapper around a Pass.ReadFile function that performs the appropriate checks.
Directories
¶
Path | Synopsis |
---|---|
Package generated defines an analyzer whose result makes it convenient to skip diagnostics within generated files.
|
Package generated defines an analyzer whose result makes it convenient to skip diagnostics within generated files. |
Package typeindex defines an analyzer that provides a golang.org/x/tools/internal/typesinternal/typeindex.Index.
|
Package typeindex defines an analyzer that provides a golang.org/x/tools/internal/typesinternal/typeindex.Index. |