package methodsets
import "cuelang.org/go/internal/golangorgx/gopls/cache/methodsets"
Package methodsets defines an incremental, serializable index of method-set information that allows efficient 'implements' queries across packages of the workspace without using the type checker.
This package provides only the "global" (all workspace) search; the "local" search within a given package uses a different implementation based on type-checker data structures for a single package plus variants; see ../implementation.go. The local algorithm is more precise as it tests function-local types too.
A global index of function-local types is challenging since they may reference other local types, for which we would need to invent stable names, an unsolved problem described in passing in Go issue 57497. The global algorithm also does not index anonymous interface types, even outside function bodies.
Consequently, global results are not symmetric: applying the operation twice may not get you back where you started.
Index ¶
- func EnsurePointer(T types.Type) types.Type
- type Index
- func Decode(data []byte) *Index
- func NewIndex(fset *token.FileSet, pkg *types.Package) *Index
- func (index *Index) Encode() []byte
- func (index *Index) Search(key Key, methodID string) []Result
- type Key
- type Location
- type Result
Functions ¶
func EnsurePointer ¶
EnsurePointer wraps T in a types.Pointer if T is a named, non-interface type. This is useful to make sure you consider a named type's full method set.
Types ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
An Index records the non-empty method sets of all package-level types in a package in a form that permits assignability queries without the type checker.
func Decode ¶
Decode decodes the given gob-encoded data as an Index.
func NewIndex ¶
NewIndex returns a new index of method-set information for all package-level types in the specified package.
func (*Index) Encode ¶
Encode encodes the receiver as gob-encoded data.
func (*Index) Search ¶
Search reports each type that implements (or is implemented by) the type that produced the search key. If methodID is nonempty, only that method of each type is reported.
The result does not include the error.Error method. TODO(adonovan): give this special case a more systematic treatment.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
A Key represents the method set of a given type in a form suitable to pass to the (*Index).Search method of many different Indexes.
func KeyOf ¶
KeyOf returns the search key for the method sets of a given type. It returns false if the type has no methods.
type Location ¶
A Location records the extent of an identifier in byte-offset form.
Conversion to protocol (UTF-16) form is done by the caller after a search, not during index construction.
type Result ¶
type Result struct { Location Location // location of the type or method // methods only: PkgPath string // path of declaring package (may differ due to embedding) ObjectPath objectpath.Path // path of method within declaring package }
A Result reports a matching type or method in a method-set search.
Source Files ¶
methodsets.go
- Version
- v0.12.0 (latest)
- Published
- Jan 30, 2025
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 8 hours ago –
Tools for package owners.