Documentation ¶
Overview ¶
Package source provides core features for use by Go editors and tools.
Index ¶
- func CallExpr(fset *token.FileSet, nodes []ast.Node) *ast.CallExpr
- func Deref(typ types.Type) types.Type
- func Diagnostics(ctx context.Context, v View, uri span.URI) (map[span.URI][]Diagnostic, error)
- func FetchIdentFromPathNodes(fset *token.FileSet, nodes []ast.Node) (*ast.Ident, error)
- func FindComments(pkg Package, fset *token.FileSet, o types.Object, name string) (string, error)
- func FindIdentObject(pkg Package, ident *ast.Ident) types.Object
- func FindIdentType(pkg Package, ident *ast.Ident) types.Type
- func FindObject(pkg Package, o types.Object) types.Object
- func GetObjectPathNode(pkg Package, fset *token.FileSet, o types.Object) (nodes []ast.Node, ident *ast.Ident, err error)
- func GetPathNodes(pkg Package, fset *token.FileSet, start, end token.Pos) ([]ast.Node, error)
- func GetSyntaxFile(pkg Package, filename string) *ast.File
- func JoinCommentGroups(a, b *ast.CommentGroup) string
- func PackageDoc(files []*ast.File, pkgName string) string
- func PathEnclosingInterval(pkg Package, fset *token.FileSet, start, end token.Pos) (path []ast.Node, exact bool)
- func PullComments(pathNodes []ast.Node) string
- func TypeLookup(typ types.Type) *types.TypeName
- type Action
- type Cache
- type CompletionItem
- type CompletionItemKind
- type Diagnostic
- type DiagnosticSeverity
- type File
- type InvalidNodeError
- type Package
- type ParameterInformation
- type SignatureInformation
- type TextEdit
- type URI
- type View
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Diagnostics ¶
func FetchIdentFromPathNodes ¶
func FindComments ¶
func GetObjectPathNode ¶
func GetPathNodes ¶
func JoinCommentGroups ¶
func JoinCommentGroups(a, b *ast.CommentGroup) string
JoinCommentGroups joins the resultant non-empty comment text from two CommentGroups with a newline.
func PackageDoc ¶
PackageDoc finds the documentation for the named package from its files or additional files.
func PathEnclosingInterval ¶
func PathEnclosingInterval(pkg Package, fset *token.FileSet, start, end token.Pos) (path []ast.Node, exact bool)
PathEnclosingInterval returns the PackageInfo and ast.Node that contain source interval [start, end), and all the node's ancestors up to the AST root. It searches all ast.Files of all packages in prog. exact is defined as for astutil.PathEnclosingInterval.
The zero value is returned if not found.
func PullComments ¶
func TypeLookup ¶
TypeLookup looks for a named type, but will search through any number of type qualifiers (chan/array/slice/pointer) which have an unambiguous base type. If no named type is found, we are not interested, because this is only used for finding a type's definition.
Types ¶
type Action ¶
type Action struct { Analyzer *analysis.Analyzer Pkg Package Deps []*Action // contains filtered or unexported fields }
An action represents one unit of analysis work: the application of one analysis to one package. Actions form a DAG, both within a package (as different analyzers are applied, either in sequence or parallel), and across packages (as dependencies are analyzed).
type CompletionItem ¶
type CompletionItem struct {
Label, Detail string
Kind CompletionItemKind
Score float64
Documentation string
}
func Completion ¶
func Completion(ctx context.Context, f File, pos token.Pos, cache Cache) (items []CompletionItem, prefix string, err error)
Completion returns a list of possible candidates for completion, given a a file and a position. The prefix is computed based on the preceding identifier and can be used by the client to score the quality of the completion. For instance, some clients may tolerate imperfect matches as valid completion results, since users may make typos.
type CompletionItemKind ¶
type CompletionItemKind int
const ( Unknown CompletionItemKind = iota InterfaceCompletionItem StructCompletionItem TypeCompletionItem ConstantCompletionItem FieldCompletionItem ParameterCompletionItem VariableCompletionItem FunctionCompletionItem MethodCompletionItem PackageCompletionItem )
type Diagnostic ¶
type Diagnostic struct { span.Span Message string Source string Severity DiagnosticSeverity }
type DiagnosticSeverity ¶
type DiagnosticSeverity int
const ( SeverityWarning DiagnosticSeverity = iota SeverityError )
type File ¶
type File interface { URI() span.URI GetAST(ctx context.Context) *ast.File GetFileSet(ctx context.Context) *token.FileSet GetPackage(ctx context.Context) Package GetToken(ctx context.Context) *token.File GetContent(ctx context.Context) []byte }
File represents a Go source file that has been type-checked. It is the input to most of the exported functions in this package, as it wraps up the building blocks for most queries. Users of the source package can abstract the loading of packages into their own caching systems.
type InvalidNodeError ¶
func NewInvalidNodeError ¶
func NewInvalidNodeError(fset *token.FileSet, node ast.Node) *InvalidNodeError
func (*InvalidNodeError) Error ¶
func (e *InvalidNodeError) Error() string
type Package ¶
type Package interface { GetFilenames() []string GetSyntax() []*ast.File GetErrors() []packages.Error GetTypes() *types.Package GetTypesInfo() *types.Info IsIllTyped() bool GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*Action, error) GetPkgPath() string GetName() string GetImport(pkgPath string) Package GetFileSet() *token.FileSet }
Package represents a Go package that has been type-checked. It maintains only the relevant fields of a *go/packages.Package.
type ParameterInformation ¶
type ParameterInformation struct {
Label string
}
type SignatureInformation ¶
type SignatureInformation struct { Label string Parameters []ParameterInformation ActiveParameter int }
type TextEdit ¶
TextEdit represents a change to a section of a document. The text within the specified span should be replaced by the supplied new text.
type URI ¶
type URI string
URI represents the full uri for a file.
func FromDocumentURI ¶
func FromDocumentURI(uri lsp.DocumentURI) URI
FromDocumentURI create a URI from lsp.DocumentURI
type View ¶
type View interface { GetFile(ctx context.Context, uri span.URI) (File, error) SetContent(ctx context.Context, uri span.URI, content []byte) error FileSet() *token.FileSet }
View abstracts the underlying architecture of the package using the source package. The view provides access to files and their contents, so the source package does not directly access the file system.