Documentation
¶
Overview ¶
Package cache implements the caching layer for gopls.
Index ¶
- Variables
- type Cache
- func (c *Cache) FileSet() *token.FileSet
- func (c *Cache) GetFile(ctx context.Context, uri span.URI) (source.FileHandle, error)
- func (c *Cache) ID() string
- func (c *Cache) MemStats() map[reflect.Type]int
- func (c *Cache) NewSession(ctx context.Context) *Session
- func (c *Cache) PackageStats(withNames bool) template.HTML
- type KnownMetadata
- type Metadata
- type PackageID
- type PackageName
- type PackagePath
- type Session
- func (s *Session) Cache() *Cache
- func (s *Session) DidModifyFiles(ctx context.Context, changes []source.FileModification) (map[source.Snapshot][]span.URI, func(), error)
- func (s *Session) ExpandModificationsToDirectories(ctx context.Context, changes []source.FileModification) []source.FileModification
- func (s *Session) FileWatchingGlobPatterns(ctx context.Context) map[string]struct{}
- func (s *Session) GetFile(ctx context.Context, uri span.URI) (source.FileHandle, error)
- func (s *Session) ID() string
- func (s *Session) ModifyFiles(ctx context.Context, changes []source.FileModification) error
- func (s *Session) NewView(ctx context.Context, name string, folder span.URI, options *source.Options) (source.View, source.Snapshot, func(), error)
- func (s *Session) Options() *source.Options
- func (s *Session) Overlays() []source.Overlay
- func (s *Session) SetOptions(options *source.Options)
- func (s *Session) SetProgressTracker(tracker *progress.Tracker)
- func (s *Session) Shutdown(ctx context.Context)
- func (s *Session) String() string
- func (s *Session) View(name string) source.View
- func (s *Session) ViewOf(uri span.URI) (source.View, error)
- func (s *Session) Views() []source.View
- type SessionKey
- type View
- func (v *View) ClearModuleUpgrades(modfile span.URI)
- func (v *View) FileKind(fh source.FileHandle) source.FileKind
- func (v *View) Folder() span.URI
- func (v *View) GoVersion() int
- func (v *View) ID() string
- func (v *View) IsGoPrivatePath(target string) bool
- func (v *View) ModuleUpgrades(modfile span.URI) map[string]string
- func (v *View) Name() string
- func (v *View) Options() *source.Options
- func (v *View) RegisterModuleUpgrades(modfile span.URI, upgrades map[string]string)
- func (v *View) Session() *Session
- func (v *View) SetOptions(ctx context.Context, options *source.Options) (source.View, error)
- func (v *View) SetVulnerabilities(modfile span.URI, vulns []govulncheck.Vuln)
- func (v *View) Shutdown(ctx context.Context)
- func (v *View) Snapshot(ctx context.Context) (source.Snapshot, func())
- func (v *View) Vulnerabilities(modfile span.URI) []govulncheck.Vuln
Constants ¶
This section is empty.
Variables ¶
var ( KeyCreateSession = NewSessionKey("create_session", "A new session was added") KeyUpdateSession = NewSessionKey("update_session", "Updated information about a session") KeyShutdownSession = NewSessionKey("shutdown_session", "A session was shut down") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func New ¶
New Creates a new cache for gopls operation results, using the given file set, shared store, and session options.
All of the fset, store and options may be nil, but if store is non-nil so must be fset (and they must always be used together), otherwise it may be possible to get cached data referencing token.Pos values not mapped by the FileSet.
type KnownMetadata ¶
type KnownMetadata struct {
*Metadata
// Valid is true if the given metadata is Valid.
// Invalid metadata can still be used if a metadata reload fails.
Valid bool
}
KnownMetadata is a wrapper around metadata that tracks its validity.
type Metadata ¶
type Metadata struct {
ID PackageID
PkgPath PackagePath
Name PackageName
GoFiles []span.URI
CompiledGoFiles []span.URI
ForTest PackagePath // package path under test, or ""
TypesSizes types.Sizes
Errors []packages.Error
Deps []PackageID // direct dependencies, in string order
MissingDeps map[PackagePath]struct{}
Module *packages.Module
// Config is the *packages.Config associated with the loaded package.
Config *packages.Config
// contains filtered or unexported fields
}
Metadata holds package Metadata extracted from a call to packages.Load.
func (*Metadata) IsIntermediateTestVariant ¶
IsIntermediateTestVariant reports whether the given package is an intermediate test variant, e.g. "net/http net/url.test".
Such test variants arise when an x_test package (in this case net/url_test) imports a package (in this case net/http) that itself imports the the non-x_test package (in this case net/url).
This is done so that the forward transitive closure of net/url_test has only one package for the "net/url" import. The intermediate test variant exists to hold the test variant import:
net/url_test net/url.test
| "net/http" -> net/http [net/url.test] | "net/url" -> net/url [net/url.test] | ...
net/http net/url.test
| "net/url" -> net/url [net/url.test] | ...
This restriction propagates throughout the import graph of net/http: for every package imported by net/http that imports net/url, there must be an intermediate test variant that instead imports "net/url net/url.test".
As one can see from the example of net/url and net/http, intermediate test variants can result in many additional packages that are essentially (but not quite) identical. For this reason, we filter these variants wherever possible.
func (*Metadata) ModuleInfo ¶
ModuleInfo implements the source.Metadata interface.
func (*Metadata) PackageName ¶
Name implements the source.Metadata interface.
func (*Metadata) PackagePath ¶
PkgPath implements the source.Metadata interface.
type PackageID ¶
type PackageID string
Declare explicit types for package paths, names, and IDs to ensure that we never use an ID where a path belongs, and vice versa. If we confused these, it would result in confusing errors because package IDs often look like package paths.
type PackageName ¶
type PackageName string
Declare explicit types for package paths, names, and IDs to ensure that we never use an ID where a path belongs, and vice versa. If we confused these, it would result in confusing errors because package IDs often look like package paths.
type PackagePath ¶
type PackagePath string
Declare explicit types for package paths, names, and IDs to ensure that we never use an ID where a path belongs, and vice versa. If we confused these, it would result in confusing errors because package IDs often look like package paths.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func (*Session) DidModifyFiles ¶
func (s *Session) DidModifyFiles(ctx context.Context, changes []source.FileModification) (map[source.Snapshot][]span.URI, func(), error)
DidModifyFiles reports a file modification to the session. It returns the new snapshots after the modifications have been applied, paired with the affected file URIs for those snapshots. On success, it returns a release function that must be called when the snapshots are no longer needed.
func (*Session) ExpandModificationsToDirectories ¶
func (s *Session) ExpandModificationsToDirectories(ctx context.Context, changes []source.FileModification) []source.FileModification
ExpandModificationsToDirectories returns the set of changes with the directory changes removed and expanded to include all of the files in the directory.
func (*Session) FileWatchingGlobPatterns ¶
FileWatchingGlobPatterns returns glob patterns to watch every directory known by the view. For views within a module, this is the module root, any directory in the module root, and any replace targets.
func (*Session) ModifyFiles ¶
func (*Session) NewView ¶
func (s *Session) NewView(ctx context.Context, name string, folder span.URI, options *source.Options) (source.View, source.Snapshot, func(), error)
NewView creates a new View, returning it and its first snapshot. If a non-empty tempWorkspace directory is provided, the View will record a copy of its gopls workspace module in that directory, so that client tooling can execute in the same main module. On success it also returns a release function that must be called when the Snapshot is no longer needed.
func (*Session) SetOptions ¶
SetOptions sets the options of this session to new values.
func (*Session) SetProgressTracker ¶
SetProgressTracker sets the progress tracker for the session.
type SessionKey ¶
type SessionKey struct {
// contains filtered or unexported fields
}
SessionKey represents an event label key that has a *Session value.
func NewSessionKey ¶
func NewSessionKey(name, description string) *SessionKey
NewSessionKey creates a new Key for *Session values.
func (*SessionKey) Description ¶
func (k *SessionKey) Description() string
func (*SessionKey) From ¶
func (k *SessionKey) From(t label.Label) *Session
From can be used to get the session value from a Label.
func (*SessionKey) Get ¶
func (k *SessionKey) Get(lm label.Map) *Session
Get can be used to get the session for the key from a label.Map.
func (*SessionKey) Name ¶
func (k *SessionKey) Name() string
type View ¶
type View struct {
// contains filtered or unexported fields
}
func (*View) ClearModuleUpgrades ¶
func (*View) IsGoPrivatePath ¶
func (*View) RegisterModuleUpgrades ¶
func (*View) SetOptions ¶
func (*View) SetVulnerabilities ¶
func (v *View) SetVulnerabilities(modfile span.URI, vulns []govulncheck.Vuln)
func (*View) Vulnerabilities ¶
func (v *View) Vulnerabilities(modfile span.URI) []govulncheck.Vuln