package cache
import "cuelang.org/go/internal/lsp/cache"
Index ¶
- Variables
- func CheckPathValid(path string) error
- type Cache
- type Module
- func NewModule(modFileUri protocol.DocumentURI, w *Workspace) *Module
- func (m *Module) DescendantPackages(ip ast.ImportPath) []*Package
- func (m *Module) EnsurePackage(ip ast.ImportPath, dirUris []protocol.DocumentURI) *Package
- func (m *Module) FindImportPathForFile(file protocol.DocumentURI) (*ast.ImportPath, []protocol.DocumentURI, error)
- func (m *Module) Package(ip ast.ImportPath) *Package
- func (m *Module) ReadCUEFile(file protocol.DocumentURI) (*ast.File, parser.Config, fscache.FileHandle, error)
- func (m *Module) ReloadModule() error
- func (m *Module) String() string
- type Package
- func (pkg *Package) EnsureImportedBy(importer *Package)
- func (pkg *Package) RemoveImportedBy(importer *Package)
- func (pkg *Package) String() string
- type Registry
- type Standalone
- type Workspace
- func NewWorkspace(cache *Cache, debugLog func(string)) *Workspace
- func (w *Workspace) Completion(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, pos protocol.Position) *protocol.CompletionList
- func (w *Workspace) Definition(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, pos protocol.Position) []protocol.Location
- func (w *Workspace) DefinitionsForURI(fileUri protocol.DocumentURI, loadAllPkgsInMod bool) (*token.File, *definitions.FileDefinitions, *protocol.Mapper, error)
- func (w *Workspace) DidModifyFiles(ctx context.Context, modifications []file.Modification) error
- func (w *Workspace) EnsureFolder(dir protocol.DocumentURI, name string) (*WorkspaceFolder, error)
- func (w *Workspace) FileWatchingGlobPatterns(ctx context.Context) map[protocol.RelativePattern]struct{}
- func (w *Workspace) FindModuleForFile(file protocol.DocumentURI) (*Module, error)
- func (w *Workspace) Hover(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, pos protocol.Position) *protocol.Hover
- func (w *Workspace) PrepareRename(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, pos protocol.Position) *protocol.PrepareRenamePlaceholder
- func (w *Workspace) ReadCUEFile(fileUri protocol.DocumentURI) (*ast.File, parser.Config, fscache.FileHandle, error)
- func (w *Workspace) References(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, params *protocol.ReferenceParams) []protocol.Location
- func (w *Workspace) RemoveFolder(dir protocol.DocumentURI)
- func (w *Workspace) Rename(tokFile *token.File, fdfns *definitions.FileDefinitions, srcMapper *protocol.Mapper, params *protocol.RenameParams) *protocol.WorkspaceEdit
- func (w *Workspace) UpdateFolderOptions(fetchFolderOptions func(folder protocol.DocumentURI) (*settings.Options, error)) error
- type WorkspaceFolder
Variables ¶
ErrBadModule is returned by any method that cannot proceed because the module is in a bad state (e.g. it's been deleted).
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 ¶
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 ¶
New creates a new Cache.
func NewWithRegistry ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package models a single CUE package within a CUE module.
func (*Package) EnsureImportedBy ¶
EnsureImportedBy ensures that importer is recorded as a user of this package. This method is idempotent.
func (*Package) RemoveImportedBy ¶
RemoveImportedBy ensures that importer is not recorded as a user of this package. This method is idempotent.
func (*Package) String ¶
type Registry ¶
type Registry interface {
modrequirements.Registry
modpkgload.Registry
}
type Standalone ¶
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 ¶
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 (*Workspace) Completion ¶
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 ¶
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 ¶
func (w *Workspace) DefinitionsForURI(fileUri protocol.DocumentURI, loadAllPkgsInMod bool) (*token.File, *definitions.FileDefinitions, *protocol.Mapper, error)
func (*Workspace) DidModifyFiles ¶
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
- all cue.mod/module.cue files in the workspace; and
- 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 ¶
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 ¶
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) ReadCUEFile ¶
func (w *Workspace) ReadCUEFile(fileUri protocol.DocumentURI) (*ast.File, parser.Config, fscache.FileHandle, error)
ReadCUEFile attempts to read and parse the indicated file as a CUE file as best as possbile. If it can be established that the file is within a valid module, then the module's language version will used. Otherwise the file will be parsed as a standalone file.
func (*Workspace) References ¶
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 ¶
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.
Source Files ¶
cache.go definitions.go folder.go module.go package.go path.go registry.go rename.go standalone.go workspace.go
- Version
- v0.15.1 (latest)
- Published
- Nov 21, 2025
- Platform
- linux/amd64
- Imports
- 30 packages
- Last checked
- 4 months ago –
Tools for package owners.