package fscache
import "cuelang.org/go/internal/lsp/fscache"
Index ¶
- func IsPhantomPackage(pkgDecl *ast.Package) bool
- func RemovePhantomPackageDecl(file *ast.File) ast.Node
- type CUECacheFS
- func NewCUECachedFS() *CUECacheFS
- func (fs *CUECacheFS) IoFS(root string) CUEDirFS
- func (fs *CUECacheFS) ReadFile(uri protocol.DocumentURI) (FileHandle, error)
- type CUEDirFS
- type DirFS
- type FileHandle
- type OverlayFS
- func NewOverlayFS(fs *CUECacheFS) *OverlayFS
- func (fs *OverlayFS) IoFS(root string) CUEDirFS
- func (fs *OverlayFS) ReadFile(uri protocol.DocumentURI) (FileHandle, error)
- func (fs *OverlayFS) Update(fun func(txn *UpdateTxn) error) error
- func (fs *OverlayFS) View(fun func(txn *ViewTxn) error) error
- type RootableFS
- type UpdateTxn
- func (txn *UpdateTxn) Delete(uri protocol.DocumentURI) error
- func (txn *UpdateTxn) Set(uri protocol.DocumentURI, content []byte, mtime time.Time, version int32) (FileHandle, error)
- type ViewTxn
Functions ¶
func IsPhantomPackage ¶
IsPhantomPackage reports whether the package declaration was created to be injected into a file's AST for files which have no package declaration themselves.
func RemovePhantomPackageDecl ¶
RemovePhantomPackageDecl removes any phantom package declaration from the provided AST.
Types ¶
type CUECacheFS ¶
type CUECacheFS struct {
// contains filtered or unexported fields
}
CUECacheFS exists to cache ast.File values and thus amortize the cost of parsing cue files. It is not an overlay in any way. Its design is influenced by gopls's similar fs caching layer (cache/fs_memoized.go in the gopls repo). CUECacheFS is also designed to bridge the API gap between LSP, in which everything is a URI, and our own module code (e.g. modpkgload) which is built around iofs.FS and related interfaces.
Note that CUECacheFS will return errors when reading files which are not understood by filetypes.ParseFileAndType.
func NewCUECachedFS ¶
func NewCUECachedFS() *CUECacheFS
func (*CUECacheFS) IoFS ¶
func (fs *CUECacheFS) IoFS(root string) CUEDirFS
IoFS implements RootableFS
func (*CUECacheFS) ReadFile ¶
func (fs *CUECacheFS) ReadFile(uri protocol.DocumentURI) (FileHandle, error)
ReadFile stats and (maybe) reads the file, updates the cache, and returns it. If uri does not exist, the error will be iofs.ErrNotExist. If uri is a directory, the error will be iofs.PathError.
type CUEDirFS ¶
type DirFS ¶
type FileHandle ¶
type FileHandle interface {
// URI is the URI for this file handle.
URI() protocol.DocumentURI
// ReadCUE attempts to parse the file content as CUE. The config
// supplied governs all parts of the parsing config apart from the
// Mode. ReadCUE will forcibly set the Mode first to ParseComments,
// and if that fails, to ImportsOnly. The returned config is the
// first config that produced no error, or, failing that, the last
// config attempted.
ReadCUE(config parser.Config) (*ast.File, parser.Config, error)
// Version returns the file version, as defined by the LSP client.
Version() int32
// Content returns the contents of a file. The byte slice returned
// is a copy of the underlying file content, and thus safe to be
// mutated. This matches the behaviour of [iofs.ReadFileFS].
Content() []byte
}
A FileHandle represents the URI, content (including parsed CUE), and optional version of a file tracked by the LSP session.
FileHandle content may be provided by the file system or from an overlay, for open files.
type OverlayFS ¶
type OverlayFS struct {
// contains filtered or unexported fields
}
OverlayFS extends CUECacheFS with an overlay facility. As with CUECacheFS, it provides both a URI-based API for use with LSP, and iofs.FS APIs for use with our module code.
func NewOverlayFS ¶
func NewOverlayFS(fs *CUECacheFS) *OverlayFS
func (*OverlayFS) IoFS ¶
IoFS implements RootableFS
func (*OverlayFS) ReadFile ¶
func (fs *OverlayFS) ReadFile(uri protocol.DocumentURI) (FileHandle, error)
ReadFile searches the overlays for the uri. If found, and is a file, the overlay is returned. If the uri is found in the overlays and is a directory, the error is iofs.PathError. If the uri is not found in the overlays, the underlying CUECacheFS.ReadFile method is called.
func (*OverlayFS) Update ¶
Update calls the given function once with a txn argument that can be used to atomically access and mutate data from fs, and must not be used after the function returns.
Multiple read-only transactions may run in parallel, but read-only and read-write transactions are mutually exclusive. Note that nested transactions of any sort are not supported, and will probably deadlock.
func (*OverlayFS) View ¶
View calls the given function once with a txn argument that can be used to atomically access read-only data from fs, and must not be used after the function returns.
Multiple read-only transactions may run in parallel, but read-only and read-write transactions are mutually exclusive. Note that nested transactions of any sort are not supported, and will probably deadlock.
type RootableFS ¶
type RootableFS interface {
// IoFS creates a CUEDirFS, for the tree of files rooted at the
// directory root. Note the root is GOOS-appropriate.
IoFS(root string) CUEDirFS
}
type UpdateTxn ¶
type UpdateTxn struct {
*ViewTxn
}
UpdateTxn provides methods to access the OverlayFS during a read-write transaction (via OverlayFS.Update). An UpdateTxn must not be used outside of a transaction.
func (*UpdateTxn) Delete ¶
func (txn *UpdateTxn) Delete(uri protocol.DocumentURI) error
Delete updates the overlay, removing the entry specified by uri. This entry could be a file or a directory. If, after the removal, a parent directory is left empty, the parent directory is also removed (and this continues transitively). I.e. no empty directories will exist within the OverlayFS. Delete is idempotent: deleting a uri that does not exist, returns nil.
This modifies the overlay *only*. It does not, under any circumstances, access the underlying CUECacheFS.
func (*UpdateTxn) Set ¶
func (txn *UpdateTxn) Set(uri protocol.DocumentURI, content []byte, mtime time.Time, version int32) (FileHandle, error)
Set updates the overlay, updating or creating a file with the given parameters. Any required parent directories will be silently created. Any existing file will be silently updated. However, if this action would require converting a file to a directory (i.e. the uri has a directory component that already exists in the overlay as a file), then an error will be returned.
The version parameter is the file version, as defined by the LSP client, corresponding to the Version method of FileHandle.
This modifies the overlay *only*. It does not, under any circumstances, access the underlying CUECacheFS.
type ViewTxn ¶
type ViewTxn struct {
*OverlayFS
}
ViewTxn provides methods to access the OverlayFS during a read-only transaction (via OverlayFS.View). A ViewTxn must not be used outside of a transaction.
func (*ViewTxn) Get ¶
func (txn *ViewTxn) Get(uri protocol.DocumentURI) (FileHandle, error)
Get is like OverlayFS.ReadFile but it *only* returns a file if it's present in the overlay itself. It does not, under any circumstances, access the underlying CUECacheFS.
func (*ViewTxn) WalkFiles ¶
func (txn *ViewTxn) WalkFiles(fun func(FileHandle) error, uri protocol.DocumentURI) error
WalkFiles invokes fun on all the files present in the overlay only. It stops walking if fun returns an error.
It does not, under any circumstances, access the underlying CUECacheFS. The function only gets passed files, never directories. All files in a directory will be passed to fun before any subdirectories; no other ordering guarantees are made.
Source Files ¶
fs_cache.go fs_overlay.go
- Version
- v0.15.1 (latest)
- Published
- Nov 21, 2025
- Platform
- linux/amd64
- Imports
- 22 packages
- Last checked
- 4 months ago –
Tools for package owners.