type hoverJSON … // Hover implements the "textDocument/hover" RPC for Go files. // It may return nil even on success. // // If pkgURL is non-nil, it should be used to generate doc links. func Hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, position protocol.Position, pkgURL func(path PackagePath, fragment string) protocol.URI) (*protocol.Hover, error) { … } // hover computes hover information at the given position. If we do not support // hovering at the position, it returns _, nil, nil: an error is only returned // if the position is valid but we fail to compute hover information. // // TODO(adonovan): strength-reduce file.Handle to protocol.DocumentURI. func hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, pp protocol.Position) (protocol.Range, *hoverJSON, error) { … } // hoverBuiltin computes hover information when hovering over a builtin // identifier. func hoverBuiltin(ctx context.Context, snapshot *cache.Snapshot, obj types.Object) (*hoverJSON, error) { … } // hoverImport computes hover information when hovering over the import path of // imp in the file pgf of pkg. // // If we do not have metadata for the hovered import, it returns _ func hoverImport(ctx context.Context, snapshot *cache.Snapshot, pkg *cache.Package, pgf *parsego.File, imp *ast.ImportSpec) (protocol.Range, *hoverJSON, error) { … } // hoverPackageName computes hover information for the package name of the file // pgf in pkg. func hoverPackageName(pkg *cache.Package, pgf *parsego.File) (protocol.Range, *hoverJSON, error) { … } // hoverLit computes hover information when hovering over the basic literal lit // in the file pgf. The provided pos must be the exact position of the cursor, // as it is used to extract the hovered rune in strings. // // For example, hovering over "\u2211" in "foo \u2211 bar" yields: // // '∑', U+2211, N-ARY SUMMATION func hoverLit(pgf *parsego.File, lit *ast.BasicLit, pos token.Pos) (protocol.Range, *hoverJSON, error) { … } // hoverEmbed computes hover information for a filepath.Match pattern. // Assumes that the pattern is relative to the location of fh. func hoverEmbed(fh file.Handle, rng protocol.Range, pattern string) (protocol.Range, *hoverJSON, error) { … } // inferredSignatureString is a wrapper around the types.ObjectString function // that adds more information to inferred signatures. It will return an empty string // if the passed types.Object is not a signature. func inferredSignatureString(obj types.Object, qf types.Qualifier, inferred *types.Signature) string { … } // objectString is a wrapper around the types.ObjectString function. // It handles adding more information to the object string. // If spec is non-nil, it may be used to format additional declaration // syntax, and file must be the token.File describing its positions. // // Precondition: obj is not a built-in function or method. func objectString(obj types.Object, qf types.Qualifier, declPos token.Pos, file *token.File, spec ast.Spec) string { … } // HoverDocForObject returns the best doc comment for obj (for which // fset provides file/line information). // // TODO(rfindley): there appears to be zero(!) tests for this functionality. func HoverDocForObject(ctx context.Context, snapshot *cache.Snapshot, fset *token.FileSet, obj types.Object) (*ast.CommentGroup, error) { … } func chooseDocComment(decl ast.Decl, spec ast.Spec, field *ast.Field) *ast.CommentGroup { … } // parseFull fully parses the file corresponding to position pos (for // which fset provides file/line information). // // It returns the resulting parsego.File as well as new pos contained // in the parsed file. // // BEWARE: the provided FileSet is used only to interpret the provided // pos; the resulting File and Pos may belong to the same or a // different FileSet, such as one synthesized by the parser cache, if // parse-caching is enabled. // // TODO(adonovan): change this function to accept a filename and a // byte offset, and eliminate the confusing (fset, pos) parameters. // Then simplify stubmethods.StubInfo, which doesn't need a Fset. func parseFull(ctx context.Context, snapshot *cache.Snapshot, fset *token.FileSet, pos token.Pos) (*parsego.File, token.Pos, error) { … } // If pkgURL is non-nil, it should be used to generate doc links. func formatHover(h *hoverJSON, options *settings.Options, pkgURL func(path PackagePath, fragment string) protocol.URI) (string, error) { … } // StdSymbolOf returns the std lib symbol information of the given obj. // It returns nil if the input obj is not an exported standard library symbol. func StdSymbolOf(obj types.Object) *stdlib.Symbol { … } // If pkgURL is non-nil, it should be used to generate doc links. func formatLink(h *hoverJSON, options *settings.Options, pkgURL func(path PackagePath, fragment string) protocol.URI) string { … } // findDeclInfo returns the syntax nodes involved in the declaration of the // types.Object with position pos, searching the given list of file syntax // trees. // // Pos may be the position of the name-defining identifier in a FuncDecl, // ValueSpec, TypeSpec, Field, or as a special case the position of // Ellipsis.Elt in an ellipsis field. // // If found, the resulting decl, spec, and field will be the inner-most // instance of each node type surrounding pos. // // If field is non-nil, pos is the position of a field Var. If field is nil and // spec is non-nil, pos is the position of a Var, Const, or TypeName object. If // both field and spec are nil and decl is non-nil, pos is the position of a // Func object. // // It returns a nil decl if no object-defining node is found at pos. // // TODO(rfindley): this function has tricky semantics, and may be worth unit // testing and/or refactoring. func findDeclInfo(files []*ast.File, pos token.Pos) (decl ast.Decl, spec ast.Spec, field *ast.Field) { … } type promotedField … // promotedFields returns the list of accessible promoted fields of a struct type t. // (Logic plundered from x/tools/cmd/guru/describe.go.) func promotedFields(t types.Type, from *types.Package) []promotedField { … } func accessibleTo(obj types.Object, pkg *types.Package) bool { … } // computeSizeOffsetInfo reports the size of obj (if a type or struct // field), its wasted space percentage (if a struct type), and its // offset (if a struct field). It returns -1 for undefined components. func computeSizeOffsetInfo(pkg *cache.Package, path []ast.Node, obj types.Object) (size, wasted, offset int64) { … }