Documentation
¶
Overview ¶
Package filesview owns the Files tool of the /files page (0.9 P4, N20): lazy direct-directory listing, directories-first stable sort, symlink no-recursive-follow, ignore semantics (fixed names + git-owned paths), bounded local file operations, the 1 MiB preview cap with text/binary classification, and copy-path/reveal helpers. Opening the panel performs zero repository-wide recursive scans; only a search the user starts reads the whole tree (search.go: file index + ripgrep/git grep content search).
Index ¶
- Constants
- Variables
- func CreateDir(root, dirRel, name string) (string, error)
- func CreateFile(root, dirRel, name string) (string, error)
- func DecodeImageBounded(path string) (image.Image, error)
- func DecodeImageBytes(raw []byte) (image.Image, error)
- func Delete(root, rel string) (string, error)
- func FormatFileSize(bytes int64) string
- func GitIgnorePaths(ctx context.Context, root string) ([]string, error)
- func ImageMIME(name string) string
- func IsBinary(buf []byte) bool
- func MatchFiles(paths []string, query string, limit int) (hits []string, total int)
- func ReadImageDataURL(path string) (string, error)
- func Rename(root, rel, newName string) (string, error)
- func ResolveRipgrep() string
- func SortEntries(entries []Entry)
- func ValidateName(name string) error
- type ContentFile
- type ContentMatch
- type ContentQuery
- type ContentResult
- type Entry
- type EntryKind
- type FileIndex
- type Flavor
- type IgnoreSet
- type Preview
Constants ¶
const ( // SearchDeadline bounds one search or file listing. SearchDeadline = 15 * time.Second // MaxIndexedFiles caps the listed files of one root. MaxIndexedFiles = 100000 // MaxContentMatches caps the matches one content search returns. MaxContentMatches = 500 // MaxMatchesPerFile caps the matches kept from one file. MaxMatchesPerFile = 20 // MaxLineChars caps the characters of a matching line that are shown. MaxLineChars = 300 // MinContentQuery is the shortest pattern a content search runs for. MinContentQuery = 2 )
const IgnoreDeadline = 5 * time.Second
IgnoreDeadline bounds the git ignore lookup; gitintel uses the same discipline. A non-repository root fails fast with an empty set.
const ImagePreviewCap = 24 << 20
ImagePreviewCap is the largest image the WebView tier takes as a data URL (24 MiB; text keeps the 1 MiB PreviewCap). Beyond it the Native UI tier renders.
const MaxNativeImagePixels = 32 << 20
MaxNativeImagePixels bounds the Native tier's decoded bitmap: 32M pixels (a 128 MiB RGBA buffer). DecodeConfig rejects insanity before the full decode allocates.
const PreviewCap = 1024 * 1024
PreviewCap is the 1 MiB maximum size for a file preview (WIX-055): what the WebView page takes of a Markdown file to render.
const TextPreviewCap = 8 << 20
TextPreviewCap bounds what the native code view takes of a file: the framework's editor virtualizes its lines, so text is shown to 8 MiB, past which the head shows with Truncated set.
Variables ¶
var ErrBadName = errors.New("invalid name")
ErrBadName reports a name that cannot be one child entry.
var ErrDimensionsTooLarge = errors.New("image dimensions exceed the preview budget")
ErrDimensionsTooLarge reports an image whose decoded size exceeds the Native tier's pixel budget.
var ErrNoContentEngine = errors.New("Content search needs ripgrep installed, or a Git repository")
ErrNoContentEngine reports that neither ripgrep nor a Git repository is available to search the root's content.
var ErrNotADirectory = errors.New("path is not a directory")
ErrNotADirectory reports attempting to list a non-directory.
var ErrTooLarge = errors.New("file is too large for the web preview")
ErrTooLarge reports a file beyond its flavor's WebView cap; the caller falls back to the Native UI tier.
Functions ¶
func CreateDir ¶
CreateDir creates one directory inside dirRel (single level, so a typo cannot build an unexpected hierarchy). The name must not exist.
func CreateFile ¶
CreateFile creates one empty file inside dirRel. The name must not exist. Returns the created absolute path.
func DecodeImageBounded ¶
DecodeImageBounded decodes an image for the Native UI tier (the WebView tier already refused it as too large): the pixel budget is checked via DecodeConfig before the full decode allocates. Runs off the UI lane; the caller wraps the result in ui.NewBitmap on the UI lane.
func DecodeImageBytes ¶
DecodeImageBytes is DecodeImageBounded for bytes already in hand (a Git blob): the same pixel budget, checked before the full decode allocates.
func Delete ¶
Delete removes the entry at rel. Directories are removed recursively (the UI confirms first); a symlink is unlinked, never followed.
func FormatFileSize ¶
FormatFileSize returns a compact, human-readable size string.
func GitIgnorePaths ¶
GitIgnorePaths returns the root's ignored paths as slash-separated relative paths, directories without a trailing slash (--directory folds node_modules into one line instead of enumerating its contents). -z keeps paths verbatim: no C-style quoting for non-ASCII (core.quotePath), no whitespace mangling. Any git failure — not a repository, no git binary — yields an empty list and an error; the caller keeps the fixed-name set.
func IsBinary ¶
IsBinary detects binary content (WIX-054): contains NUL bytes in the first 8 KiB or is not valid UTF-8.
func MatchFiles ¶
MatchFiles ranks the paths that match every word of the query, best first. A word matches as a substring of the path or, failing that, as a subsequence of it; a hit in the file's own name beats one in a folder, and a shorter path beats a longer one. total is the count before limit.
func ReadImageDataURL ¶
ReadImageDataURL reads an image up to ImagePreviewCap and returns it as a data URL for the WebView tier's <img>.
func Rename ¶
Rename renames the entry at rel within its own directory. A distinct existing target is refused rather than silently replaced (os.Rename would overwrite it); a case-only variant of the same name is allowed through — on case-insensitive filesystems (default APFS) it collides in Lstat but is the ordinary "fix the casing" rename.
func ResolveRipgrep ¶
func ResolveRipgrep() string
ResolveRipgrep finds ripgrep: PATH first, then the places a Finder-launched app (which does not inherit the shell's PATH) will not look on its own. Empty when it is not installed.
func SortEntries ¶
func SortEntries(entries []Entry)
SortEntries applies the stable WIX-051 order: directories first, then alphabetical case-insensitive.
func ValidateName ¶
ValidateName refuses names that are blank, carry path separators (on any platform, so a cross-platform tree cannot create names Windows breaks on) or NUL, or are relative path segments themselves.
Types ¶
type ContentFile ¶
type ContentFile struct {
Path string // slash-separated, relative to the root
Matches []ContentMatch
More bool // more lines matched than MaxMatchesPerFile
}
ContentFile is the matches of one file.
type ContentMatch ¶
ContentMatch is one matching line. Text is the line without its leading whitespace, cut to MaxLineChars; Start and End are the first match's byte range in Text (-1 when it cannot be located); Col is that match's byte offset in the whole line, for opening the file on it.
type ContentQuery ¶
type ContentQuery struct {
Pattern string
CaseSensitive bool
WholeWord bool
Regex bool
IncludeIgnored bool
}
ContentQuery is one full-text search over a root.
type ContentResult ¶
type ContentResult struct {
Files []ContentFile
Matches int
Truncated bool // MaxContentMatches reached
Engine string // "ripgrep" or "git grep"
}
ContentResult is a finished search.
func SearchContent ¶
func SearchContent(ctx context.Context, root string, q ContentQuery) (ContentResult, error)
SearchContent runs a full-text search under root. A pattern shorter than MinContentQuery yields no result.
type Entry ¶
type Entry struct {
Name string `json:"name"`
Path string `json:"path"` // absolute path
RelPath string `json:"rel_path"`
Kind EntryKind `json:"kind"`
SizeBytes int64 `json:"size_bytes"`
IsDir bool `json:"is_dir"`
IsSymlink bool `json:"is_symlink"`
// TargetDir marks a symlink pointing to a directory; the no-recursive-
// follow rule prevents expanding it in the tree (WIX-052).
TargetDir bool `json:"target_dir"`
}
Entry is one direct child of a listed directory.
func ListDirect ¶
ListDirect lists only the immediate children of dir (no recursion; WIX-050). Results sort directories first, then alphabetical case- insensitive (WIX-051). Hidden files/directories (.git, .DS_Store, ...) stay visible by default so developers see project realities.
type EntryKind ¶
type EntryKind string
EntryKind distinguishes directory nodes from files and symlinks.
type FileIndex ¶
FileIndex is a root's files as slash-separated relative paths.
type Flavor ¶
type Flavor string
Flavor names the three render paths a preview can take.
func PreviewFlavor ¶
PreviewFlavor maps a filename to its preview flavor. Everything that is neither Markdown nor an image previews as text (the code view highlights by extension; unknown extensions render plain).
type IgnoreSet ¶
type IgnoreSet struct {
// contains filtered or unexported fields
}
IgnoreSet answers one question for the tree renderer: is this entry hidden? It merges the fixed names with git's ignored paths for the root.
func NewIgnoreSet ¶
NewIgnoreSet builds the merged set from git's ignored relative paths.
type Preview ¶
type Preview struct {
Path string `json:"path"`
SizeBytes int64 `json:"size_bytes"`
IsBinary bool `json:"is_binary"`
Truncated bool `json:"truncated"`
Content string `json:"content"`
}
Preview carries the read-only content of one inspected file.
func ReadPreview ¶
ReadPreview reads a file up to PreviewCap (1 MiB; WIX-055), classifying text vs binary (WIX-054). Truncated is true when the file exceeds 1 MiB. If root is provided, path is verified to stay within root (symlink escape guard).