cache

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: BSD-3-Clause Imports: 58 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

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, options func(*source.Options)) *Cache

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.

func (*Cache) FileSet

func (c *Cache) FileSet() *token.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) NewSession

func (c *Cache) NewSession(ctx context.Context) *Session

func (*Cache) PackageStats

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

type KnownMetadata added in v0.1.6

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

	// PkgFilesChanged reports whether the file set of this metadata has
	// potentially changed.
	//
	// TODO(rfindley): this is used for WorkspacePackages, and looks fishy: we
	// should probably only consider valid packages to be workspace packages.
	PkgFilesChanged bool
}

KnownMetadata is a wrapper around metadata that tracks its validity.

type Metadata added in v0.1.6

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

	// IsIntermediateTestVariant reports whether the given package is an
	// intermediate test variant, e.g.
	// "golang.org/x/tools/internal/lsp/cache [golang.org/x/tools/internal/lsp/source.test]".
	//
	// Such test variants arise when an x_test package (in this case source_test)
	// imports a package (in this case cache) that itself imports the the
	// non-x_test package (in this case source).
	//
	// This is done so that the forward transitive closure of source_test has
	// only one package for the "golang.org/x/tools/internal/lsp/source" import.
	// The intermediate test variant exists to hold the test variant import:
	//
	// golang.org/x/tools/internal/lsp/source_test [golang.org/x/tools/internal/lsp/source.test]
	//  | "golang.org/x/tools/internal/lsp/cache" -> golang.org/x/tools/internal/lsp/cache [golang.org/x/tools/internal/lsp/source.test]
	//  | "golang.org/x/tools/internal/lsp/source" -> golang.org/x/tools/internal/lsp/source [golang.org/x/tools/internal/lsp/source.test]
	//  | ...
	//
	// golang.org/x/tools/internal/lsp/cache [golang.org/x/tools/internal/lsp/source.test]
	//  | "golang.org/x/tools/internal/lsp/source" -> golang.org/x/tools/internal/lsp/source [golang.org/x/tools/internal/lsp/source.test]
	//  | ...
	//
	// We filter these variants out in certain places. For example, there is
	// generally no reason to run diagnostics or analysis on them.
	//
	// TODO(rfindley): this can probably just be a method, since it is derived
	// from other fields.
	IsIntermediateTestVariant bool
	// contains filtered or unexported fields
}

Metadata holds package Metadata extracted from a call to packages.Load.

func (*Metadata) ModuleInfo added in v0.1.10

func (m *Metadata) ModuleInfo() *packages.Module

ModuleInfo implements the source.Metadata interface.

func (*Metadata) PackageName added in v0.1.6

func (m *Metadata) PackageName() string

Name implements the source.Metadata interface.

func (*Metadata) PackagePath added in v0.1.6

func (m *Metadata) PackagePath() string

PkgPath implements the source.Metadata interface.

type PackageID added in v0.1.6

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 added in v0.1.6

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 added in v0.1.6

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

func (s *Session) Cache() interface{}

func (*Session) DidModifyFiles

func (s *Session) DidModifyFiles(ctx context.Context, changes []source.FileModification) (map[source.Snapshot][]span.URI, func(), error)

func (*Session) ExpandModificationsToDirectories

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

func (*Session) FileWatchingGlobPatterns

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

func (*Session) GetFile

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

func (*Session) ID

func (s *Session) ID() string

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) (source.View, source.Snapshot, func(), error)

func (*Session) Options

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

func (*Session) Overlays

func (s *Session) Overlays() []source.Overlay

func (*Session) SetOptions

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

func (*Session) SetProgressTracker added in v0.1.4

func (s *Session) SetProgressTracker(tracker *progress.Tracker)

func (*Session) Shutdown

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

func (*Session) String

func (s *Session) String() string

func (*Session) View

func (s *Session) View(name string) source.View

View returns the view by name.

func (*Session) ViewOf

func (s *Session) ViewOf(uri span.URI) (source.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() []source.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) FileKind added in v0.1.9

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

func (v *View) ID() string

func (*View) IsGoPrivatePath

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

func (*View) ModuleUpgrades added in v0.1.1

func (v *View) ModuleUpgrades() 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) Rebuild

func (v *View) Rebuild(ctx context.Context) (source.Snapshot, func(), error)

func (*View) RegisterModuleUpgrades added in v0.1.1

func (v *View) RegisterModuleUpgrades(upgrades map[string]string)

func (*View) Session

func (v *View) Session() *Session

func (*View) SetOptions

func (v *View) SetOptions(ctx context.Context, options *source.Options) (source.View, error)

func (*View) Shutdown

func (v *View) Shutdown(ctx context.Context)

func (*View) Snapshot

func (v *View) Snapshot(ctx context.Context) (source.Snapshot, func())

Jump to

Keyboard shortcuts

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