Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Agent 笔记:项目树目录读取使用独立 I/O 限时

状态:已实现

## 先说结论

项目树读取会访问文件系统并查询 Git,不能沿用纯计算请求的两秒限时。
桌面端为每批目录读取保留三十秒上限,关闭项目仍立即取消请求。
同级忽略目录的跟踪文件检查属于独立 Rust Core 仓库;本文对应的主仓库修改不改变 Core 固定版本,也不把本地 Core 优化当成已经合入的能力。

## 问题

Windows 0.8.0 的项目树把目录读取超时统一显示为项目目录不可用,虽然目录和 Git 均正常。
诊断项目的十个忽略目录触发逐项 Git 检查,单独复现耗时 2.412 秒,超过原请求限时。

## 决策

- `desktop/internal/workbench/filetree.go` 仅对目录列表使用独立 I/O 限时,仍通过项目 context 取消,并复用既有过期结果隔离。
- Git 忽略与跟踪规则留在外部 Rust Core,桌面端不复制或解释 Git 忽略策略。
- Core 批量查询优化与桌面端 I/O 生命周期修改分别提交,依赖升级前保持原固定版本和契约。

## 考虑过的备选方案

- 重开项目或重新安装 Git:不改变稳定复现的查询数量和限时。
- 全局提高纯计算限时:会扩大无关调用的等待范围。
- 无界等待或在 Go 重写忽略规则:分别失去故障上限、破坏共享逻辑归属。

## 后果

慢磁盘上的目录读取可以完成;永久阻塞仍由有限超时和关闭项目的取消边界约束。
本地诊断包通过 `LITHE_CORE_RUST_DIR` 链接任务目录的 Core 优化,并保留原始修订、补丁和构建身份;它的性能数据不能代表本次主仓库 PR 已包含 Core 优化。

## 验证

先确认 Go 的 `TestProjectTreeDirectoryReadsAllowNativeIO` 在修复前失败,再验证修复后通过,并检查 `TestProjectTreeDirectoryReadCancelsWhenProjectCloses`。
实际项目读取、独立 Core 优化及本地诊断包的验证分别记录,不能混用;测试报告随本地构建保存。

## 适用范围

