cache

package
v0.0.0-...-45b19af Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: BSD-3-Clause Imports: 60 Imported by: 1

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

This section is empty.

Types

type Cache

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

func New

func New(fset *token.FileSet, 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) GetFile

func (c *Cache) GetFile(ctx context.Context, uri span.URI) (source.FileHandle, error)

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

func (*Cache) ID

func (c *Cache) ID() string

func (*Cache) MemStats

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

func (*Cache) PackageStats

func (c *Cache) PackageStats(withNames bool) template.HTML

type ImportPath

type ImportPath = source.ImportPath

Convenient local aliases for typed strings.

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

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.

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.

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

func (s *Session) GetFile(ctx context.Context, uri span.URI) (source.FileHandle, error)

GetFile returns a handle for the specified file.

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 (s *Session) Overlays() []source.Overlay

Overlays returns a slice of file overlays for the session.

func (*Session) RemoveView

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

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(name string) *View

View 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

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

func (v *View) GoVersion() int

func (*View) GoVersionString

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(ctx context.Context) (source.Snapshot, func())

func (*View) Vulnerabilities

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

Jump to

Keyboard shortcuts

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