Documentation
¶
Index ¶
- Variables
- func CheckPathValid(path string) error
- type Cache
- type Module
- func (m *Module) ActiveFilesAndDirs(files map[protocol.DocumentURI][]packageOrModule, ...)
- func (m *Module) Encloses(file protocol.DocumentURI) bool
- func (m *Module) FindPackagesOrModulesForFile(file protocol.DocumentURI) ([]packageOrModule, error)
- func (m *Module) MarkFileDirty(file protocol.DocumentURI)
- func (m *Module) ReadCUEFile(file protocol.DocumentURI) (*ast.File, fscache.FileHandle, error)
- func (m *Module) ReloadModule() error
- func (m *Module) ReloadPackages() error
- func (m *Module) String() string
- type Package
- func (pkg *Package) ActiveFilesAndDirs(files map[protocol.DocumentURI][]packageOrModule, ...)
- func (pkg *Package) Encloses(file protocol.DocumentURI) bool
- func (pkg *Package) EnsureImportedBy(importer *Package)
- func (pkg *Package) MarkFileDirty(file protocol.DocumentURI)
- func (pkg *Package) RemoveImportedBy(importer *Package)
- func (pkg *Package) String() string
- type Registry
- type Workspace
- 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) RemoveFolder(dir protocol.DocumentURI)
- func (w *Workspace) UpdateFolderOptions(...) error
- type WorkspaceFolder
Constants ¶
This section is empty.
Variables ¶
var ErrModuleDeleted = errors.New("Module deleted")
ErrModuleDeleted is returned by any method that cannot proceed because module has been marked 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 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, 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 ¶
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 ¶
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.
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 ¶
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 ¶
RemoveImportedBy ensures that importer is not recorded as a user of this package. This method is idempotent.
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 (*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, 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.