cache

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrModuleDeleted = errors.New("Module deleted")

ErrModuleDeleted is returned by any method that cannot proceed because module has been marked deleted.

Functions

func CheckPathValid

func CheckPathValid(path string) error

CheckPathValid checks whether a directory is suitable as a workspace folder.

This exists for use by tests, to check the testing.TempDir result is acceptable.

Types

type Cache

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

A Cache holds content that is shared across multiple cuelsp client/editor connections.

func New

func New() (*Cache, error)

New creates a new Cache.

func NewWithRegistry

func NewWithRegistry(reg Registry) *Cache

NewWithRegistry creates a new cache, using the specified registry.

type Module

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

Module models a single CUE module.

func NewModule

func NewModule(modFileUri protocol.DocumentURI, registry Registry, overlayFS *fscache.OverlayFS, debugLog func(string)) *Module

NewModule creates a new Module. The CUE module itself (that is, the cue.mod/module.cue file) is not loaded until Module.ReloadModule is called.

func (*Module) ActiveFilesAndDirs

func (m *Module) ActiveFilesAndDirs(files map[protocol.DocumentURI][]packageOrModule, dirs map[protocol.DocumentURI]struct{})

ActiveFilesAndDirs implements [packageOrModule]

func (*Module) Encloses

func (m *Module) Encloses(file protocol.DocumentURI) bool

MarkFileDirty implements [packageOrModule]

func (*Module) FindPackagesOrModulesForFile

func (m *Module) FindPackagesOrModulesForFile(file protocol.DocumentURI) ([]packageOrModule, error)

FindPackagesOrModulesForFile searches for the given file in both the module itself, and packages within the module, returning a (possibly empty) list of [packageOrModule]s to which the file belongs. The file must be enclosed by the module's rootURI.

The file will belong to the module if the file is the module's modFileURI.

Otherwise, the file will be read and parsed as a CUE file, in order to obtain its package. If the module doesn't already have a suitable package one will be created.

Already-loaded packages which include this file via ancestor-imports are also returned in the list. However, if such packages exist but are not loaded, they are not discovered here. For example, if file is file:///a/b.cue, and it contains "package x", and a package a/c:x within the same module is already loaded, then the results will contain both package a:x and a/c:x, but only if a/c:x is already loaded.

func (*Module) MarkFileDirty

func (m *Module) MarkFileDirty(file protocol.DocumentURI)

MarkFileDirty implements [packageOrModule]

func (*Module) ReadCUEFile

func (m *Module) ReadCUEFile(file protocol.DocumentURI) (*ast.File, fscache.FileHandle, error)

ReadCUEFile attempts to read the file, using the language version extracted from the module's Language.Version field. This will fail if the module's module.cue file is invalid, and ErrModuleInvalid will be returned.

func (*Module) ReloadModule

func (m *Module) ReloadModule() error

ReloadModule reloads the module's modfile iff the module's status is dirty. An error is returned if any problem is encountered when reloading the module, or if the module has been marked as being deleted.

func (*Module) ReloadPackages

func (m *Module) ReloadPackages() error

ReloadPackages reloads all dirty packages within this module, and all packages which (transitively) import any dirty package within this module.

The goal is to reach a point where all dirty files have been loaded into at least one (re)loaded package.

If a previously-loaded package now cannot be loaded (perhaps all its files have been deleted) then the package will be deleted from the module. If a dirty file has changed package, that new package will be created and loaded. Imports are followed, and may result in new packages being added to this module.

func (*Module) String

func (m *Module) String() string

type Package

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

Package models a single CUE package within a CUE module.

func NewPackage

func NewPackage(module *Module, importPath ast.ImportPath, dir protocol.DocumentURI) *Package

func (*Package) ActiveFilesAndDirs

func (pkg *Package) ActiveFilesAndDirs(files map[protocol.DocumentURI][]packageOrModule, dirs map[protocol.DocumentURI]struct{})

ActiveFilesAndDirs implements [packageOrModule]

func (*Package) Encloses

func (pkg *Package) Encloses(file protocol.DocumentURI) bool

Encloses implements [packageOrModule]

func (*Package) EnsureImportedBy

func (pkg *Package) EnsureImportedBy(importer *Package)

EnsureImportedBy ensures that importer is recorded as a user of this package. This method is idempotent.

func (*Package) MarkFileDirty

func (pkg *Package) MarkFileDirty(file protocol.DocumentURI)

MarkFileDirty implements [packageOrModule]

func (*Package) RemoveImportedBy

func (pkg *Package) RemoveImportedBy(importer *Package)

RemoveImportedBy ensures that importer is not recorded as a user of this package. This method is idempotent.

func (*Package) String

