file

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPollInterval = time.Second

Variables

This section is empty.

Functions

func AutocompleteDirectory added in v1.3.0

func AutocompleteDirectory(path string) ([]string, error)

AutocompleteDirectory autocompletes the last subdirectory in a path.

func GlobMatch added in v0.2.0

func GlobMatch(pattern, name string) bool

GlobMatch checks if a path matches a glob pattern. A "*" in the pattern is a wildcard that matches part of a component in a path. A "**" in a component of the pattern is a wildcard that matches components of the path. For example, the pattern "**/*.go" matches "foo/bar/baz.go" The algorithm is based on the backtracking approach described in https://research.swtch.com/glob

func ListDir added in v0.2.0

func ListDir(ctx context.Context, root string, options ListDirOptions) []string

ListDir lists every file in a root directory and its subdirectories. The returned paths are relative to the root directory. The order of the returned paths is non-deterministic. Symbolic links are not followed. If an error occurs while accessing a directory, ListDir will skip that directory and log the error.

func RelativePath

func RelativePath(p string, baseDir string) string

RelativePath converts an absolute path to a path relative to a base directory. If the conversion fails, the absolute path will be returned instead.

func RelativePathCwd

func RelativePathCwd(p string) string

RelativePathCwd converts an absolute path to a path relative to the current working directory. If the conversion fails, the absolute path will be returned instead.

func ValidateCreate added in v1.3.0

func ValidateCreate(path string) error

ValidateCreate checks whether the user can (probably) create a file at a path. This is meant to catch common issues (non-existent directory, file already exists) but isn't 100% accurate. In particular, another process could modify the filesystem after the check, or the user might not have permission to create the file.

Types

type Checksummer

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

Checksummer calculates an MD5 checksum.

func NewChecksummer

func NewChecksummer() *Checksummer

func (*Checksummer) Checksum

func (c *Checksummer) Checksum() string

Checksum returns the MD5 checksum as a base16 string.

func (*Checksummer) Write

func (c *Checksummer) Write(p []byte) (n int, err error)

Write implements io.Writer#Write()

type ListDirOptions added in v0.7.0

type ListDirOptions struct {
	DirPatternsToHide []string // Glob patterns for directories to skip.
	DirectoriesOnly   bool     // If true, return directories (not files) in results.
}

type Timeline

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

Timeline represents the history of files loaded in the editor. It provides the ability to move forward or backward through loaded files.

func NewTimeline

func NewTimeline() *Timeline

NewTimeline returns a new, empty timeline.

func (*Timeline) PeekBackward

func (t *Timeline) PeekBackward() TimelineState

PeekBackward returns the state immediately before the current state.

func (*Timeline) PeekForward

func (t *Timeline) PeekForward() TimelineState

PeekForward returns the state immediately after the current state.

func (*Timeline) TransitionBackwardFrom

func (t *Timeline) TransitionBackwardFrom(fromState TimelineState)

TransitionBackwardFrom moves the timeline backward to the previous state.

func (*Timeline) TransitionForwardFrom

func (t *Timeline) TransitionForwardFrom(fromState TimelineState)

TransitionForwardFrom moves the timeline forward to the next state.

func (*Timeline) TransitionFrom

func (t *Timeline) TransitionFrom(fromState TimelineState)

TransitionFrom moves the timeline forward from the given state and invalidates any future states in the timeline. This happens when the user loads a new document in the editor.

type TimelineState

type TimelineState struct {
	Path    string
	LineNum uint64
	Col     uint64
}

TimelineState represents the state of a file loaded in the editor before or after a transition in the timeline.

func (TimelineState) Empty

func (s TimelineState) Empty() bool

Empty checks whether the timeline state is empty. An empty state represents the beginning or end of the timeline.

type Watcher

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

Watcher checks if a file's contents have changed.

func Load

func Load(path string, watcherPollInterval time.Duration) (*text.Tree, *Watcher, error)

Load reads a file from disk and starts a watcher to detect changes. This will remove the POSIX end-of-file indicator (line feed at end of file).

func NewEmptyWatcher

func NewEmptyWatcher() *Watcher

NewEmptyWatcher returns a watcher that has an empty path and never triggers.

func NewWatcherForExistingFile added in v1.3.0

func NewWatcherForExistingFile(pollInterval time.Duration, path string, lastModified time.Time, size int64, checksum string) *Watcher

NewWatcherForExistingFile returns a watcher for a file that exists on disk. lastModified is the time the file was last modified, as reported when the file was loaded. size is the size in bytes of the file when it was loaded. checksum is an MD5 hash of the file's contents when it was loaded.

func NewWatcherForNewFile added in v1.3.0

func NewWatcherForNewFile(pollInterval time.Duration, path string) *Watcher

NewWatcherForNewFile returns a watcher for a file that does not yet exist on disk.

func Save

func Save(path string, tree *text.Tree, watcherPollInterval time.Duration) (*Watcher, error)

Save writes the text to disk and starts a new watcher to detect subsequent changes. This adds the POSIX end-of-file indicator (line feed at the end of the file).

func (*Watcher) ChangedChan

func (w *Watcher) ChangedChan() chan struct{}

ChangedChan returns a channel that receives a message when the file's contents change. This can produce false negatives if an error occurs accessing the file (for example, if file permissions changed). The channel will receive at most one message. This method is thread-safe.

func (*Watcher) CheckFileContentsChanged added in v0.4.0

func (w *Watcher) CheckFileContentsChanged() (bool, error)

CheckFileContentsChanged checks whether the file's checksum has changed. If the file no longer exists, this will return an error.

func (*Watcher) CheckFileMovedOrDeleted added in v1.3.0

func (w *Watcher) CheckFileMovedOrDeleted() (bool, error)

CheckFileMovedOrDeleted checks whether the file used to exist at the path but has since been moved or deleted.

func (*Watcher) Path

func (w *Watcher) Path() string

Path returns the path to the file being watched.

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop stops the watcher from checking for changes.

Jump to

Keyboard shortcuts

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