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:
zerorigin committed 2026-11-05 15:43:33 +08:00
1 parent bbff08f364
commit 4ace9c9fb6
14 files changed
+965 -34

No files matched your search

+99 -2
View File
@@ -49,6 +49,9 @@ type coverState struct {
files map[string]coverFile // 键是小写规范化的绝对路径
all float64
total string // 整体一行摘要,显示在状态栏
// failMsg 非空表示这一轮 go test 有失败,覆盖率数字不可信;
// 详情已写进输出面板,界面上只放这一行摘要。
failMsg string
}
// parseCoverProfile 解析 coverprofile 文本。
@@ -153,20 +156,101 @@ func (a *App) RunCoverage() {
lines = append(lines, line)
}
t.Wait()
// Task.Wait 没有返回值,退出状态只能从 ExitCode 取(未结束是 -1)。
code := t.ExitCode()
data, readErr := os.ReadFile(path)
a.win.Update(func() {
a.cover.running = false
if code != 0 {
// 测试没全过时 coverprofile 可能只是一部分包的,数字会骗人:
// 摘要放本页,明细进输出面板(本页只显示覆盖率,看不到日志)。
a.cover.failMsg = coverageFailSummary(code, lines)
a.appendOut("$ go test -coverprofile=… ./...")
for _, ln := range coverageFailLines(lines) {
a.appendOut(ln)
}
a.appendOut("覆盖率:测试未全部通过,以上数字仅供参考")
} else {
a.cover.failMsg = ""
}
if readErr != nil {
a.appendOut("覆盖率失败:没拿到 coverprofile")
if code != 0 {
a.appendOut("覆盖率失败:测试未通过,没有生成 coverprofile")
} else {
a.appendOut("覆盖率失败:没拿到 coverprofile")
}
a.refresh()
return
}
a.applyCoverage(string(data))
})
_ = lines
}()
}
// coverFailCap 是回放到输出面板的失败行上限:全量回放会刷屏。
const coverFailCap = 200
// coverageFailLines 从 go test 输出里挑出能说明失败原因的行。
//
// 只挑这几类:FAIL 汇总、--- FAIL 用例、panic、以及带 file.go:12: 的
// 断言消息(parseOutLine 认得出位置,点一下能跳源码)。其余(ok 行、
// 进度行)丢掉,避免把输出面板灌满。
func coverageFailLines(lines []string) []string {
out := make([]string, 0, 16)
for _, ln := range lines {
s := strings.TrimSpace(ln)
if s == "" {
continue
}
keep := strings.HasPrefix(s, "FAIL") ||
strings.HasPrefix(s, "--- FAIL") ||
strings.HasPrefix(s, "panic:") ||
strings.HasPrefix(s, "# ")
if !keep {
if _, ok := splitLoc(s); ok {
keep = true
}
}
if !keep {
continue
}
out = append(out, ln)
if len(out) >= coverFailCap {
out = append(out, fmt.Sprintf("…(失败输出超过 %d 行,已截断)", coverFailCap))
break
}
}
return out
}
// coverageFailSummary 生成一行失败摘要,例如:
// 「2 个包失败 · 3 个用例失败(go test 退出码 1)」。
func coverageFailSummary(code int, lines []string) string {
var pkgs, cases int
for _, ln := range lines {
s := strings.TrimSpace(ln)
switch {
case strings.HasPrefix(s, "--- FAIL"):
cases++
case strings.HasPrefix(s, "FAIL\t"), strings.HasPrefix(s, "FAIL "):
if !strings.HasPrefix(s, "FAIL\t ") {
pkgs++
}
}
}
parts := make([]string, 0, 3)
if pkgs > 0 {
parts = append(parts, fmt.Sprintf("%d 个包失败", pkgs))
}
if cases > 0 {
parts = append(parts, fmt.Sprintf("%d 个用例失败", cases))
}
if len(parts) == 0 {
parts = append(parts, "go test 未通过")
}
return fmt.Sprintf("%s(退出码 %d),覆盖率数字仅供参考", strings.Join(parts, " · "), code)
}
// applyCoverage 把 coverprofile 套到打开的文件上。
func (a *App) applyCoverage(text string) {
files := parseCoverProfile(text)
@@ -308,6 +392,19 @@ func (a *App) coverageView(c *ui.Context) {
}
})
// 上一轮测试没全过:数字不可信,先把话说明白,再给个去看日志的入口。
if a.cover.failMsg != "" {
ui.Row(c).Padding(3, 10).Gap(8).AlignItems(ui.Center).
Background(t.Danger.Alpha(0.12)).Children(func() {
ui.Text(c, "⚠ "+a.cover.failMsg).FontSize(11).
TextColor(t.Danger).SingleLine()
ui.Box(c).Grow(1)
if ui.Button(c, "查看测试输出").Clicked() {
a.panelTab = 0
}
})
}
if len(a.cover.files) == 0 {
ui.Column(c).Grow(1).FillHeight().Center().Children(func() {
ui.Text(c, "点「统计覆盖率」跑一遍 go test -coverprofile").FontSize(12).