cache

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOverlayFS

func NewOverlayFS(delegate FileSource) *overlayFS

Types

type AST

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

type Cache

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

func New

func New(store *memoize.Store) *Cache

func (*Cache) ID

func (c *Cache) ID() string

func (*Cache) MemStats

func (c *Cache) MemStats() map[reflect.Type]int

func (Cache) ReadFile

func (fs Cache) ReadFile(ctx context.Context, uri uri.URI) (FileHandle, error)

ReadFile stats and (maybe) reads the file, updates the cache, and returns it.

type DiskFile

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

A DiskFile is a file on the filesystem, or a failure to read one. It implements the source.FileHandle interface.

func (*DiskFile) Content

func (h *DiskFile) Content() ([]byte, error)

func (*DiskFile) FileIdentity

func (h *DiskFile) FileIdentity() FileIdentity

func (*DiskFile) Saved

func (h *DiskFile) Saved() bool

func (*DiskFile) URI

func (h *DiskFile) URI() uri.URI

func (*DiskFile) Version

func (h *DiskFile) Version() int32

type FileChange

type FileChange struct {
	URI     uri.URI
	Version int
	Content []byte
	From    FileChangeType
}

func FileChangeFromLSPDidChange

func FileChangeFromLSPDidChange(params *protocol.DidChangeTextDocumentParams) []*FileChange

func (*FileChange) FullContent

func (f *FileChange) FullContent(base []byte) []byte

type FileChangeType

type FileChangeType string
const (
	FileChangeTypeInitialize FileChangeType = "Initialize"
	FileChangeTypeDidOpen    FileChangeType = "DidOpen"
	FileChangeTypeDidChange  FileChangeType = "DidChange"
	FileChangeTypeDidSave    FileChangeType = "DidSave"
)

type FileHandle

type FileHandle interface {
	// URI is the URI for this file handle.
	// TODO(rfindley): this is not actually well-defined. In some cases, there
	// may be more than one URI that resolve to the same FileHandle. Which one is
	// this?
	URI() uri.URI
	// FileIdentity returns a FileIdentity for the file, even if there was an
	// error reading it.
	FileIdentity() FileIdentity
	// Saved reports whether the file has the same content on disk:
	// it is false for files open on an editor with unsaved edits.
	Saved() bool
	// Version returns the file version, as defined by the LSP client.
	// For on-disk file handles, Version returns 0.
	Version() int32
	// Content returns the contents of a file.
	// If the file is not available, returns a nil slice and an error.
	Content() ([]byte, error)
}

A FileHandle represents the URI, content, hash, and optional version of a file tracked by the LSP session.

File content may be provided by the file system (for Saved files) or from an overlay, for open files with unsaved edits. A FileHandle may record an attempt to read a non-existent file, in which case Content returns an error.

type FileID

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

A FileID uniquely identifies a file in the file system.

If GetFileID(name1) returns the same ID as GetFileID(name2), the two file names denote the same file. A FileID is comparable, and thus suitable for use as a map key.

func GetFileID

func GetFileID(filename string) (FileID, time.Time, error)

GetFileID returns the file system's identifier for the file, and its modification time. Like os.Stat, it reads through symbolic links.

type FileIdentity

type FileIdentity struct {
	URI  uri.URI
	Hash Hash // digest of file contents
}

FileIdentity uniquely identifies a file at a version from a FileSystem.

func (FileIdentity) String

func (id FileIdentity) String() string

type FileSource

type FileSource interface {
	// ReadFile returns the FileHandle for a given URI, either by
	// reading the content of the file or by obtaining it from a cache.
	ReadFile(ctx context.Context, uri uri.URI) (FileHandle, error)
}

A FileSource maps URIs to FileHandles.

type FilesMap

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

FilesMap holds files on disk and overlay files

func (*FilesMap) Clone

func (m *FilesMap) Clone() *FilesMap

func (*FilesMap) Destroy

func (m *FilesMap) Destroy()

func (*FilesMap) Forget

func (m *FilesMap) Forget(key uri.URI)

func (*FilesMap) Get

func (m *FilesMap) Get(key uri.URI) (FileHandle, bool)

func (*FilesMap) Set

func (m *FilesMap) Set(key uri.URI, file FileHandle)

type Hash

type Hash [sha256.Size]byte

func HashOf

func HashOf(data []byte) Hash

HashOf returns the hash of some data.

func Hashf

func Hashf(format string, args ...interface{}) Hash

Hashf returns the hash of a printf-formatted string.

func (Hash) Less

func (h Hash) Less(other Hash) bool

Less returns true if the given hash is less than the other.

func (Hash) String

func (h Hash) String() string

String returns the digest as a string of hex digits.

func (*Hash) XORWith

func (h *Hash) XORWith(h2 Hash)

XORWith updates *h to *h XOR h2.

type IncludeGraph

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

func NewIncludeGraph

func NewIncludeGraph() *IncludeGraph

func (*IncludeGraph) Clone

func (g *IncludeGraph) Clone() *IncludeGraph

func (*IncludeGraph) Debug

func (g *IncludeGraph) Debug()

func (*IncludeGraph) Get

func (g *IncludeGraph) Get(file uri.URI) *IncludeNode

