cache

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadFile = errors.New("bad file")
View Source
var ErrBadModule = errors.New("bad module")

ErrBadModule is returned by any method that cannot proceed because the module is in a bad state (e.g. it's been deleted).

View Source
var ErrBadPackage = errors.New("bad package")

ErrBadPackage is returned by any method that cannot proceed because package is in an errored state (e.g. it's been 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, w *Workspace) *Module

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

func (*Module) DescendantPackages added in v0.15.0

func (m *Module) DescendantPackages(ip ast.ImportPath) []*Package

DescendantPackages returns all the existing loaded packages within this module that correspond to the given import path, or would include the import path's files due to the ancestor-import mechanism. The ancestor-import mechanism is not available for the "old module" system, so only call this unless you know the import path corresponds to the new module system.

This method only returns existing packages; it does not create any new packages.

func (*Module) EnsurePackage added in v0.15.0

func (m *Module) EnsurePackage(ip ast.ImportPath, dirUris []protocol.DocumentURI) *Package

EnsurePackage returns the *Package for the given import path within this module, creating a new package if necessary.

func (*Module) FindImportPathForFile added in v0.15.0

func (m *Module) FindImportPathForFile(file protocol.DocumentURI) (*ast.ImportPath, []protocol.DocumentURI, error)

FindImportPathForFile calculates the import path and directories for the package implied by the given file. The file must be enclosed by the module's rootURI. The file will be read and parsed as a CUE file, in order to find its package directive.

If exactly one directory uri is returned then the file's package uses the new module system. If three directory uris are returned then the package uses the old module system. No other number of directory uris is possible.

This method does not inspect existing packages, nor create any new package. Use *Module.EnsurePackage for that purpose.

func (*Module) Package added in v0.15.0

func (m *Module) Package(ip ast.ImportPath) *Package

Package returns the *Package, if any, for the given import path within this module.

func (*Module) ReadCUEFile

func (m *Module) ReadCUEFile(file protocol.DocumentURI) (*ast.File, parser.Config, 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 file can't be loaded.

func (*Module) ReloadModule

func (m *Module) ReloadModule() error

ReloadModule reloads the module's modfile iff the module's status is dirty. If an error is encountered when reloading the module, the module and all its packages are deleted from the workspace.

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 (*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) 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 Standalone added in v0.15.0

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

Standalone models cue files which cannot be placed within a Package within a Module. This could be because:

  • The cue file has no valid package declaration;
  • No cue.mod/module.cue file could be found in any of the cue file's ancestor directories;
  • The cue.mod/module.cue file is invalid.

It should be impossible for a file to simultaneously exist within a Package and within Standalone.

func NewStandalone added in v0.15.0

func NewStandalone(workspace *Workspace) *Standalone

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) Completion added in v0.15.0

func (w *Workspace) Completion(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, pos protocol.Position) *protocol.CompletionList

Completion attempts to resolve the given position, within the file definitions, from which subsequent path elements can be suggested.

func (*Workspace) Definition added in v0.15.0

func (w *Workspace) Definition(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, pos protocol.Position) []protocol.Location

Definition attempts to resolve the given position, within the file definitions, to one or more ast nodes, and returns the positions of the definitions of those nodes.

func (*Workspace) DefinitionsForURI added in v0.15.0

func (w *Workspace) DefinitionsForURI(fileUri protocol.DocumentURI, loadAllPkgsInMod bool) (*token.File, *definitions.FileDefinitions, *protocol.Mapper, error)

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, [errModuleNotFound].

func (*Workspace) Hover added in v0.15.0

func (w *Workspace) Hover(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, pos protocol.Position) *protocol.Hover

Hover is very similar to Definition. It attempts to resolve the given position, within the file definitions, to one or more ast nodes, and returns the doc comments attached to those ast nodes.

func (*Workspace) PrepareRename added in v0.15.0

func (w *Workspace) PrepareRename(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, pos protocol.Position) *protocol.PrepareRenamePlaceholder

Rename implements the LSP PrepareRename functionality.

func (*Workspace) References added in v0.15.0

func (w *Workspace) References(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, params *protocol.ReferenceParams) []protocol.Location

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) Rename added in v0.15.0

func (w *Workspace) Rename(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, params *protocol.RenameParams) *protocol.WorkspaceEdit

Rename implements the LSP Rename functionality.

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