Viva 桌面端项目树和所链接 Rust Core 的索引目录决策;不改变项目文件、Git 配置或安装目录写入规则。
7 changes: 6 additions & 1 deletion desktop/internal/workbench/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"path/filepath"
"time"

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
Expand Down Expand Up @@ -208,6 +209,10 @@ func (a *App) listTree(p *project, paths ...string) {

const treeListingBatch = 64

// Directory reads include native I/O and Git ignore queries, unlike the pure Core
// computations guarded by kernelCallTimeout. Project closure still cancels each read.
const treeListingTimeout = 30 * time.Second

// pumpTreeListings keeps only one bounded request in flight. A notification
// during a read advances its node's revision, so that read cannot publish stale
// children; the queued replacement will use the latest disk state.
Expand Down Expand Up @@ -237,7 +242,7 @@ func (a *App) pumpTreeListings(p *project) {
return
}
t.reading = true
a.background(p, kernelCallTimeout, func(ctx context.Context) func(*App) {
a.background(p, treeListingTimeout, func(ctx context.Context) func(*App) {
listings, err := a.kernel.ListDirectories(ctx, p.root, paths)
return func(a *App) {
t.reading = false
Expand Down
83 changes: 83 additions & 0 deletions desktop/internal/workbench/filetree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,89 @@ type failingTreeListingKernel struct {
armed atomic.Bool
}

// nativeIOBudgetTreeKernel models an adapter that needs more than a pure computation's
// budget, without making the test wait for disk or a real timeout.
type nativeIOBudgetTreeKernel struct {
*testKernel
}

func (k *nativeIOBudgetTreeKernel) ListDirectories(ctx context.Context, root string, paths []string) ([]core.DirectoryListing, error) {
deadline, bounded := ctx.Deadline()
if !bounded || time.Until(deadline) < 3*time.Second || time.Until(deadline) > time.Minute {
return nil, context.DeadlineExceeded
}
return k.Client.ListDirectories(ctx, root, paths)
}

func TestProjectTreeDirectoryReadsAllowNativeIO(t *testing.T) {
root := t.TempDir()
if err := os.WriteFile(filepath.Join(root, "visible.txt"), nil, 0o600); err != nil {
t.Fatal(err)
}
h := newHarness(t, &nativeIOBudgetTreeKernel{testKernel: &testKernel{Client: core.NewClient()}})
h.open(root)
p := h.app.project
awaitDocumentState(t, h, func() bool { return !p.tree.reading })
if p.tree.failed != "" || p.tree.find("visible.txt") == nil {
t.Fatalf("directory I/O did not populate the project tree: %q", p.tree.failed)
}
}

type cancelledTreeListingKernel struct {
*testKernel
armed atomic.Bool
started chan struct{}
stopped chan struct{}
release chan struct{}
}

func (k *cancelledTreeListingKernel) ListDirectories(ctx context.Context, root string, paths []string) ([]core.DirectoryListing, error) {
if !k.armed.Load() {
return k.Client.ListDirectories(ctx, root, paths)
}
close(k.started)
defer close(k.stopped)
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-k.release:
return nil, context.Canceled
}
}

func TestProjectTreeDirectoryReadCancelsWhenProjectCloses(t *testing.T) {
kernel := &cancelledTreeListingKernel{
testKernel: &testKernel{Client: core.NewClient()},
started: make(chan struct{}),
stopped: make(chan struct{}),
release: make(chan struct{}),
}
h := newHarness(t, kernel)
t.Cleanup(func() { close(kernel.release) })
p := h.openTree(t, t.TempDir())
h.app.closeTree(p)
kernel.armed.Store(true)
h.app.listTree(p, "")
deadline := time.NewTimer(8 * time.Second)
defer deadline.Stop()
select {
case <-kernel.started:
case <-deadline.C:
t.Fatal("directory read did not start")
}
h.app.closeProject()
h.await("project close", func() bool { return h.app.project == nil })
select {
case <-kernel.stopped:
case <-deadline.C:
t.Fatal("closing the project did not cancel the directory read")
}
h.settle()
if h.app.project != nil {
t.Fatal("a closed project's listing restored the project")
}
}

func (k *failingTreeListingKernel) ListDirectories(ctx context.Context, root string, paths []string) ([]core.DirectoryListing, error) {
if k.armed.Load() {
return nil, errors.New("directory listing failed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
]
},
"owner": "Workspace",
"verification": "macOS 和 Windows 无头测试覆盖目录选择、展开、键盘、虚拟绘制、长文件名滚动、外部新增删除、空目录变化、超过 128 个目录、隐藏路径过滤、视口锚定、过期读取以及与搜索共享监听的关闭和重试;真实 Core 测试覆盖共享自然排序样例及 Python 隐藏路径。运行 scripts/desktop/desktop-go.sh test -race ./internal/workbench -run 'TestProjectTree|TestProjectSearch|TestEverywhere' -count=3 和 scripts/desktop/desktop-go.sh test -race ./internal/core -run TestWorkspaceDirectory -count=3。完整文件树和原生窗口行为仍待验收。 标题栏按钮:运行 scripts/desktop/desktop-go.sh test ./internal/workbench -run 'TestProjectTree(Locate|ExpandsAndCollapses|ExpandAll|Refresh)' -count=1 和 scripts/desktop/desktop-go.sh test ./internal/treelist -count=1;实机打开深层文件后折叠祖先,点击定位确认展开、选中并滚动到中间,键盘焦点在该行;在超过 512 个目录的项目中全部展开出现提示;删除并恢复项目根目录后点击刷新恢复树。 Unix 文件名里的反斜杠(2026-11-16,#2009,Lithe-core-rust #62):macOS 和 Linux 上 \\ 与 : 是文件名的一部分。Spring Boot 按 Windows 写法配置 logging.file.path: D:\\logs 后在项目里建出的 D:\\logs 目录,显示为根目录下的一个文件夹,展开后列出其中的文件,不再报 workspace.projectTree.rows 的“A project tree node is not in the folder above it”而让项目树为空;Windows 上 \\ 仍是分隔符,行为不变。运行 scripts/desktop/desktop-go.sh test ./internal/workbench -run TestProjectTreeShowsUnixNamesWithBackslashes -count=1(Windows 上跳过);原生窗口验收待做。",
"verification": "项目树磁盘与 Git 目录查询使用独立有界 I/O 限时;运行 TestProjectTreeDirectoryReadsAllowNativeIO 和 TestProjectTreeDirectoryReadCancelsWhenProjectCloses,验证超过纯计算限时仍可加载、关闭项目取消请求且旧结果不恢复项目。macOS 和 Windows 无头测试覆盖目录选择、展开、键盘、虚拟绘制、长文件名滚动、外部新增删除、空目录变化、超过 128 个目录、隐藏路径过滤、视口锚定、过期读取以及与搜索共享监听的关闭和重试;真实 Core 测试覆盖共享自然排序样例及 Python 隐藏路径。运行 scripts/desktop/desktop-go.sh test -race ./internal/workbench -run 'TestProjectTree|TestProjectSearch|TestEverywhere' -count=3 和 scripts/desktop/desktop-go.sh test -race ./internal/core -run TestWorkspaceDirectory -count=3。完整文件树和原生窗口行为仍待验收。 标题栏按钮:运行 scripts/desktop/desktop-go.sh test ./internal/workbench -run 'TestProjectTree(Locate|ExpandsAndCollapses|ExpandAll|Refresh)' -count=1 和 scripts/desktop/desktop-go.sh test ./internal/treelist -count=1;实机打开深层文件后折叠祖先,点击定位确认展开、选中并滚动到中间,键盘焦点在该行;在超过 512 个目录的项目中全部展开出现提示;删除并恢复项目根目录后点击刷新恢复树。 Unix 文件名里的反斜杠(2026-11-16,#2009,Lithe-core-rust #62):macOS 和 Linux 上 \\ 与 : 是文件名的一部分。Spring Boot 按 Windows 写法配置 logging.file.path: D:\\logs 后在项目里建出的 D:\\logs 目录,显示为根目录下的一个文件夹,展开后列出其中的文件,不再报 workspace.projectTree.rows 的“A project tree node is not in the folder above it”而让项目树为空;Windows 上 \\ 仍是分隔符,行为不变。运行 scripts/desktop/desktop-go.sh test ./internal/workbench -run TestProjectTreeShowsUnixNamesWithBackslashes -count=1(Windows 上跳过);原生窗口验收待做。",
"notes": "Viva 接入 Core 按需列目录、单选、方向键及虚拟绘制;项目根节点(包括空项目)可显示和选择,树行尺寸与展开图标参照旧版,批量列目录失败只记录一次宿主错误;新增根节点和失败日志回归仅在 macOS 验证,Windows 待重跑。2026-11-14 起可见行、选择修正、视口顶端行和多选由 Core 计算(workspace.projectTree.rows、workspace.rowSelection.reduce,#1800),树的形状变化时才调用,缩放和重绘不调用;Viva 日志生成与使用门禁跟踪 #1802。macOS 和 Windows 用一个项目级递归监听,供项目树和搜索共用,事件经 Core 过滤,重读保持节点及视口锚点。Linux 暂用最多 128 个按需目录监听,超限提示。多选、批量移动、上下文菜单、完整旧版增量行为与平台差异仍需迁移,macOS 和 Windows 原生窗口、逐像素对照及大项目性能均待验收。 Project 标题栏有定位当前文件、刷新、全部展开、全部折叠四个按钮:定位逐级列出并展开祖先目录后选中、居中并聚焦目标行,路径不可见时放弃并记录 operation_rejected;刷新重读已展开目录,根目录读取失败时重新监听并读取;全部展开按广度优先最多打开 512 个目录,超出时提示;全部折叠保留根目录,被隐藏的选择移到其所在的顶层目录。项目树是 Viva 的 ui.Tree(只声明可见行,RowWidth 使行等宽于最长名称以横向滚动),行尺寸与文字色取自 desktop/internal/treelist,Git Log 改动文件共用。方向键只移动焦点环,选中行跟随点击、Enter 与箭头,待 Viva 提供 TreeState.RowID 后改为跟随焦点。",
"legacy": {
"revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36",
Expand Down
Loading