Documentation ¶
Overview ¶
Package cache implements the caching layer for gopls.
Index ¶
- Variables
- func ParseGoSrc(ctx context.Context, fset *token.FileSet, uri span.URI, src []byte, ...) (res *source.ParsedGoFile, fixes []fixType)
- type Cache
- type DiskFile
- type ImportPath
- type Overlay
- type Package
- func (p *Package) CompiledGoFiles() []*source.ParsedGoFile
- func (p *Package) DependencyTypes(path source.PackagePath) *types.Package
- func (p *Package) DiagnosticsForFile(ctx context.Context, s source.Snapshot, uri span.URI) ([]*source.Diagnostic, error)
- func (p *Package) File(uri span.URI) (*source.ParsedGoFile, error)
- func (p *Package) FileSet() *token.FileSet
- func (p *Package) GetSyntax() []*ast.File
- func (p *Package) GetTypes() *types.Package
- func (p *Package) GetTypesInfo() *types.Info
- func (p *Package) HasParseErrors() bool
- func (p *Package) HasTypeErrors() bool
- func (p *Package) Metadata() *source.Metadata
- func (p *Package) String() string
- 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) GoCommandRunner() *gocommand.Runner
- 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) (*View, source.Snapshot, func(), error)
- func (s *Session) Options() *source.Options
- func (fs Session) Overlays() []*Overlay
- func (fs Session) ReadFile(ctx context.Context, uri span.URI) (source.FileHandle, error)
- func (s *Session) RemoveView(view *View)
- func (s *Session) SetOptions(options *source.Options)
- func (s *Session) SetViewOptions(ctx context.Context, v *View, options *source.Options) (*View, error)
- func (s *Session) Shutdown(ctx context.Context)
- func (s *Session) String() string
- func (s *Session) View(id string) (*View, error)
- func (s *Session) ViewByName(name string) *View
- func (s *Session) ViewOf(uri span.URI) (*View, error)
- func (s *Session) Views() []*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 (w View) GO111MODULE() string
- func (w View) GOWORK() (span.URI, bool)
- func (v *View) GoVersion() int
- func (v *View) GoVersionString() string
- 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) SetVulnerabilities(modfile span.URI, vulns *govulncheck.Result)
- func (v *View) Snapshot() (source.Snapshot, func(), error)
- func (w View) ViewType() ViewType
- func (v *View) Vulnerabilities(modfiles ...span.URI) map[span.URI]*govulncheck.Result
- type ViewType
- type XrefIndex
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 ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
A Cache holds caching stores that are bundled together for consistency.
TODO(rfindley): once fset and store need not be bundled together, the Cache type can be eliminated.
func New ¶
New Creates a new cache for gopls operation results, using the given file set, shared store, and session options.
Both the fset and store 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 DiskFile ¶ added in v0.12.0
type DiskFile struct {
// contains filtered or unexported fields
}
A DiskFile is a file on the filesystem, or a failure to read one. It implements the source.FileHandle interface.
func (*DiskFile) FileIdentity ¶ added in v0.12.0
func (h *DiskFile) FileIdentity() source.FileIdentity
type Overlay ¶ added in v0.12.0
type Overlay struct {
// contains filtered or unexported fields
}
An Overlay is a file open in the editor. It may have unsaved edits. It implements the source.FileHandle interface.
func (*Overlay) FileIdentity ¶ added in v0.12.0
func (o *Overlay) FileIdentity() source.FileIdentity
type Package ¶ added in v0.12.0
type Package struct {
// contains filtered or unexported fields
}
A Package is the union of type-checking inputs (packageHandle) and results (a syntaxPackage).
TODO(rfindley): for now, we do not persist the post-processing of loadDiagnostics, because the value of the snapshot.packages map is just the package handle. Fix this.
func (*Package) CompiledGoFiles ¶ added in v0.12.0
func (p *Package) CompiledGoFiles() []*source.ParsedGoFile
func (*Package) DependencyTypes ¶ added in v0.12.0
func (p *Package) DependencyTypes(path source.PackagePath) *types.Package
DependencyTypes returns the type checker's symbol for the specified package. It returns nil if path is not among the transitive dependencies of p, or if no symbols from that package were referenced during the type-checking of p.
func (*Package) DiagnosticsForFile ¶ added in v0.12.0
func (*Package) GetTypesInfo ¶ added in v0.12.0
func (*Package) HasParseErrors ¶ added in v0.12.0
func (*Package) HasTypeErrors ¶ added in v0.12.0
type PackageName ¶
type PackageName = source.PackageName
Convenient local aliases for typed strings.
type PackagePath ¶
type PackagePath = source.PackagePath
Convenient local aliases for typed strings.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶ added in v0.11.0
NewSession creates a new gopls session with the given cache and options overrides.
The provided optionsOverrides may be nil.
TODO(rfindley): move this to session.go.
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.
TODO(rfindley): what happens if this function fails? It must leave us in a broken state, which we should surface to the user, probably as a request to restart gopls.
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 a new set of 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) GoCommandRunner ¶ added in v0.12.0
GoCommandRunner returns the gocommand Runner for this session.
func (*Session) ModifyFiles ¶
func (*Session) NewView ¶
func (s *Session) NewView(ctx context.Context, name string, folder span.URI, options *source.Options) (*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) Overlays ¶
func (fs Session) Overlays() []*Overlay
Overlays returns a new unordered array of overlays.
func (*Session) RemoveView ¶ added in v0.11.0
RemoveView removes the view v from the session
func (*Session) SetOptions ¶
SetOptions sets the options of this session to new values.
func (*Session) SetViewOptions ¶ added in v0.11.0
func (s *Session) SetViewOptions(ctx context.Context, v *View, options *source.Options) (*View, error)
SetViewOptions sets the options of the given view to new values. Calling this may cause the view to be invalidated and a replacement view added to the session. If so the new view will be returned, otherwise the original one will be returned.
func (*Session) ViewByName ¶ added in v0.12.0
ViewByName returns a view with a matching name, if the session has one.
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) GO111MODULE ¶ added in v0.11.0
func (w View) GO111MODULE() string
GO111MODULE returns the value of GO111MODULE to use for running the go command. It differs from the user's environment in order to allow for the more forgiving default value "auto" when using recent go versions.
TODO(rfindley): it is probably not worthwhile diverging from the go command here. The extra forgiveness may be nice, but breaks the invariant that running the go command from the command line produces the same build list.
Put differently: we shouldn't go out of our way to make GOPATH work, when the go command does not.
func (View) GOWORK ¶ added in v0.12.0
GOWORK returns the effective GOWORK value for this workspace, if any, in URI form.
The second result reports whether the effective GOWORK value is "" because GOWORK=off.
func (*View) GoVersionString ¶ added in v0.11.0
func (*View) IsGoPrivatePath ¶
func (*View) RegisterModuleUpgrades ¶
func (*View) SetVulnerabilities ¶
func (v *View) SetVulnerabilities(modfile span.URI, vulns *govulncheck.Result)
func (View) ViewType ¶ added in v0.12.0
func (w View) ViewType() ViewType
ViewType derives the type of the view from its workspace information.
TODO(rfindley): this logic is overlapping and slightly inconsistent with validBuildConfiguration. As part of zero-config-gopls (golang/go#57979), fix this inconsistency and consolidate on the ViewType abstraction.
func (*View) Vulnerabilities ¶
type ViewType ¶ added in v0.12.0
type ViewType int
A ViewType describes how we load package information for a view.
This is used for constructing the go/packages.Load query, and for interpreting missing packages, imports, or errors.
Each view has a ViewType which is derived from its immutable workspace information -- any environment change that would affect the view type results in a new view.
const ( // GoPackagesDriverView is a view with a non-empty GOPACKAGESDRIVER // environment variable. GoPackagesDriverView ViewType = iota // GOPATHView is a view in GOPATH mode. // // I.e. in GOPATH, with GO111MODULE=off, or GO111MODULE=auto with no // go.mod file. GOPATHView // GoModuleView is a view in module mode with a single Go module. GoModuleView // GoWorkView is a view in module mode with a go.work file. GoWorkView // An AdHocView is a collection of files in a given directory, not in GOPATH // or a module. AdHocView )
type XrefIndex ¶ added in v0.12.0
type XrefIndex struct {
// contains filtered or unexported fields
}
An XrefIndex is a helper for looking up a package in a given package.
func (XrefIndex) Lookup ¶ added in v0.12.0
func (index XrefIndex) Lookup(targets map[PackagePath]map[objectpath.Path]struct{}) []protocol.Location