func (pkg *Package) String() string

type Registry

type Registry interface {
	modrequirements.Registry
	modpkgload.Registry
}

type Workspace

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

Workspace corresponds to an LSP Workspace. Each LSP client/editor configures one workspace. A workspace may have several workspace folders WorkspaceFolder.

func NewWorkspace

func NewWorkspace(cache *Cache, debugLog func(string)) *Workspace

func (*Workspace) DidModifyFiles

func (w *Workspace) DidModifyFiles(ctx context.Context, modifications []file.Modification) error

DidModifyFiles is responsible for processing notifications of file modifications that are sent to us from the editor/client. There are two types of notification that we can receive, which are both catered for by the file.Modification type. 1) modifications that concern files/buffers that are open in the editor; 2) modifications that have happened on disk (e.g. by other tools) that the editor/client tells us about because of the watching globs that we've set up. Note that if a file is open in the editor, and there is a modification of that same file on disk, we should not make any assumption that the state of the editor has changed.

func (*Workspace) EnsureFolder

func (w *Workspace) EnsureFolder(dir protocol.DocumentURI, name string) (*WorkspaceFolder, error)

EnsureFolder ensures that the folder at dir is a WorkspaceFolder within this workspace. The name is for display purposes only and does not have any semantics attached to it. This method is idempotent: if the workspace already includes a workspace folder at dir, then this method is a noop and returns nil.

func (*Workspace) FileWatchingGlobPatterns

func (w *Workspace) FileWatchingGlobPatterns(ctx context.Context) map[protocol.RelativePattern]struct{}

FileWatchingGlobPatterns returns a set of glob patterns that the client is required to watch for changes and notify the server of them, in order to keep the server's state up to date.

This set includes

  1. all cue.mod/module.cue files in the workspace; and
  2. for each WorkspaceFolder, its modules (or directory for ad-hoc views). In module mode, this is the set of active modules (and for VS Code, all workspace directories within them, due to golang/go#42348).

The watch for workspace cue.mod/module.cue files in (1) is sufficient to capture changes to the repo structure that may affect the sets of modules and packages. Whenever this set changes, we reload the workspace and invalidate memoized files.

The watch for workspace directories in (2) should keep each Package up to date, as it should capture any newly added/modified/deleted cue files.

Patterns are returned as a set of protocol.RelativePatterns, since they can always be later translated to glob patterns (i.e. strings) if the client lacks relative pattern support. By convention, any pattern returned with empty baseURI should be served as a glob pattern.

In general, we prefer to serve relative patterns, as they work better on most clients that support both, and do not have issues with Windows driver letter casing: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#relativePattern

func (*Workspace) FindModuleForFile

func (w *Workspace) FindModuleForFile(file protocol.DocumentURI) (*Module, error)

FindModuleForFile attempts to find the most-specific (i.e. accommodating nested modules) module for the given file. This may result in new modules being added to the workspace.

If no module can be found, this method returns nil, nil.

func (*Workspace) RemoveFolder

func (w *Workspace) RemoveFolder(dir protocol.DocumentURI)

RemoveFolder removes the folder at dir. This is idempotent.

An LSP client/editor can dynamically reconfigure which workspace folders exist. RemoveFolder is used when the client changes its configuration and removes a folder.

func (*Workspace) UpdateFolderOptions

func (w *Workspace) UpdateFolderOptions(fetchFolderOptions func(folder protocol.DocumentURI) (*settings.Options, error)) error

UpdateFolderOptions requests that the workspace refetches from the client/editor options for every workspace folder.

An LSP client/editor can inform the server that its options have changed. It's up to the server to query the client for options for each workspace folder.

type WorkspaceFolder

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

A WorkspaceFolder corresponds to an LSP Workspace Folder. A single workspace is configured with one or more workspace folders. Each folder can have its own options, for which the server can query the editor/client.

func NewWorkspaceFolder

func NewWorkspaceFolder(dir protocol.DocumentURI, name string) (*WorkspaceFolder, error)

NewWorkspaceFolder creates a new workspace folder. The name is entirely decorative and does not have any semantics attached to it.

func (*WorkspaceFolder) FileWatchingGlobPatterns

func (wf *WorkspaceFolder) FileWatchingGlobPatterns(patterns map[protocol.RelativePattern]struct{}) bool

FileWatchingGlobPatterns adds a pattern for watching the folder to the given patterns map and reports whether this folder requires subdirectories to be watched explicitly.

func (*WorkspaceFolder) UpdateOptions

func (wf *WorkspaceFolder) UpdateOptions(opts *settings.Options)

UpdateOptions sets the folders options to opts. The caller should not modify the contents of opts after calling this method.

Jump to

Keyboard shortcuts

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