func (*IncludeGraph) Remove

func (g *IncludeGraph) Remove(file uri.URI)

func (*IncludeGraph) Set

func (g *IncludeGraph) Set(file uri.URI, includes []*parser.Include)

type IncludeNode

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

func (*IncludeNode) Clone

func (n *IncludeNode) Clone() *IncludeNode

func (*IncludeNode) InDegree

func (n *IncludeNode) InDegree() []uri.URI

func (*IncludeNode) OutDegree

func (n *IncludeNode) OutDegree() []uri.URI

type Overlay

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

An Overlay is a file open in the editor. It may have unsaved edits. It implements the source.FileHandle interface.

func NewOverlay

func NewOverlay(uri uri.URI, content []byte, version int32) *Overlay

func (*Overlay) Content

func (o *Overlay) Content() ([]byte, error)

func (*Overlay) FileIdentity

func (o *Overlay) FileIdentity() FileIdentity

func (*Overlay) Saved

func (o *Overlay) Saved() bool

func (*Overlay) URI

func (o *Overlay) URI() uri.URI

func (*Overlay) Version

func (o *Overlay) Version() int32

type ParseCaches

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

func NewParseCaches

func NewParseCaches() *ParseCaches

func (*ParseCaches) Clone

func (c *ParseCaches) Clone() *ParseCaches

func (*ParseCaches) Forget

func (c *ParseCaches) Forget(filePath uri.URI)

func (*ParseCaches) Get

func (c *ParseCaches) Get(filePath uri.URI) *ParsedFile

func (*ParseCaches) Set

func (c *ParseCaches) Set(filePath uri.URI, res *ParsedFile)

func (*ParseCaches) Tokens

func (c *ParseCaches) Tokens() map[string]struct{}

type ParsedFile

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

func Parse

func Parse(fh FileHandle) (*ParsedFile, error)

TODO(jpf): use promise

func (*ParsedFile) AST

func (p *ParsedFile) AST() *parser.Document

func (*ParsedFile) AggregatedError

func (p *ParsedFile) AggregatedError() error

func (*ParsedFile) DumpAST

func (p *ParsedFile) DumpAST()

DumpAST is for debug

func (*ParsedFile) Errors

func (p *ParsedFile) Errors() []parser.ParserError

func (*ParsedFile) Mapper

func (p *ParsedFile) Mapper() *mapper.Mapper

type Position

type Position struct {
	Filename string // filename, if any
	Offset   int    // offset, starting at 0
	Line     int    // line number, starting at 1
	Column   int    // column number, starting at 1 (byte count)
}

func (Position) IsValid

func (p Position) IsValid() bool

func (Position) String

func (p Position) String() string

type Session

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

func NewSession

func NewSession(cache *Cache) *Session

func (*Session) CreateView

func (s *Session) CreateView(folder uri.URI)

func (*Session) Initialize

func (s *Session) Initialize(fn func())

func (Session) Overlays

func (fs Session) Overlays() []*Overlay

Overlays returns a new unordered array of overlays.

func (Session) ReadFile

func (fs Session) ReadFile(ctx context.Context, uri uri.URI) (FileHandle, error)

func (Session) Update

func (fs Session) Update(ctx context.Context, changes []*FileChange) error

Update only updates overlays

func (*Session) UpdateOverlayFS

func (s *Session) UpdateOverlayFS(ctx context.Context, changes []*FileChange) error

func (*Session) ViewOf

func (s *Session) ViewOf(fileURI uri.URI) (*View, error)

type Snapshot

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

func BuildSnapshotForTest

func BuildSnapshotForTest(files []*FileChange) *Snapshot

func NewSnapshot

func NewSnapshot(view *View, store *memoize.Store) *Snapshot

func (*Snapshot) Acquire

func (s *Snapshot) Acquire() func()

func (*Snapshot) ForgetFile

func (s *Snapshot) ForgetFile(uri uri.URI)

ForgetFile is called when file changed or removed it remove file cache and parsed cache

func (*Snapshot) Graph

func (s *Snapshot) Graph() *IncludeGraph

func (*Snapshot) Initialize

func (s *Snapshot) Initialize(ctx context.Context)

func (*Snapshot) Parse

func (s *Snapshot) Parse(ctx context.Context, uri uri.URI) (*ParsedFile, error)

func (*Snapshot) ReadFile

func (s *Snapshot) ReadFile(ctx context.Context, uri uri.URI) (FileHandle, error)

func (*Snapshot) Tokens

func (s *Snapshot) Tokens() map[string]struct{}

type View

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

func NewView

func NewView(name string, folder uri.URI, fs FileSource, store *memoize.Store) *View

func (*View) ContainsFile

func (v *View) ContainsFile(uri uri.URI) bool

func (*View) FileChange

func (v *View) FileChange(ctx context.Context, changes []*FileChange, postFns ...func())

func (*View) FileKnown

func (v *View) FileKnown(uri uri.URI) bool

func (*View) MarkFileKnown

func (v *View) MarkFileKnown(fileURI uri.URI)

func (*View) Snapshot

func (v *View) Snapshot() (*Snapshot, func())

Jump to

Keyboard shortcuts

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