Documentation
¶
Overview ¶
Package fsview 提供受限工作目录内的文件浏览 / 管理。
路径钉在 session 的 cwd(git 项目的 worktree 或非 git 项目目录),前端只传相对路径, 后端 safeJoin 解析并校验「结果仍落在 root 内」,防 ../ 越界与符号链接逃逸。
供右侧「文件」面板:列目录(懒加载,git 仓库尊重 .gitignore)、读文件、增删改。
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEscapesRoot = errors.New("path escapes workspace root")
ErrEscapesRoot 路径越界(试图跳出 root)。
Functions ¶
func CreateFile ¶
CreateFile 新建文件(含内容)。父目录自动创建;已存在则报错。
func RenamePath ¶
RenamePath 把 root/rel 改名为 newName(仅叶子名,不含路径)。 返回新的相对路径。非法名(含路径分隔符 / . / ..)拒绝。
Types ¶
type FileData ¶
type FileData struct {
Content string `json:"content"`
Binary bool `json:"binary"`
TooLarge bool `json:"tooLarge"`
}
FileData is the structured result of ReadFile: the text content plus the reasons content may be absent. Binary / too-large files return zero Content with the flag set, so callers (frontend preview/edit gating) decide off a typed field instead of matching placeholder strings.
type FileNode ¶
type FileNode struct {
Name string `json:"name"`
Path string `json:"path"` // 相对 root 的路径(用 / 分隔,前端原样回传用于展开/操作)
IsDir bool `json:"isDir"`
Size int64 `json:"size,omitempty"` // 文件字节数
}
FileNode 树节点(一层):目录或文件。
func FuzzyFind ¶
FuzzyFind 在 root 的 scope 子树下按 query 子串模糊匹配路径,返回最多 limit 个命中 (文件与目录都参与匹配)。
scope 限定搜索范围(相对 root 的路径,空表示整棵 root 树);先经 safeJoin 校验防越界。
query 行为:
- 空 / 纯空白:返回 scope 的直接子项(含目录,等价 ListDir),作为 picker 初始态 —— 用户打开查找器还没输入时直接看到顶层可选项。
- 非空:在 scope 子树内按整条相对路径(含目录段)子串匹配,大小写不敏感,命中含目录。 例如 "sub/b" 命中 "src/sub/b.go","go" 命中所有 .go 文件与名为 xxxgo 的目录。
数据源分两条:
- git 仓库:复用 gitVisibleFiles(尊重 .gitignore);目录从文件路径隐式推导 (git 不跟踪目录,但含文件的目录必然存在)。
- 非 git 目录:filepath.WalkDir 跳过 heavyDirs(.git / node_modules 等)整棵子树。
返回路径始终相对 root(与 ListDir 一致,前端原样回传)。limit<=0 取 defaultFuzzyLimit。 结果按路径字母序(大小写不敏感),目录与文件混合排序(fuzzy finder 语义,非 ListDir 的目录优先)。