Documentation
¶
Overview ¶
Package workspacefiles serves ranked file and folder search under one directory root from a cached, git-backed index with a bounded walk fallback.
Index ¶
- Constants
- Variables
- type Entry
- type EntryKind
- type GitRunner
- type Index
- type Option
- func WithBuildTimeout(timeout time.Duration) Option
- func WithCacheTTL(ttl time.Duration) Option
- func WithClock(now func() time.Time) Option
- func WithGitTimeout(timeout time.Duration) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMaxFiles(limit int) Option
- func WithMaxWalkEntries(limit int) Option
- type Result
- type StreamingGitRunner
Constants ¶
const ( // DefaultMaxFiles caps the number of files indexed per root. DefaultMaxFiles = 25_000 // DefaultCacheTTL is how long a built index serves searches for one root. DefaultCacheTTL = 15 * time.Second // DefaultGitTimeout bounds the git subprocesses of one index build. DefaultGitTimeout = 5 * time.Second // DefaultBuildTimeout bounds one whole shared index build, git and walk fallback included. DefaultBuildTimeout = 10 * time.Second // DefaultMaxWalkEntries caps the directory entries (files and folders) one walk visits. DefaultMaxWalkEntries = 4 * DefaultMaxFiles )
Variables ¶
var ErrInvalidRoot = errors.New("workspacefiles: search root is required")
ErrInvalidRoot reports a blank search root.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
Path string // relative to the searched root; folders end in "/"
Name string
Kind EntryKind
}
Entry is one indexed file or folder.
type GitRunner ¶
type GitRunner interface {
Run(ctx context.Context, dir string, args ...string) (stdout []byte, stderr []byte, err error)
}
GitRunner runs git with structured arguments. It is satisfied by worktree.RealGitRunner, which internal/daemon injects; this package never spawns git itself.
type Index ¶
type Index interface {
Search(ctx context.Context, root string, query string, limit int) (Result, error)
}
Index searches files and folders under a directory root.
type Option ¶
type Option func(*index)
Option customizes an index. Options exist for tests.
func WithBuildTimeout ¶
WithBuildTimeout overrides the deadline of one shared build.
func WithCacheTTL ¶
WithCacheTTL overrides the per-root cache lifetime.
func WithGitTimeout ¶
WithGitTimeout overrides the git deadline of one build.
func WithLogger ¶
WithLogger overrides the index logger.
func WithMaxFiles ¶
WithMaxFiles overrides the per-root file cap.
func WithMaxWalkEntries ¶
WithMaxWalkEntries overrides how many directory entries one walk may visit.
type Result ¶
type Result struct {
Entries []Entry
// Truncated reports that the root held more files than the index cap.
Truncated bool
}
Result is one ranked search page.
type StreamingGitRunner ¶
type StreamingGitRunner interface {
GitRunner
RunStreaming(
ctx context.Context,
dir string,
onStdout func(chunk []byte),
args ...string,
) (stderr []byte, err error)
}
StreamingGitRunner is an optional GitRunner capability that delivers stdout chunks as git writes them, without an output cap. When the injected runner implements it, listings stream and stop at the index cap; otherwise the buffered Run path is used.