fix: 按评估优先级修四项(标签右键/UTF-8 截断/覆盖率输出/.gitignore)
1. 标签页右键菜单接回(回归修复) tabmenu.go 的 160 行实现全库零调用点,tabBar 只处理 Clicked。 补 RightClicked → openPop(tabEntries(path)),右键时先设 active (菜单无标题,靠标签高亮传达「关闭左边」相对谁算)。 新增 tabmenu_test.go 8 个单测。 2. 中文按字节截断导致乱码 palette.go trimmed[:160]、rename.go s[:140] 会把多字节字符切断。 trimTo 从 gitlog.go 提到 strutil.go(三个调用方共用),两处改用它; n<=0 返回空串。strutil_test.go 6 个单测(含真实 linePreview 路径)。 3. 覆盖率运行不再吞测试输出 原来 lines 收集后 _ = lines 丢弃,测试失败只看到覆盖率数字。 改用 ExitCode() 判失败,只回放 FAIL/--- FAIL/panic/# 包/file.go:12 行 (上限 200),覆盖率页顶部给红底摘要 + 「查看测试输出」按钮。 coverageFailLines/Summary 纯函数 + 5 个单测。 4. 索引与搜索感知 .gitignore 新增 ignore.go:dir/、*.ext、/rootonly、带路径、**、! 取反、注释。 内置跳过扩到 vendor/dist/build/out/target/.next(文件树仍用保守 skipDir)。 indexState 加 truncated,快速打开底部提示「索引已截断至 N 个文件」。 ignore_test.go 10 个单测 + 真实遍历集成测试。 验证:go vet ./... 干净;go test ./internal/... 7 包全绿; e2e 实例 tools/tree 确认菜单 5 项齐全 + tools/shot 截图核对。
This commit is contained in:
1 parent
bbff08f364
commit
4ace9c9fb6
14 files changed
+965
-34
No files matched your search
+35
-10
@@ -10,38 +10,54 @@ import (
|
||||
|
||||
// 文件名索引与模糊匹配,供快速打开使用。
|
||||
|
||||
// indexFileCap 是文件索引的规模上限。超过就截断并置 indexState.truncated,
|
||||
// 界面据此提示——静默截断会让用户以为「搜不到就是没有」。
|
||||
const indexFileCap = 20000
|
||||
|
||||
// indexState 是工作区文件索引。
|
||||
type indexState struct {
|
||||
mu sync.Mutex
|
||||
root string
|
||||
files []string // 相对路径,正斜杠
|
||||
ready bool
|
||||
mu sync.Mutex
|
||||
root string
|
||||
files []string // 相对路径,正斜杠
|
||||
ready bool
|
||||
truncated bool // 是否因超过 indexFileCap 被截断
|
||||
}
|
||||
|
||||
// buildIndex 在后台遍历工作区,收集可打开的文件。
|
||||
//
|
||||
// 跳过规则有三层:内置目录(.git/vendor/dist…)、根 .gitignore、
|
||||
// 生成物后缀(.exe/.test)。vendor 必须跳过——一个 Go 项目的 vendor
|
||||
// 能塞几千个包,进索引后快速打开与全局搜索全是第三方噪音。
|
||||
func (a *App) buildIndex(root string) {
|
||||
rules := loadIgnoreRules(root)
|
||||
go func() {
|
||||
var files []string
|
||||
truncated := false
|
||||
_ = filepath.WalkDir(root, func(p string, d os.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
name := d.Name()
|
||||
rel, relErr := filepath.Rel(root, p)
|
||||
relSlash := ""
|
||||
if relErr == nil {
|
||||
relSlash = filepath.ToSlash(rel)
|
||||
}
|
||||
if d.IsDir() {
|
||||
if p != root && skipDir(name) {
|
||||
if p != root && (isBuiltinSkipDir(name) || rules.match(relSlash, true)) {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if skipFile(name) {
|
||||
if skipFile(name) || rules.match(relSlash, false) {
|
||||
return nil
|
||||
}
|
||||
rel, err := filepath.Rel(root, p)
|
||||
if err != nil {
|
||||
if relErr != nil {
|
||||
return nil
|
||||
}
|
||||
files = append(files, filepath.ToSlash(rel))
|
||||
if len(files) > 20000 {
|
||||
files = append(files, relSlash)
|
||||
if len(files) > indexFileCap {
|
||||
truncated = true
|
||||
return filepath.SkipAll
|
||||
}
|
||||
return nil
|
||||
@@ -51,6 +67,7 @@ func (a *App) buildIndex(root string) {
|
||||
if a.index.root == root {
|
||||
a.index.files = files
|
||||
a.index.ready = true
|
||||
a.index.truncated = truncated
|
||||
}
|
||||
a.index.mu.Unlock()
|
||||
}()
|
||||
@@ -72,6 +89,14 @@ func (a *App) indexSnapshot() ([]string, bool) {
|
||||
return a.index.files, a.index.ready
|
||||
}
|
||||
|
||||
// indexTruncated 报告索引是否因超过 indexFileCap 被截断。
|
||||
// 只看已建好的索引:没建好时截断与否还没有意义。
|
||||
func (a *App) indexTruncated() bool {
|
||||
a.index.mu.Lock()
|
||||
defer a.index.mu.Unlock()
|
||||
return a.index.ready && a.index.truncated
|
||||
}
|
||||
|
||||
// fuzzyScore 判断 query 是否为 path 的子序列,并给出一个分数(越大越靠前)。
|
||||
//
|
||||
// 规则很朴素:连续匹配、匹配到文件名部分、匹配位置靠前,都会加分。
|
||||
|
||||
Reference in new issue
Block a user