cache

package
v0.12.1-pre.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2023 License: BSD-3-Clause Imports: 73 Imported by: 0

Documentation

Overview

Package cache implements the caching layer for gopls.

Index

Constants

This section is empty.

Variables

View Source
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

func ParseGoSrc added in v0.12.0

func ParseGoSrc(ctx context.Context, fset *token.FileSet, uri span.URI, src []byte, mode parser.Mode) (res *source.ParsedGoFile, fixes []fixType)

ParseGoSrc parses a buffer of Go source, repairing the tree if necessary.

The provided ctx is used only for logging.

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

func New(store *memoize.Store) *Cache

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.

func (*Cache) FileStats added in v0.12.0

func (c *Cache) FileStats() (files, largest, errs int)

FileStats returns information about the set of files stored in the cache. It is intended for debugging only.

func (*Cache) ID

func (c *Cache) ID() string

func (*Cache) MemStats

func (c *Cache) MemStats() map[reflect.Type]int

func (Cache) ReadFile added in v0.12.0

func (fs Cache) ReadFile(ctx context.Context, uri span.URI) (source.FileHandle, error)

ReadFile stats and (maybe) reads the file, updates the cache, and returns it.

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) Content added in v0.12.0

func (h *DiskFile) Content() ([]byte, error)

func (*DiskFile) FileIdentity added in v0.12.0

func (h *DiskFile) FileIdentity() source.FileIdentity

func (*DiskFile) Saved added in v0.12.0

func (h *DiskFile) Saved() bool

func (*DiskFile) URI added in v0.12.0

func (h *DiskFile) URI() span.URI

func (*DiskFile) Version added in v0.12.0

func (h *DiskFile) Version() int32

type ImportPath

type ImportPath = source.ImportPath

Convenient local aliases for typed strings.

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) Content added in v0.12.0

func (o *Overlay) Content() ([]byte, error)

func (*Overlay) FileIdentity added in v0.12.0

func (o *Overlay) FileIdentity() source.FileIdentity

func (*Overlay) Kind added in v0.12.0

func (o *Overlay) Kind() source.FileKind

func (*Overlay) Saved added in v0.12.0

func (o *Overlay) Saved() bool

func (*Overlay) URI added in v0.12.0

func (o *Overlay) URI() span.URI

func (*Overlay) Version added in v0.12.0

func (o *Overlay) Version() int32

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 (p *Package) DiagnosticsForFile(ctx context.Context, s source.Snapshot, uri span.URI) ([]*source.Diagnostic, error)

func (*Package) File added in v0.12.0

func (p *Package) File(uri span.URI) (*source.ParsedGoFile, error)

func (*Package) FileSet added in v0.12.0

func (p *Package) FileSet() *token.FileSet

func (*Package) GetSyntax added in v0.12.0

func (p *Package) GetSyntax() []*ast.File

func (*Package) GetTypes added in v0.12.0

func (p *Package) GetTypes() *types.Package

func (*Package) GetTypesInfo added in v0.12.0

func (p *Package) GetTypesInfo() *types.Info

func (*Package) HasParseErrors added in v0.12.0

func (p *Package) HasParseErrors() bool

func (*Package) HasTypeErrors added in v0.12.0

func (p *Package) HasTypeErrors() bool

func (*Package) Metadata added in v0.12.0

func (p *Package) Metadata() *source.Metadata

func (*Package) String added in v0.12.0

func (p *Package) String() string

type PackageID

type PackageID = source.PackageID

Convenient local aliases for typed strings.

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

func NewSession(ctx context.Context, c *Cache, optionsOverrides func(*source.Options)) *Session

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) Cache

func (s *Session) Cache() *Cache

Cache returns the cache that created this session, for debugging only.

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

func (s *Session) FileWatchingGlobPatterns(ctx context.Context) map[string]struct{}

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

func (s *Session) GoCommandRunner() *gocommand.Runner

GoCommandRunner returns the gocommand Runner for this session.

func (*Session) ID

func (s *Session) ID() string

ID returns the unique identifier for this session on this server.

func (*Session) ModifyFiles

func (s *Session) ModifyFiles(ctx context.Context, changes []source.FileModification) error

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) Options

func (s *Session) Options() *source.Options

Options returns a copy of the SessionOptions for this session.

func (Session) Overlays

func (fs Session) Overlays() []*Overlay

Overlays returns a new unordered array of overlays.

func (Session) ReadFile added in v0.12.0

func (fs Session) ReadFile(ctx context.Context, uri span.URI) (source.FileHandle, error)

func (*Session) RemoveView added in v0.11.0

func (s *Session) RemoveView(view *View)

RemoveView removes the view v from the session

func (*Session) SetOptions

func (s *Session) SetOptions(options *source.Options)

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) Shutdown

func (s *Session) Shutdown(ctx context.Context)

Shutdown the session and all views it has created.

func (*Session) String

func (s *Session) String() string

func (*Session) View

func (s *Session) View(id string) (*View, error)

View returns the view with a matching id, if present.

func (*Session) ViewByName added in v0.12.0

func (s *Session) ViewByName(name string) *View

ViewByName returns a view with a matching name, if the session has one.

func (*Session) ViewOf

func (s *Session) ViewOf(uri span.URI) (*View, error)

ViewOf returns a view corresponding to the given URI. If the file is not already associated with a view, pick one using some heuristics.

func (*Session) Views

func (s *Session) Views() []*View

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) Format

func (k *SessionKey) Format(w io.Writer, buf []byte, l label.Label)

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

func (*SessionKey) Of

func (k *SessionKey) Of(v *Session) label.Label

Of creates a new Label with this key and the supplied session.

type View

type View struct {
	// contains filtered or unexported fields
}

func (*View) ClearModuleUpgrades

func (v *View) ClearModuleUpgrades(modfile span.URI)

func (*View) FileKind

func (v *View) FileKind(fh source.FileHandle) source.FileKind

func (*View) Folder

func (v *View) Folder() span.URI

Folder returns the folder at the base of this view.

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

func (w View) GOWORK() (span.URI, bool)

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) GoVersion

func (v *View) GoVersion() int

func (*View) GoVersionString added in v0.11.0

func (v *View) GoVersionString() string

func (*View) ID

func (v *View) ID() string

func (*View) IsGoPrivatePath

func (v *View) IsGoPrivatePath(target string) bool

func (*View) ModuleUpgrades

func (v *View) ModuleUpgrades(modfile span.URI) map[string]string

func (*View) Name

func (v *View) Name() string

Name returns the user visible name of this view.

func (*View) Options

func (v *View) Options() *source.Options

func (*View) RegisterModuleUpgrades

func (v *View) RegisterModuleUpgrades(modfile span.URI, upgrades map[string]string)

func (*View) SetVulnerabilities

func (v *View) SetVulnerabilities(modfile span.URI, vulns *govulncheck.Result)

func (*View) Snapshot

func (v *View) Snapshot() (source.Snapshot, func(), error)

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

func (v *View) Vulnerabilities(modfiles ...span.URI) map[span.URI]*govulncheck.Result

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL