diff --git a/.agents/notes/implemented/feature/2026-10-29-skip-python-environments-in-workspace-scans.md b/.agents/notes/archived/feature/2026-10-29-skip-python-environments-in-workspace-scans.md similarity index 91% rename from .agents/notes/implemented/feature/2026-10-29-skip-python-environments-in-workspace-scans.md rename to .agents/notes/archived/feature/2026-10-29-skip-python-environments-in-workspace-scans.md index 5ae63d7ae4..3e87a43168 100644 --- a/.agents/notes/implemented/feature/2026-10-29-skip-python-environments-in-workspace-scans.md +++ b/.agents/notes/archived/feature/2026-10-29-skip-python-environments-in-workspace-scans.md @@ -2,6 +2,10 @@ 状态:已实现 +归档日期:2026-11-16 + +> 2026-11-16 起(#1856,Lithe-core-rust #72)Core 不再内置 `.venv`、`venv`、`__pycache__`、`*.pyc` 等工具目录名,改由插件在清单里声明;当前决策见 [工具和生态的隐藏目录由插件声明](../../implemented/architecture/2026-11-16-plugin-declared-hidden-directories.md)。本文只保留历史取舍,文中的 `TestWorkspaceDirectoryAndSearchHidePythonEnvironments` 已删除。 + ## 先说结论 Rust Core 的默认工作区规则排除 `.venv`、`venv`、`__pycache__` 和 `*.pyc`。Viva 桌面端的项目树、工作区搜索和快照都经由 Core,所以这套默认规则对所有平台生效。规则按名字匹配,其他名称的虚拟环境不会因此自动识别。 diff --git a/.agents/notes/implemented/architecture/2026-10-17-build-system-plugin-contract.md b/.agents/notes/implemented/architecture/2026-10-17-build-system-plugin-contract.md index 29c2e56365..68cba56f97 100644 --- a/.agents/notes/implemented/architecture/2026-10-17-build-system-plugin-contract.md +++ b/.agents/notes/implemented/architecture/2026-10-17-build-system-plugin-contract.md @@ -4,6 +4,8 @@ > 2026-11-14 更新:下文第 8 节的 `hostIntegration: maven` 已不存在。Core #23 删除了 Maven 集成,`hostIntegration` 只剩保留字段,写任何值都以 `plugin.integration.unsupported` 拒绝;Core #28 起清单 schema 也删掉了 `model`、`test.results`、`dependencies` 里的 `source: "hostIntegration"`,这样写按未知来源以 `plugin.manifest.invalid` 拒绝。Maven 改由 [lithe-plugin-maven](https://github.com/Lithe-IDEA/lithe-plugin-maven) 用声明和 Provider 提供。下文保留当时的决策与理由。 +> 2026-11-16 更新:Core 不再按名字认识任何运行时(Lithe-core-rust #69,#1856 第 3 项)。`go`、`node` 和其他 ID 一样:没写 `executables` 的运行时按同 ID 的工具定义解析,Core 不再提供版本探测参数,也没有 `hostManaged` 字段;Java 早在 Core 去除 Java 依赖时就交给了插件。下文“运行时”一条和“只允许宿主管理的运行时”一节已按此改写。 + ## 先说结论 Lithe 现在用一套统一的构建模型描述所有项目级构建工具(Build Tool,例如 Maven、Gradle、Cargo、Go)。插件在 `plugin.json` 的 `buildSystems`(插件 API 级别 3)里用纯 JSON 声明:怎样认出工程、用哪个可执行文件、有哪些选项、任务、运行入口和测试,以及怎样读工具的输出。思路与 LSP 插件化相同:插件只提供数据,通用逻辑只在 Rust Core 实现一次。 @@ -107,7 +109,7 @@ Rust Core 负责校验声明、识别工程、展开每一条命令行,并把 - `environment`:某个环境变量下的相对路径,例如 `MAVEN_HOME` 下的 `bin/mvn`。变量必须列在 `environmentInputs` 里,宿主只传这些变量。 - `command`:在 `PATH` 上查找的裸命令名。 - `runtime`:直接使用一个声明的运行时,例如 Go fixture 直接用 `go`。 -- **运行时**:`java`、`node`、`go` 由宿主管理,只写 ID 和最低版本,按用户的运行时设置发现。Core 提供 Java 的 `-version`、Node 的 `--version`、Go 的 `version` 探测参数,宿主合并标准输出与错误输出再交回 Core 校验;Java 8 不支持 `--version`,且版本信息通常写到错误输出,不能据此误判为不可用。其他任何 ID 都由插件自己写可执行文件候选和版本探测,所以运行时列表是开放的。 +- **运行时**:Core 不按名字认识任何运行时。没写 `executables` 的运行时只写 ID 和最低版本,按同 ID 的工具定义解析(候选为 `{ "kind": "toolchain" }`),版本由工具定义检查;其余运行时由插件自己写可执行文件候选和版本探测,宿主合并标准输出与错误输出再交回 Core 校验。所以运行时列表是开放的。 - **自带逻辑**:插件附带的脚本(例如 Gradle 的 init script,即初始化脚本)可以直接输出规范格式,不必写选择器映射。规范格式有 `litheBuildModel`、`litheTestResults`、`litheDependencies`、`litheDiagnostics`。规范文档里的未知字段会被忽略,所以新脚本配旧宿主也能用。插件自带的常驻 Provider 进程也用这几种格式回复(第 9 节)。 固定词汇(要扩展就给对应能力加一个新版本,见[插件契约从统一基线 0 开始](2026-11-11-plugin-contract-single-baseline.md)): @@ -260,7 +262,7 @@ Gradle 的 `offline` 和 `userHome` 是用户自己选的值,不是猜测, ### 只允许宿主管理的运行时 -最有吸引力的地方:运行时发现全部由宿主掌控。不采用,因为这会把 .NET、Erlang、Dart 这类工具挡在外面。现在 `java`、`node`、`go` 由宿主管理,其余运行时由插件自己描述可执行文件和版本探测。 +最有吸引力的地方:运行时发现全部由宿主掌控。不采用,因为这会把 .NET、Erlang、Dart 这类工具挡在外面。现在没有宿主管理的运行时:运行时要么由插件描述可执行文件和版本探测,要么交给同 ID 的工具定义(2026-11-16 起 `go`、`node` 也一样)。 ## 后果 diff --git a/.agents/notes/implemented/architecture/2026-11-16-plugin-declared-hidden-directories.md b/.agents/notes/implemented/architecture/2026-11-16-plugin-declared-hidden-directories.md new file mode 100644 index 0000000000..a8477dc865 --- /dev/null +++ b/.agents/notes/implemented/architecture/2026-11-16-plugin-declared-hidden-directories.md @@ -0,0 +1,80 @@ +# Agent 笔记:工具和生态的隐藏目录由插件声明 + +状态:已实现 + +## 先说结论 + +Core 自己只隐藏 `.git`、`.worktree`、`.worktrees` 三个目录,以及 `.DS_Store` 和 `.lithe`。构建产物、依赖、缓存和虚拟环境目录(`target`、`build`、`node_modules`、`.venv` 等)属于具体工具的知识,由提供该工具的插件在清单里声明。宿主读取插件语言时,把已启用插件的清单交给 Core 的 `workspace.configureVisibility`;Core 按这份名单统一决定项目树、搜索、文件事件、本地历史、运行发现、构建探测和仓库发现跳过哪些目录。日常开发时,要隐藏一个新生态的目录,就去改它的插件,不改 Core 也不改宿主。 + +## 问题 + +- Core 里原来有 4 份各自维护的目录名单:可见性规则的 `BUILT_IN_HIDDEN_DIRECTORIES`、本地历史的 `BUILT_IN_IGNORED_DIRECTORY_NAMES`、VCS 根目录探测的 `PRUNED`,以及运行扫描的名单。桌面端的文件图标又写死了一份(`target`、`build`、`out`、`bin`、`dist`、`node_modules`、`.idea`)。同一个目录要不要跳过,在不同入口可能得到不同答案。 +- 这些名字是 Cargo、Gradle、npm、Python 等工具的约定。Core 不允许对任何语言或工具做特判(Issue #1856),每支持一个新生态就要改 Core,也违背“工具内容由插件注入”的边界。 +- 隐藏这些目录本身仍然必要:一个 Python 项目的虚拟环境和 `__pycache__` 就有约 3.2 万个文件,扫进来会拖慢快照、搜索和索引。问题不在“要不要隐藏”,而在“谁来说出名字”。 + +## 决策 + +### 正确做法 + +- 构建系统插件在 `buildSystems[].layout.hiddenDirectoryNames` 里列出要隐藏的目录名,例如 Cargo 插件写 `target`。VCS 提供者的目录标记(例如 `.svn`)本身就是元数据目录,插件启用期间同样隐藏。名称规则(单个路径片段、不区分 ASCII 大小写、不是通配符、最多 32 个)以 Core 的[插件契约 README](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/contract/v1/README.md) 为准。 +- 宿主在 `desktop/internal/workbench/hidden_directories.go` 里把已启用的构建系统插件和 VCS 插件的清单交给 Core,每个插件只发一次。发送时机和插件语言重读相同:工作台启动时,以及安装、启用、禁用、卸载插件之后。 +- Core 为整个进程保存一份名单,每次调用整份替换。名单变化后,宿主让每个打开的标签页重读已展开的目录;名单没变就什么都不做,所以一次插件变化里,后面几个标签页的调用不会重复刷新。 +- 文件图标的“排除目录”样式也只认这份名单(`fileicons.SetHiddenDirectoryNames`),不再自己写死名字。 +- 过滤放在 Core 里做,所有入口共用一份判断。 + +正确做法的小例子: + +```text +Cargo 插件清单:buildSystems[0].layout.hiddenDirectoryNames = ["target"] +→ 宿主重读插件语言时发给 Core +→ 项目树、搜索、本地历史、仓库发现都跳过任意层级的 target/ +``` + +### 不要这样做 + +- 不要把 `target`、`node_modules`、`.venv` 之类的名字加回 Core 或宿主的任何名单,也不要在宿主里按插件 ID 写分支。 +- 不要只在界面上过滤结果。目录已经被读完、序列化、传给界面之后再丢掉,扫描和内存的代价都已经付出了。 +- 不要默认按 `.gitignore` 隐藏目录,原因见下面的备选方案。 + +## 考虑过的备选方案 + +### 在 Core 保留一份“中立”的默认名单 + +好处是没有安装插件的生态也能隐藏常见目录。没有采用的原因:`target`、`build`、`node_modules` 本身就是工具知识,换个名字叫“中立默认值”并不改变 Core 了解具体工具的事实。用户的决定是这些目录本来就该由插件探测和声明,没有对应插件的生态失去默认隐藏是可以接受的代价。 + +### 每次请求时由宿主带上目录名 + +好处是 Core 不用保存状态。没有采用的原因:项目树、搜索、文件事件、本地历史、运行发现、构建探测、仓库发现都会读目录,每个调用点都要记得带上名单,漏掉一个就会出现两个入口结论不同。插件启用状态本来就是整个应用共用的,在 Core 里存一份进程级名单更不容易出错。 + +### 读取 `.gitignore` 来决定隐藏什么 + +好处是项目自己声明的忽略项都能覆盖。没有采用的原因:非 Git 项目和没写 `.gitignore` 的项目不受益;嵌套 `.gitignore`、`!` 否定规则和全局忽略文件都要单独求值;被 Git 忽略但仍想搜索的文件(例如本地配置)会搜不到。IntelliJ 也不自动排除,只在用户编辑忽略文件时提示是否标记为排除(`IgnoredToExcludedSynchronizer`)。 + +### 像 IntelliJ 那样把依赖目录登记为“库根” + +IntelliJ 把 `.venv` 登记成外部库,保留补全和跳转,但不算项目内容。没有采用的原因:库根在 IntelliJ 里仍然会被索引,性能上不省。Lithe 的语言事实由语言服务器负责,Core 不应该再为依赖库维护第二份索引。 + +## 后果 + +- 收益:Core 和宿主里不再有任何工具目录名;新生态只改自己的插件;所有读目录的入口共用一份名单,结论一致。 +- 代价:没有对应插件,或插件还没发布 `hiddenDirectoryNames` 的生态,`target`、`build`、`node_modules`、`.venv` 等目录会重新出现在项目树里,也会被搜索和本地历史记录。Cargo、Gradle、Maven 插件需要在包含本次接入的桌面端版本发布之后再发布声明。 +- 代价:本地历史设置列出的默认规则现在全部是隐藏目录。Viva 桌面端没有“隐藏路径”设置,这些目录始终隐藏,所以删掉其中一行也不会开始记录;设置页的说明已经写明这一点。 +- 代价:名单是进程级的。两次插件重读如果几乎同时完成,后到的结果会覆盖先到的结果;下一次重读会纠正,目前没有观察到实际影响。 +- 需要重新评估的触发条件:需要按目录内容(例如 `pyvenv.cfg`)而不是名字识别目录,或者桌面端要提供“隐藏路径”设置让用户放开默认隐藏目录时。 + +## 验证 + +- `scripts/desktop/desktop-go.sh test ./internal/core -run TestWorkspaceVisibility -count=1`:真实 Core 隐藏插件声明的目录(任意层级、不区分大小写),被拒的清单不生效,清空后目录重新出现。 +- `scripts/desktop/desktop-go.sh test ./internal/workbench -run 'TestPluginDeclaredFolders|TestHiddenFolders|TestLocalHistorySettingsReachCore' -count=1`:启用插件后项目树隐藏声明的目录,禁用后重新显示;名单变化才重读目录;每个打开的标签页都生效;本地历史的默认规则包含插件声明的目录。 +- `scripts/desktop/desktop-go.sh test ./internal/fileicons -count=1`:排除目录图标只认当前名单。 +- 本地历史默认规则的 ⓘ 说明截图和复验命令见 `docs/assets/hidden-directories/README.md`。 + +## 适用范围 + +- `desktop/internal/workbench/hidden_directories.go` +- `desktop/internal/workbench/plugins.go` +- `desktop/internal/core/workspace_visibility.go` +- `desktop/internal/fileicons/fileicons.go` +- `desktop/internal/settingswindow/local_history_view.go` +- Core 实现:[Lithe-core-rust #72](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/72) +- 本文取代已归档的“工作区扫描默认跳过 Python 环境和字节码”(2026-10-29),其中仍有价值的理由已并入上文。 diff --git a/.agents/notes/implemented/bug-fix/2026-10-04-git-repository-discovery-and-selection.md b/.agents/notes/implemented/bug-fix/2026-10-04-git-repository-discovery-and-selection.md index 6e786f6dc5..06ce87a194 100644 --- a/.agents/notes/implemented/bug-fix/2026-10-04-git-repository-discovery-and-selection.md +++ b/.agents/notes/implemented/bug-fix/2026-10-04-git-repository-discovery-and-selection.md @@ -5,7 +5,7 @@ ## 先说结论 工作区的 Git 列表不应自动纳入 `.build/checkouts` 等缓存中的依赖仓库。 -自动发现默认跳过隐藏目录和内置构建目录,但保留工作树容器及用户显式打开的目录。 +自动发现默认跳过隐藏目录和默认隐藏目录(Core 自己的,加上已启用插件声明的构建、缓存目录),但保留工作树容器及用户显式打开的目录。 切换仓库时,历史请求、分支选择和提交选择必须一起切换,不能把旧仓库的引用传给新仓库。 ## 问题 @@ -19,8 +19,10 @@ Issue #1064 中,文件树已经隐藏 `.build`,Git 却列出了 SwiftTerm、 ## 决策 -- Rust Core 在进入子目录前排除以点开头的目录,并复用文件树已有的内置隐藏目录清单, - 避免 `.build`、`node_modules`、`target` 等规则在两端各维护一份。 +- Rust Core 在进入子目录前排除以点开头的目录,并复用文件树的默认隐藏目录名单, + 避免同一份规则在两处各维护一份。2026-11-16 起这份名单只含 Core 自己的目录和已启用插件声明的目录, + `node_modules`、`target` 等名称由对应插件声明,见 + [工具和生态的隐藏目录由插件声明](../architecture/2026-11-16-plugin-declared-hidden-directories.md)。 - `.worktree` 和 `.worktrees` 是显式保留的工作树容器;继续识别目录或文件形式的 `.git`, 并在容器内部照常跳过构建目录。这里只决定扫描范围,不根据目录名判断是否真是链接工作树。 - 过滤仅作用于递归子目录。直接打开 `.build/checkouts/SwiftTerm` 时仍然管理这个仓库; diff --git a/desktop/internal/core/build.go b/desktop/internal/core/build.go index ab307562b0..f2d2f255e2 100644 --- a/desktop/internal/core/build.go +++ b/desktop/internal/core/build.go @@ -73,7 +73,6 @@ type BuildRuntimeRequirement struct { PathVariable string `json:"pathVariable,omitempty"` ID string `json:"id"` DisplayName string `json:"displayName"` - HostManaged bool `json:"hostManaged"` MinimumVersion string `json:"minimumVersion,omitempty"` Executables []BuildExecutableCandidate `json:"executables"` Version *BuildVersionProbe `json:"version,omitempty"` diff --git a/desktop/internal/core/repository_discovery_test.go b/desktop/internal/core/repository_discovery_test.go index 37a474748e..772f714dcd 100644 --- a/desktop/internal/core/repository_discovery_test.go +++ b/desktop/internal/core/repository_discovery_test.go @@ -58,6 +58,7 @@ func TestWorkspaceRepositorySelectionUsesCoreFixtures(t *testing.T) { Request struct { Repositories []WorkspaceRepository `json:"repositories"` Selected string `json:"selected"` + Chosen []string `json:"chosen"` } `json:"request"` Response struct { Active *string `json:"active"` @@ -73,7 +74,14 @@ func TestWorkspaceRepositorySelectionUsesCoreFixtures(t *testing.T) { t.Fatal("the selection fixture has no cases") } client := NewClient() + checked := 0 for _, item := range fixture.Cases { + if item.Request.Chosen != nil { + // A view acting on several repositories at once sends chosen instead of selected; + // the bridge does not, until the Git Log takes several repositories (#2013). + continue + } + checked++ t.Run(item.Name, func(t *testing.T) { want := WorkspaceRepositorySelection{FellBack: item.Response.FellBack, Others: item.Response.Others} if item.Response.Active != nil { @@ -85,6 +93,9 @@ func TestWorkspaceRepositorySelectionUsesCoreFixtures(t *testing.T) { } }) } + if checked == 0 { + t.Fatal("the selection fixture has no case with selected") + } duplicate := []WorkspaceRepository{ {Path: "/w/a", ID: "a", Name: "a", Role: RepositoryNested}, {Path: "/w/b", ID: "a", Name: "a", Role: RepositoryNested}, diff --git a/desktop/internal/core/workspace_search_test.go b/desktop/internal/core/workspace_search_test.go index 7e2cee54ba..1187af1998 100644 --- a/desktop/internal/core/workspace_search_test.go +++ b/desktop/internal/core/workspace_search_test.go @@ -32,7 +32,7 @@ func TestWorkspaceSearchUsesCoreOptionsAndRefreshesChanges(t *testing.T) { if err := os.WriteFile(path, []byte("new external value\n"), 0600); err != nil { t.Fatal(err) } - filtered, err := client.FilterWorkspaceChanges(ctx, []string{"node_modules/ignored.js", "example.go"}) + filtered, err := client.FilterWorkspaceChanges(ctx, []string{".worktrees/copy/ignored.js", "example.go"}) if err != nil || len(filtered) != 1 || filtered[0] != "example.go" { t.Fatalf("filtered changes = %v, %v", filtered, err) } diff --git a/desktop/internal/core/workspace_tree_test.go b/desktop/internal/core/workspace_tree_test.go index a6e71191bf..4195c9777f 100644 --- a/desktop/internal/core/workspace_tree_test.go +++ b/desktop/internal/core/workspace_tree_test.go @@ -61,30 +61,3 @@ func TestWorkspaceDirectoryTreeUsesCoreNaturalOrder(t *testing.T) { t.Fatalf("directory order = %v, want %v", got, want) } } - -func TestWorkspaceDirectoryAndSearchHidePythonEnvironments(t *testing.T) { - root := t.TempDir() - for _, dir := range []string{".venv", "venv", "__pycache__"} { - if err := os.Mkdir(filepath.Join(root, dir), 0o700); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(root, dir, "hidden.py"), []byte("distinctive needle"), 0o600); err != nil { - t.Fatal(err) - } - } - for _, name := range []string{"main.py", "compiled.pyc"} { - if err := os.WriteFile(filepath.Join(root, name), []byte("distinctive needle"), 0o600); err != nil { - t.Fatal(err) - } - } - client := NewClient() - ctx := testContext(t) - listings, err := client.ListDirectories(ctx, root, []string{""}) - if err != nil || len(listings) != 1 || len(listings[0].Children) != 1 || listings[0].Children[0].Name != "main.py" { - t.Fatalf("visible directory entries = %+v, error = %v", listings, err) - } - matches, err := client.SearchWorkspace(ctx, WorkspaceSearchRequest{Root: root, Query: "distinctive needle", MaxResults: 20}) - if err != nil || len(matches) != 1 || matches[0].Path != "main.py" { - t.Fatalf("search matches = %+v, error = %v", matches, err) - } -} diff --git a/desktop/internal/core/workspace_visibility.go b/desktop/internal/core/workspace_visibility.go new file mode 100644 index 0000000000..80b2b724ec --- /dev/null +++ b/desktop/internal/core/workspace_visibility.go @@ -0,0 +1,39 @@ +package core + +import ( + "context" + "encoding/json" +) + +// VisibilityConfiguration is Core's answer to workspace.configureVisibility. +type VisibilityConfiguration struct { + // HiddenDirectoryNames are the folder names the enabled plugins hide in every workspace, + // at any depth: their build systems' dependency, cache and output folders and their VCS + // metadata folders. Core sorts them and drops duplicates; its own folders, such as .git, + // are not among them. + HiddenDirectoryNames []string `json:"hiddenDirectoryNames"` + // Rejected are the manifests Core could not validate, by their index in the request, in the + // form build.detect reports them. Such a manifest hides nothing. + Rejected []BuildDetectionRejection `json:"rejected"` +} + +// ConfigureVisibility replaces the folder names the enabled plugins hide with those that +// manifests, the manifests of every enabled plugin, declare. The list is Core's for the whole +// process: every tree listing, search, file event and history check made after the call obeys +// it, in every workspace. An empty list leaves only Core's own folders hidden. +func (c *Client) ConfigureVisibility(ctx context.Context, manifests []json.RawMessage) (VisibilityConfiguration, error) { + type plugin struct { + Manifest json.RawMessage `json:"manifest"` + } + plugins := make([]plugin, 0, len(manifests)) + for _, manifest := range manifests { + plugins = append(plugins, plugin{Manifest: manifest}) + } + var result VisibilityConfiguration + if err := c.Execute(ctx, "workspace.configureVisibility", struct { + Plugins []plugin `json:"plugins"` + }{plugins}, &result); err != nil { + return VisibilityConfiguration{}, err + } + return result, nil +} diff --git a/desktop/internal/core/workspace_visibility_test.go b/desktop/internal/core/workspace_visibility_test.go new file mode 100644 index 0000000000..51355e3af8 --- /dev/null +++ b/desktop/internal/core/workspace_visibility_test.go @@ -0,0 +1,124 @@ +package core + +import ( + "context" + "encoding/json" + "os" + "path/filepath" + "reflect" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/contractfixture" +) + +// declaredFoldersManifest is the contract's static build system fixture under the fictional +// plugin id, its layout hiding the folders named names. +func declaredFoldersManifest(t *testing.T, id string, names ...string) json.RawMessage { + t.Helper() + raw, err := os.ReadFile(contractfixture.Path("fixtures/build-systems/build-static-file.plugin.json")) + if err != nil { + t.Fatal(err) + } + var manifest map[string]any + if err := json.Unmarshal(raw, &manifest); err != nil { + t.Fatal(err) + } + manifest["id"] = id + systems, _ := manifest["buildSystems"].([]any) + if len(systems) == 0 { + t.Fatal("the build system fixture declares no build system") + } + system := systems[0].(map[string]any) + layout, _ := system["layout"].(map[string]any) + if layout == nil { + layout = map[string]any{} + } + layout["hiddenDirectoryNames"] = names + system["layout"] = layout + encoded, err := json.Marshal(manifest) + if err != nil { + t.Fatal(err) + } + return encoded +} + +// childNames lists the names in the folder at path of root, in Core's order. +func childNames(t *testing.T, client *Client, ctx context.Context, root, path string) []string { + t.Helper() + listings, err := client.ListDirectories(ctx, root, []string{path}) + if err != nil || len(listings) != 1 { + t.Fatalf("listing %q = %+v, %v", path, listings, err) + } + names := []string{} + for _, child := range listings[0].Children { + names = append(names, child.Name) + } + return names +} + +// matchPaths is the files a search for the needle finds in root. +func matchPaths(t *testing.T, client *Client, ctx context.Context, root string) []string { + t.Helper() + matches, err := client.SearchWorkspace(ctx, WorkspaceSearchRequest{Root: root, Query: "distinctive needle", MaxResults: 20}) + if err != nil { + t.Fatal(err) + } + paths := []string{} + for _, match := range matches { + paths = append(paths, match.Path) + } + return paths +} + +// Core hides its own folders, such as .worktrees, by itself, and the folders an enabled +// plugin's build system names at any depth and in any ASCII case once it is handed the +// manifest. A manifest it rejects hides nothing, and an empty call shows the folders again. +func TestWorkspaceVisibilityHidesTheFoldersPluginsDeclare(t *testing.T) { + root := t.TempDir() + for _, dir := range []string{"fixture-out", "nested/Fixture-Out", ".worktrees", "src"} { + if err := os.MkdirAll(filepath.Join(root, dir), 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(root, dir, "hidden.txt"), []byte("distinctive needle"), 0o600); err != nil { + t.Fatal(err) + } + } + client := NewClient() + ctx := testContext(t) + t.Cleanup(func() { + if _, err := client.ConfigureVisibility(context.Background(), nil); err != nil { + t.Errorf("clearing the hidden folders: %v", err) + } + }) + + configuration, err := client.ConfigureVisibility(ctx, []json.RawMessage{ + declaredFoldersManifest(t, "dev.lithe.test.declared-folders", "fixture-out"), + declaredFoldersManifest(t, "dev.lithe.test.invalid-folder-name", "fixture/out"), + }) + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(configuration.HiddenDirectoryNames, []string{"fixture-out"}) || len(configuration.Rejected) != 1 || configuration.Rejected[0].Index != 1 { + t.Fatalf("configureVisibility = %+v", configuration) + } + if got := childNames(t, client, ctx, root, ""); !reflect.DeepEqual(got, []string{"nested", "src"}) { + t.Fatalf("root entries = %v", got) + } + if got := childNames(t, client, ctx, root, "nested"); len(got) != 0 { + t.Fatalf("nested entries = %v, want the declared folder hidden", got) + } + if got := matchPaths(t, client, ctx, root); !reflect.DeepEqual(got, []string{"src/hidden.txt"}) { + t.Fatalf("search matches = %v", got) + } + + cleared, err := client.ConfigureVisibility(ctx, nil) + if err != nil || len(cleared.HiddenDirectoryNames) != 0 || len(cleared.Rejected) != 0 { + t.Fatalf("clearing = %+v, %v", cleared, err) + } + if got := childNames(t, client, ctx, root, ""); !reflect.DeepEqual(got, []string{"fixture-out", "nested", "src"}) { + t.Fatalf("root entries after clearing = %v", got) + } + if got := matchPaths(t, client, ctx, root); len(got) != 3 { + t.Fatalf("search matches after clearing = %v, want the three visible files", got) + } +} diff --git a/desktop/internal/fileicons/fileicons.go b/desktop/internal/fileicons/fileicons.go index 4ac7bcc109..7271f105e5 100644 --- a/desktop/internal/fileicons/fileicons.go +++ b/desktop/internal/fileicons/fileicons.go @@ -5,7 +5,9 @@ package fileicons import ( + "slices" "strings" + "sync/atomic" "unicode" "github.com/vivaui/viva/gfx" @@ -392,10 +394,50 @@ func directoryKind(name string) kind { return directoryKindInSourceRoot(name, false) } +// hiddenDirectoryNames are the names SetHiddenDirectoryNames last set, ASCII lower case, sorted. +var hiddenDirectoryNames atomic.Pointer[[]string] + +// SetHiddenDirectoryNames sets the folder names whose folders take the excluded-folder icon at +// any depth: the names Core hides by default because an enabled plugin declares them, which a +// tree lists only where the user turned the default off. Names match ignoring ASCII case, as +// Core compares them. It reports whether the names differ from the ones set before. +func SetHiddenDirectoryNames(names []string) bool { + lowered := make([]string, 0, len(names)) + for _, name := range names { + lowered = append(lowered, lowerASCII(name)) + } + slices.Sort(lowered) + lowered = slices.Compact(lowered) + var before []string + if previous := hiddenDirectoryNames.Swap(&lowered); previous != nil { + before = *previous + } + return !slices.Equal(before, lowered) +} + +// isHiddenDirectoryName reports whether name is one of the names SetHiddenDirectoryNames set. +func isHiddenDirectoryName(name string) bool { + names := hiddenDirectoryNames.Load() + if names == nil { + return false + } + _, found := slices.BinarySearch(*names, lowerASCII(name)) + return found +} + +// lowerASCII lowers the ASCII letters of name only, leaving other runes as they are. +func lowerASCII(name string) string { + return strings.Map(func(r rune) rune { + if 'A' <= r && r <= 'Z' { + return r + 'a' - 'A' + } + return r + }, name) +} + // directoryKindInSourceRoot checks exclusions before considering package names inside source roots. func directoryKindInSourceRoot(name string, insideSourceRoot bool) kind { - switch strings.ToLower(name) { - case "target", "build", "out", "bin", "dist", "node_modules", ".idea": + if isHiddenDirectoryName(name) { return kindExcludedFolder } if insideSourceRoot && IsPackageSegmentName(name) { diff --git a/desktop/internal/fileicons/fileicons_test.go b/desktop/internal/fileicons/fileicons_test.go index 017c778e6e..51099ad014 100644 --- a/desktop/internal/fileicons/fileicons_test.go +++ b/desktop/internal/fileicons/fileicons_test.go @@ -60,15 +60,26 @@ func TestFileKind(t *testing.T) { } } -// TestDirectoryKind covers excluded directory names and regular directories. +// useHiddenDirectoryNames sets names for one test and clears them after it. +func useHiddenDirectoryNames(t *testing.T, names ...string) { + t.Helper() + SetHiddenDirectoryNames(names) + t.Cleanup(func() { SetHiddenDirectoryNames(nil) }) +} + +// TestDirectoryKind covers the configured hidden folder names, matched ignoring ASCII case, +// and regular directories, which no built-in name list turns into excluded folders. func TestDirectoryKind(t *testing.T) { + useHiddenDirectoryNames(t, "fixture-out", ".Fixture-Cache") tests := []struct { name string want kind }{ - {"node_modules", kindExcludedFolder}, - {"Target", kindExcludedFolder}, - {".idea", kindExcludedFolder}, + {"fixture-out", kindExcludedFolder}, + {"Fixture-Out", kindExcludedFolder}, + {".fixture-cache", kindExcludedFolder}, + {"target", kindFolder}, + {"node_modules", kindFolder}, {"src", kindFolder}, {"META-INF", kindFolder}, } @@ -82,6 +93,30 @@ func TestDirectoryKind(t *testing.T) { } } +// TestSetHiddenDirectoryNamesReportsChanges covers the change report the workbench re-lists its +// trees on: the same names in another order, case or with repeats are no change, while new names +// and clearing them are. +func TestSetHiddenDirectoryNamesReportsChanges(t *testing.T) { + SetHiddenDirectoryNames(nil) + t.Cleanup(func() { SetHiddenDirectoryNames(nil) }) + steps := []struct { + names []string + changed bool + }{ + {nil, false}, + {[]string{}, false}, + {[]string{"fixture-out", ".fixture-cache"}, true}, + {[]string{".Fixture-Cache", "FIXTURE-OUT", "fixture-out"}, false}, + {[]string{"fixture-out"}, true}, + {nil, true}, + } + for index, step := range steps { + if got := SetHiddenDirectoryNames(step.names); got != step.changed { + t.Fatalf("step %d: SetHiddenDirectoryNames(%q) = %v, want %v", index, step.names, got, step.changed) + } + } +} + // TestSplitExt covers basename extensions and dotfile boundaries. func TestSplitExt(t *testing.T) { tests := []struct { @@ -179,6 +214,7 @@ func TestForDirectoryMark(t *testing.T) { } func TestForSourceDirectory(t *testing.T) { + useHiddenDirectoryNames(t, "fixture-out") cases := []struct { label string directory string @@ -194,8 +230,8 @@ func TestForSourceDirectory(t *testing.T) { {"my-lib", "my-lib", &Folder, &FolderDark}, {"a.b", "a.b", &Folder, &FolderDark}, {"empty", "", &Folder, &FolderDark}, - {"build", "build", &ExcludeRoot, &ExcludeRootDark}, - {"target", "target", &ExcludeRoot, &ExcludeRootDark}, + {"hidden", "fixture-out", &ExcludeRoot, &ExcludeRootDark}, + {"target", "target", &Package, &PackageDark}, } for _, test := range cases { t.Run(test.label, func(t *testing.T) { diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index f5ff62433e..23dccd39ab 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1400,7 +1400,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.settings.fontsSystemDefault": "System Default", "desktop.settings.languageHelp": "The language of menus, buttons and messages", "desktop.settings.layoutHint": "Drag the buttons on the stripes, title bar and status bar to rearrange them", - "desktop.settings.localHistory.builtInsHelp": "Built-in rules are listed here too. Delete one to keep that folder out of local history after Apply; it then shows as a \"!\" line, and deleting that line turns the rule back on.", + "desktop.settings.localHistory.builtInsHelp": "Folders hidden from the project tree are listed here too: Lithe's own, such as `**/.git/`, and those enabled plugins declare, such as a build's output folder. Files in a hidden folder are never recorded, even after you delete its line. A deleted line shows as a \"!\" line after Apply; delete that line to restore the rule.", "desktop.settings.localHistory.help": "Local history keeps versions of a project's files as you save and edit them, in Lithe's own data folder. Ignore rules only keep files out of local history; the project tree still shows them.", "desktop.settings.localHistory.invalidLimit": "Enter the limit as a whole number of megabytes, 1 or more, or leave it empty for the default.", "desktop.settings.localHistory.regexHelp": "One per line, case-insensitive, matched anywhere in the project-relative path with `/` separators, for example `^build/` or `(test|spec)/`.", @@ -4136,7 +4136,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.settings.fontsSystemDefault": "系统默认", "desktop.settings.languageHelp": "菜单、按钮和提示使用的语言", "desktop.settings.layoutHint": "拖动侧栏、标题栏和状态栏里的按钮可以调整位置", - "desktop.settings.localHistory.builtInsHelp": "内置规则也列在这里。删除其中一行,应用后该目录不再记入本地历史,并以 `!` 开头的行显示;删除这行 `!` 行即可重新开启该规则。", + "desktop.settings.localHistory.builtInsHelp": "项目树中隐藏的目录也列在这里:Lithe 自己的目录(例如 `**/.git/`),以及已启用插件声明的目录(例如构建输出目录)。隐藏目录里的文件始终不记入本地历史,删掉对应的行也一样。删掉的行在应用后显示为以“!”开头的行;删除这一行即可恢复该规则。", "desktop.settings.localHistory.help": "本地历史在你保存和编辑项目文件时保留各个版本,存放在 Lithe 自己的数据目录中。忽略规则只让文件不进入本地历史,项目树仍然显示它们。", "desktop.settings.localHistory.invalidLimit": "上限请填写不小于 1 的整数(单位 MB),留空则使用默认值。", "desktop.settings.localHistory.regexHelp": "每行一条,不区分大小写,在以 `/` 分隔的项目内相对路径中任意位置匹配,例如 `^build/` 或 `(test|spec)/`。", diff --git a/desktop/internal/settingswindow/local_history_view.go b/desktop/internal/settingswindow/local_history_view.go index 8b1df5aa57..592811efde 100644 --- a/desktop/internal/settingswindow/local_history_view.go +++ b/desktop/internal/settingswindow/local_history_view.go @@ -111,7 +111,8 @@ type localHistoryDraft struct { confirmClear, wantedUsage bool // regexMode shows the regular expression list instead of the wildcard list. regexMode bool - // builtIns are Core's built-in wildcard rules as the last preview reported them. shown are + // builtIns are Core's default wildcard rules as the last preview reported them: a rule for + // each folder hidden from the tree, Core's own and those the enabled plugins declare. shown are // the ones the wildcard list displays, and loadedPatterns the text it was loaded with: a // list nobody has edited yet picks up the built-in rules when they first arrive. builtIns, shown []string diff --git a/desktop/internal/settingswindow/visual_capture_test.go b/desktop/internal/settingswindow/visual_capture_test.go index 00b0be27d9..8033a70f7e 100644 --- a/desktop/internal/settingswindow/visual_capture_test.go +++ b/desktop/internal/settingswindow/visual_capture_test.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "testing" + "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" @@ -47,7 +48,7 @@ func TestVisualSettings(t *testing.T) { {"29-marketplace-empty", pagePlugins}, {"31-settings-updates", pageUpdates}, {"33-settings-toolchains", pageBuild}, {"m44-toolchain-directory-menu", pageBuild}, {"m45-toolchain-custom-directory", pageBuild}, {"fonts", pageFonts}, - {"21-settings-language-popup", pageGeneral}, {"30-settings-history", pageGeneral}, {"35-settings-search", pageEditor}, + {"21-settings-language-popup", pageGeneral}, {"30-settings-history", pageGeneral}, {"m46-history-default-rules-help", pageGeneral}, {"35-settings-search", pageEditor}, {"m35-editor-tab-layout", pageEditor}, {"m25-project-open-mode", pageGeneral}, {"m29-editor-font-menu", pageFonts}, {"m38-plugin-management-menu", pagePlugins}, {"m39-proxy-mode-menu", pageNetwork}, {"m40-process-run-policy", pageProcessTermination}, {"m41-process-terminal-policy", pageProcessTermination}, {"m43-process-orphan-policy", pageProcessTermination}, @@ -113,6 +114,30 @@ func TestVisualSettings(t *testing.T) { if err := d.driver.Scroll(gfx.ScrollEvent{X: 700, Y: 500, DeltaY: 500, Viewport: gfx.Size{Width: 900, Height: 700}}); err != nil { t.Fatal(err) } + case "m46-history-default-rules-help": + // The ⓘ on the wildcard list's row explains the default rules: the folders + // hidden from the tree, which deleting a line does not record. + if err := d.driver.Scroll(gfx.ScrollEvent{X: 700, Y: 500, DeltaY: 500, Viewport: gfx.Size{Width: 900, Height: 700}}); err != nil { + t.Fatal(err) + } + d.pump() + help := text("desktop.settings.localHistory.wildcardHelp") + " " + text("desktop.settings.localHistory.builtInsHelp") + info := d.hintHit(help).Bounds + x, y := info.X+info.Width/2, info.Y+info.Height/2 + if err := d.driver.Move(x, y); err != nil { + t.Fatal(err) + } + if err := d.driver.Click(x, y); err != nil { + t.Fatal(err) + } + d.pump() + if !d.showsHelp(help) { + t.Fatal("the ⓘ did not pin its help open") + } + // The popover fades in; move the frame clock past it. + if err := session.Advance(time.Second); err != nil { + t.Fatal(err) + } case "35-settings-search": query := "编辑器" if language == i18n.English { diff --git a/desktop/internal/workbench/build.go b/desktop/internal/workbench/build.go index 8036ecf0b1..6054d5819d 100644 --- a/desktop/internal/workbench/build.go +++ b/desktop/internal/workbench/build.go @@ -1169,21 +1169,10 @@ func (a *App) resolveBuildCandidates(ctx context.Context, p *project, directory execution.Executable = path } case "runtime": + // The tool runs on one of its declared runtimes, all resolved before the tool's + // own candidates; Core rejects a runtime that names another runtime. if resolved, ok := runtimes[candidate.Runtime]; ok { execution = resolved - break - } - selection, selectErr := a.resolveToolchainSelection(ctx, p.root, directory, candidate.Runtime, minimum) - if selectErr == nil { - execution = buildExecution{Executable: selection.Executable, Environment: selection.Environment, PathPrepend: selection.PathPrepend} - break - } - var unavailable *toolchain.UnavailableError - if !errors.As(selectErr, &unavailable) || unavailable.Code != "definitionUnavailable" { - return buildExecution{}, selectErr - } - if path, lookupErr := exec.LookPath(candidate.Runtime); lookupErr == nil { - execution.Executable = path } case "toolchain": selection, selectErr := a.resolveToolchainSelection(ctx, p.root, directory, candidate.ToolchainID, minimum) diff --git a/desktop/internal/workbench/filetree_test.go b/desktop/internal/workbench/filetree_test.go index 6d92b4ba2d..dde448c2cc 100644 --- a/desktop/internal/workbench/filetree_test.go +++ b/desktop/internal/workbench/filetree_test.go @@ -260,7 +260,7 @@ func TestProjectTreeUsesCoreToFilterHiddenEvents(t *testing.T) { p.tree.recursiveWatch = true p.search.watch = &documentWatch{} before := k.listings.Load() - h.app.applyTreeRecursiveWatch(p, false, true, nil, app.DirectoryChanges{Names: []string{"node_modules/tool/generated.js"}}) + h.app.applyTreeRecursiveWatch(p, false, true, nil, app.DirectoryChanges{Names: []string{".worktrees/copy/generated.js"}}) select { case <-k.filtered: case <-time.After(8 * time.Second): diff --git a/desktop/internal/workbench/hidden_directories.go b/desktop/internal/workbench/hidden_directories.go new file mode 100644 index 0000000000..ea5bdfcc4c --- /dev/null +++ b/desktop/internal/workbench/hidden_directories.go @@ -0,0 +1,93 @@ +package workbench + +import ( + "context" + "encoding/json" + "errors" + "fmt" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/fileicons" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginmanager" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" +) + +// This file hands Core the folder names the enabled plugins hide (workspace.configureVisibility). +// Core hides only its own folders, such as .git, by itself; a build system's output and cache +// folders and a VCS's metadata folder are hidden because the plugin providing it says so. Core +// keeps one list for the process, which every tree listing, search, file event and local history +// check obeys, so the list is sent again with the plugin languages: as a workbench starts and +// after a plugin is installed, enabled, disabled or removed. A changed list re-lists the folders +// every tab's tree shows, and its names take the excluded-folder icon. +// +// Note: 隐藏目录由插件声明的决策见 .agents/notes/implemented/architecture/2026-11-16-plugin-declared-hidden-directories.md + +// visibilityKernel is the part of Core the hidden folders use. +type visibilityKernel interface { + ConfigureVisibility(ctx context.Context, manifests []json.RawMessage) (core.VisibilityConfiguration, error) +} + +// hiddenDirectories is what configureVisibility did: the names Core now hides, valid when +// answered, and every failure on the way, which may come with an answer for the plugins +// that could be read. +type hiddenDirectories struct { + names []string + answered bool + err error +} + +// configureVisibility sends Core the manifests of the enabled plugins that can declare hidden +// folders: those with build systems, whose layouts name them, and those with VCS providers, +// whose directory markers do. vcs is the VCS plugins of entries as the tool windows read them, +// whose failures are reported there. A plugin whose manifest could not be read hides nothing, +// as its build system is not detected either. It reads files and blocks on Core; call it from +// a background goroutine. +func (a *App) configureVisibility(ctx context.Context, entries []pluginmanager.Entry, vcs []pluginservice.VcsPlugin) hiddenDirectories { + kernel, ok := a.kernel.(visibilityKernel) + if !ok { + return hiddenDirectories{} + } + builds, readErr := a.plugins.BuildPlugins(ctx, entries) + var manifests []json.RawMessage + sent := make(map[string]bool, len(builds)+len(vcs)) + add := func(pluginID string, manifest json.RawMessage) { + // A plugin with both build systems and VCS providers is sent once. + if !sent[pluginID] { + sent[pluginID] = true + manifests = append(manifests, manifest) + } + } + for _, plugin := range builds { + add(plugin.PluginID, plugin.Manifest) + } + for _, plugin := range vcs { + add(plugin.PluginID, plugin.Manifest) + } + configuration, err := kernel.ConfigureVisibility(ctx, manifests) + if err != nil { + return hiddenDirectories{err: errors.Join(readErr, err)} + } + if len(configuration.Rejected) > 0 { + readErr = errors.Join(readErr, fmt.Errorf("%d plugin manifests were rejected", len(configuration.Rejected))) + } + return hiddenDirectories{names: configuration.HiddenDirectoryNames, answered: true, err: readErr} +} + +// applyHiddenDirectories shows what configureVisibility did. When Core took a new list, the +// tree of every open tab lists the folders it shows again, keeping what is open and selected, +// and a listing still in flight under the old list is dropped for the new one. The list is +// the same for every tab, so the tabs reloading after one plugin change find it unchanged +// after the first and list nothing again. +func (a *App) applyHiddenDirectories(hidden hiddenDirectories) { + if hidden.err != nil { + a.backgroundFailed("workspace_visibility", hidden.err) + } + if !hidden.answered || !fileicons.SetHiddenDirectoryNames(hidden.names) { + return + } + for _, tab := range a.openTabs() { + if p := tab.project; p != nil && p.tree.root != nil && p.tree.failed == "" { + tab.resyncTreeListings(p) + } + } +} diff --git a/desktop/internal/workbench/hidden_directories_test.go b/desktop/internal/workbench/hidden_directories_test.go new file mode 100644 index 0000000000..a69307fc53 --- /dev/null +++ b/desktop/internal/workbench/hidden_directories_test.go @@ -0,0 +1,240 @@ +package workbench + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "os" + "path/filepath" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/fileicons" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginstate" + "github.com/1lck/Lithe-IDEA/desktop/internal/store" +) + +// hiddenFoldersManifest is a fictional plugin whose build system, found by a fixture.build file, +// hides the folders named names in every workspace. +func hiddenFoldersManifest(t *testing.T, id, system string, names ...string) []byte { + t.Helper() + quoted, err := json.Marshal(names) + if err != nil { + t.Fatal(err) + } + return fmt.Appendf(nil, `{ + "schemaVersion": 0, + "id": %q, + "displayName": "Hidden Folders Fixture", + "version": "1.0.0", + "pluginAPIVersion": 0, + "requires": {"buildSystems": 0}, + "vendor": {"id": "dev.lithe.test", "displayName": "Test", "signatureRequirement": "publisherPackage"}, + "permissions": ["process.build"], + "activationEvents": ["onBuildSystem:%s"], + "languages": [], + "buildSystems": [{ + "id": %q, + "displayName": "Fixture Build", + "detection": {"markers": ["fixture.build"]}, + "invocation": {"executables": [{"kind": "command", "command": "fixture-build"}]}, + "tasks": [{"id": "build", "displayName": "Build", "group": "build", "scopes": ["project"], "arguments": ["build"]}], + "layout": {"hiddenDirectoryNames": %s} + }] +}`, id, system, system, quoted) +} + +// installHiddenFoldersPlugin installs and enables manifest as plugin id under pluginRoot. +func installHiddenFoldersPlugin(t *testing.T, preferences *store.Store, pluginRoot, id string, manifest []byte) { + t.Helper() + installed := filepath.Join(pluginRoot, id, "1.0.0") + if err := os.MkdirAll(installed, 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(installed, "plugin.json"), manifest, 0o600); err != nil { + t.Fatal(err) + } + if err := pluginstate.New(preferences).SetEnabled(id, true); err != nil { + t.Fatal(err) + } +} + +// makeFolders makes each folder under root. +func makeFolders(t *testing.T, root string, folders ...string) { + t.Helper() + for _, folder := range folders { + if err := os.MkdirAll(filepath.Join(root, folder), 0o700); err != nil { + t.Fatal(err) + } + } +} + +// clearHiddenFolders lets every later test start with no hidden folder names, which Core and the +// file icons each keep for the whole process, also after a failed assertion. +func clearHiddenFolders(t *testing.T) { + t.Cleanup(func() { + if _, err := core.NewClient().ConfigureVisibility(context.Background(), nil); err != nil { + t.Errorf("clearing the hidden folders: %v", err) + } + fileicons.SetHiddenDirectoryNames(nil) + }) +} + +// settleTabsUntil settles every tab until condition holds, a step at a time, as settleUntil does +// for one. +func settleTabsUntil(h *harness, what string, condition func() bool) { + h.t.Helper() + for range 12 { + h.settleTabs() + if condition() { + return + } + } + h.t.Fatalf("%s did not happen", what) +} + +// visibilityFailures counts the logged failures of workspace.configureVisibility. +func visibilityFailures(logger *treeRecordingLog) int { + logger.mu.Lock() + defer logger.mu.Unlock() + count := 0 + for _, event := range logger.events { + if event.Event == backgroundFailedEvent && event.Fields["operation"] == "workspace_visibility" { + count++ + } + } + return count +} + +// An enabled plugin's build system hides the folders its layout names from a project tree +// listed before Core knew them, as the tree is at startup, and disabling the plugin shows them +// again. A plugin whose names Core rejects hides nothing and is logged, while the others still +// apply. +func TestPluginDeclaredFoldersLeaveTheProjectTree(t *testing.T) { + dir := t.TempDir() + if err := os.WriteFile(filepath.Join(dir, settingsFile), []byte(`{"theme":"dark"}`), 0o600); err != nil { + t.Fatal(err) + } + preferences := store.At(dir) + pluginRoot := t.TempDir() + const declaring = "dev.lithe.test.hidden-folders" + installHiddenFoldersPlugin(t, preferences, pluginRoot, declaring, hiddenFoldersManifest(t, declaring, "fixture-hidden", "fixture-out")) + const invalid = "dev.lithe.test.invalid-hidden-folder" + installHiddenFoldersPlugin(t, preferences, pluginRoot, invalid, hiddenFoldersManifest(t, invalid, "fixture-invalid", "fixture/out")) + root := t.TempDir() + makeFolders(t, root, "fixture-out", "src") + h := newHarnessWithOptions(t, Options{ + Kernel: &testKernel{Client: core.NewClient()}, + PluginKernel: &testKernel{Client: core.NewClient()}, + PluginRoot: pluginRoot, + Store: preferences, + Languages: []string{"en-US"}, + }) + clearHiddenFolders(t) + logger := &treeRecordingLog{} + h.app.logSink = logger + // The harness does not run the window, so the plugins are read once the tree is listed. + h.open(root) + p := h.app.project + if p == nil { + t.Fatal("the project did not open") + } + h.settleUntil("the tree to list fixture-out", func() bool { + return p.tree.root != nil && p.tree.root.listed && p.tree.find("fixture-out") != nil + }) + + h.app.reloadPluginLanguages() + h.settleUntil("the declared folder to leave the tree", func() bool { + return p.tree.find("src") != nil && p.tree.find("fixture-out") == nil + }) + if got := visibilityFailures(logger); got != 1 { + t.Fatalf("the rejected plugin was logged %d times, want once: %+v", got, logger.events) + } + + if err := pluginstate.New(preferences).SetEnabled(declaring, false); err != nil { + t.Fatal(err) + } + h.app.reloadPluginLanguages() + h.settleUntil("the folder to come back once its plugin is disabled", func() bool { + return p.tree.find("fixture-out") != nil + }) +} + +// The tree lists its folders again when Core hides other folder names, not when the names are +// the same in another case, and a failed call keeps the names Core still has. +func TestHiddenFoldersListTheTreeAgainOnlyWhenTheyChange(t *testing.T) { + k := &countedTreeFilterKernel{testKernel: &testKernel{Client: core.NewClient()}, filtered: make(chan struct{}, 1)} + h := newHarness(t, k) + clearHiddenFolders(t) + root := t.TempDir() + makeFolders(t, root, "src") + h.open(root) + p := h.app.project + awaitDocumentState(t, h, func() bool { return p.tree.root != nil && p.tree.root.listed && !p.tree.reading }) + h.settle() + logger := &treeRecordingLog{} + h.app.logSink = logger + + before := k.listings.Load() + h.app.applyHiddenDirectories(hiddenDirectories{names: []string{"fixture-out"}, answered: true}) + h.settle() + changed := k.listings.Load() + if changed == before { + t.Fatal("new hidden folder names did not list the tree again") + } + h.app.applyHiddenDirectories(hiddenDirectories{names: []string{"FIXTURE-OUT"}, answered: true}) + h.settle() + if got := k.listings.Load(); got != changed { + t.Fatalf("the same names in another case listed the tree again: %d to %d", changed, got) + } + + h.app.applyHiddenDirectories(hiddenDirectories{err: errors.New("fixture visibility failure")}) + h.settle() + if got := k.listings.Load(); got != changed { + t.Fatalf("a failed call listed the tree again: %d to %d", changed, got) + } + if fileicons.SetHiddenDirectoryNames([]string{"fixture-out"}) { + t.Fatal("a failed call changed the hidden folder names") + } + if got := visibilityFailures(logger); got != 1 { + t.Fatalf("the failed call was logged %d times, want once: %+v", got, logger.events) + } +} + +// Core keeps one list for every tab, so the tab that hands it the new names lists the tree of +// every other open tab again too. +func TestHiddenFoldersLeaveTheTreeOfEveryOpenTab(t *testing.T) { + h, alpha, beta := newTabsHarness(t) + clearHiddenFolders(t) + makeFolders(t, alpha, "fixture-out") + makeFolders(t, beta, "fixture-out") + h.open(alpha) + h.app.openProject(beta) + h.settleTabs() + second := h.app.sessions.active + if second == h.app || second.project == nil { + t.Fatal("beta did not open in a second tab") + } + trees := []*fileTree{&h.app.project.tree, &second.project.tree} + shown := func(want bool) func() bool { + return func() bool { + for _, tree := range trees { + if tree.root == nil || !tree.root.listed || (tree.find("fixture-out") != nil) != want { + return false + } + } + return true + } + } + settleTabsUntil(h, "both trees to list fixture-out", shown(true)) + + configuration, err := core.NewClient().ConfigureVisibility(context.Background(), []json.RawMessage{ + hiddenFoldersManifest(t, "dev.lithe.test.hidden-folders", "fixture-hidden", "fixture-out"), + }) + if err != nil || len(configuration.Rejected) != 0 { + t.Fatalf("configureVisibility = %+v, %v", configuration, err) + } + h.app.applyHiddenDirectories(hiddenDirectories{names: configuration.HiddenDirectoryNames, answered: true}) + settleTabsUntil(h, "both trees to hide fixture-out", shown(false)) +} diff --git a/desktop/internal/workbench/local_history_settings_test.go b/desktop/internal/workbench/local_history_settings_test.go index 9dd54e0525..4c910352cc 100644 --- a/desktop/internal/workbench/local_history_settings_test.go +++ b/desktop/internal/workbench/local_history_settings_test.go @@ -2,8 +2,10 @@ package workbench import ( "context" + "encoding/json" "errors" "path/filepath" + "slices" "strings" "testing" "time" @@ -66,24 +68,26 @@ func TestLocalHistorySettingsReachCore(t *testing.T) { if preview, err = source.Preview(ctx, rules, "x.tmp"); err != nil || preview.Matched == nil || preview.Matched.Kind != "regex" || preview.Matched.Index != 2 { t.Fatalf("x.tmp matched %+v, %v, want the third regular expression line", preview.Matched, err) } - // Some built-in folders are hidden in the project tree too, which Core reports first; any - // other one is reported as the built-in rule that keeps it out. - builtIn := false + // The default rules are the folders hidden from the project tree, Core's own and those an + // enabled plugin declares, so a file in any of them is reported as hidden. + clearHiddenFolders(t) + if _, err := core.NewClient().ConfigureVisibility(ctx, []json.RawMessage{ + hiddenFoldersManifest(t, "dev.lithe.test.hidden-folders", "fixture-hidden", "fixture-out"), + }); err != nil { + t.Fatal(err) + } + if preview, err = source.Preview(ctx, core.HistoryIgnoreRules{}, "src/x.txt"); err != nil || preview.Matched != nil { + t.Fatalf("src/x.txt matched %+v, %v, want it recorded", preview.Matched, err) + } + if !slices.Contains(preview.BuiltInIgnorePatterns, "**/.git/") || !slices.Contains(preview.BuiltInIgnorePatterns, "**/fixture-out/") { + t.Fatalf("default rules %q, want Core's own folders and the declared one", preview.BuiltInIgnorePatterns) + } for _, pattern := range preview.BuiltInIgnorePatterns { - name, ok := strings.CutPrefix(pattern, "**/") - if !ok || !strings.HasSuffix(name, "/") { - continue + name := strings.TrimSuffix(strings.TrimPrefix(pattern, "**/"), "/") + folder, err := source.Preview(ctx, core.HistoryIgnoreRules{}, name+"/x.txt") + if err != nil || folder.Matched == nil || folder.Matched.Kind != "hidden" { + t.Fatalf("%s/x.txt matched %+v, %v, want it hidden", name, folder.Matched, err) } - folder, err := source.Preview(ctx, core.HistoryIgnoreRules{}, name+"x.txt") - if err != nil || folder.Matched == nil { - t.Fatalf("%sx.txt matched %+v, %v, want it kept out", name, folder.Matched, err) - } - if folder.Matched.Kind == "pattern" && folder.Matched.Pattern == pattern { - builtIn = true - } - } - if !builtIn { - t.Fatalf("no built-in folder of %q is reported as its built-in rule", preview.BuiltInIgnorePatterns) } var refused *core.Error if _, err = source.Preview(ctx, rules, "../outside.txt"); !errors.As(err, &refused) || refused.Code != core.CodeInvalidRequest { diff --git a/desktop/internal/workbench/plugins.go b/desktop/internal/workbench/plugins.go index 17d09dfeeb..f7aa45938e 100644 --- a/desktop/internal/workbench/plugins.go +++ b/desktop/internal/workbench/plugins.go @@ -311,11 +311,12 @@ func (a *App) uninstallPlugin(id string) { }) } -// reloadPluginLanguages registers the languages and tool windows of the enabled plugins. +// reloadPluginLanguages registers the languages and tool windows of the enabled plugins, and +// hands Core the folders they hide. // -// The registry replaces its plugin languages whole, and the catalog its plugin tool -// windows, so a plugin that was disabled or removed loses its highlighting and its -// windows in the same pass that registers a new one. +// The registry replaces its plugin languages whole, the catalog its plugin tool windows and +// Core its plugin-declared folders, so a plugin that was disabled or removed loses its +// highlighting, its windows and its hidden folders in the same pass that registers a new one. func (a *App) reloadPluginLanguages() { if a.plugins == nil { return @@ -331,7 +332,9 @@ func (a *App) reloadPluginLanguages() { windows, windowsErr := a.plugins.ToolWindows(ctx, entries) commands, commandsErr := a.plugins.ToolCommands(ctx, entries) vcsPlugins, vcsErr := a.plugins.VcsPlugins(ctx, entries) + hidden := a.configureVisibility(ctx, entries, vcsPlugins) return func(a *App) { + a.applyHiddenDirectories(hidden) if commandsErr != nil { a.backgroundFailed("plugin_tool_commands", commandsErr) } diff --git a/desktop/internal/workbench/updates.go b/desktop/internal/workbench/updates.go index 7e1affee8a..5642b6cf3a 100644 --- a/desktop/internal/workbench/updates.go +++ b/desktop/internal/workbench/updates.go @@ -306,6 +306,15 @@ func (a *App) everyTab() []*App { return []*App{a} } +// openTabs is every workbench whose tab is open, or a alone without one; a retired workbench +// is left out, as nothing it shows is seen again. +func (a *App) openTabs() []*App { + if s := a.sessions; s != nil && len(s.list) > 0 { + return s.list + } + return []*App{a} +} + // shownTab is the workbench the window shows, which a notice has to land on to be seen. func (a *App) shownTab() *App { if s := a.sessions; s != nil && s.active != nil { diff --git a/docs/assets/hidden-directories/README.md b/docs/assets/hidden-directories/README.md new file mode 100644 index 0000000000..71c6bee5d0 --- /dev/null +++ b/docs/assets/hidden-directories/README.md @@ -0,0 +1,13 @@ +# 本地历史默认规则说明测试截图 + +来自生产 Viva Page 的无头渲染。设置窗口滚到“外观与行为 > 通用”的本地历史,点击通配符列表那一行的 ⓘ, +固定显示说明:默认规则是项目树中隐藏的目录,包括 Lithe 自己的目录和已启用插件声明的目录;隐藏目录里的文件始终 +不记入本地历史,删掉对应的行也一样。深色使用中文、浅色使用英文。截图不代表 macOS/Windows 原生窗口验收。 + +| 场景 | 深色中文 | 浅色英文 | +| --- | --- | --- | +| 本地历史通配符列表的 ⓘ 说明:先说明通配符的写法,再说明列出的默认规则来自隐藏目录(例如 `**/.git/` 和构建输出目录),以及删掉这些行不会开始记录、删掉的行显示为以“!”开头的行 | [截图](local-history-rules-help-dark.png) | [截图](local-history-rules-help-light.png) | + +复验:分别设置 `LITHE_VISUAL_OUTPUT_DIR`,以及 `LITHE_VISUAL_LANGUAGE=en`(英文)或不设置(中文), +通过 `scripts/desktop/desktop-go.sh test -tags vivahead,lithevisual ./internal/settingswindow +-run 'TestVisualSettings/m46-history-default-rules-help' -count=1 -timeout 300s` 生成。 diff --git a/docs/assets/hidden-directories/local-history-rules-help-dark.png b/docs/assets/hidden-directories/local-history-rules-help-dark.png new file mode 100644 index 0000000000..cc20f54e21 Binary files /dev/null and b/docs/assets/hidden-directories/local-history-rules-help-dark.png differ diff --git a/docs/assets/hidden-directories/local-history-rules-help-light.png b/docs/assets/hidden-directories/local-history-rules-help-light.png new file mode 100644 index 0000000000..8139518816 Binary files /dev/null and b/docs/assets/hidden-directories/local-history-rules-help-light.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index 5ca79b2097..d59ac799af 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -27,6 +27,18 @@ native_path() { fi } +# Lithe-core-rust main at ac8825b, #72 squash-merged: Core hides only .git, .worktree, +# .worktrees, .DS_Store and .lithe by itself; workspace.configureVisibility takes the +# manifests of the enabled plugins and hides the folders their build systems name in +# layout.hiddenDirectoryNames and their VCS providers name as directory markers, in every +# workspace, until the next call replaces them (#1856). On top of #74 squash-merged, which +# adds git.workspacePushPreview, the multi-repository push preview ordering submodules before +# their parents, which the desktop does not send yet; #69 squash-merged, so Core knows no +# runtime by name and go and node resolve through their tool definitions like any other +# runtime without executables, with no hostManaged field (#1856); and #71 squash-merged, which +# adds git.workspaceHistoryMerge, the optional chosen of git.workspaceRepositorySelection and +# the optional maxCommits and limitReached of git.historyPage, none of which the desktop sends +# or reads yet (#2013). # Lithe-core-rust main at 5a8d786, #67 squash-merged: toolchains.candidates takes the optional # commandHomes, lists the commands found on the PATH as shell rows, and offers each shell home that # checks out as an installations entry with provider host:shell, once per canonical home (#2032). @@ -150,7 +162,7 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # the contract, plugin guides, reference and SDKs live only in shared/plugins; on top of #16 (reported Git queries folded in the console), # #15 (git.write cherryPick, revert and reset fields), #14 (word-level changed ranges of diff # rows), #13, #8, #7, #6 and #4. -PINNED_CORE_REVISION="5a8d786e9b44a5a8c7a977a8b376264fa941dcd9" +PINNED_CORE_REVISION="ac8825beaca4ecdf32d7aa031182a24874619e1c" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index 9287224a24..1a1c1bfd9e 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -11016,7 +11016,7 @@ "desktop.settings.network.ignoredExclusions": "These exclusions have none of the supported forms and are ignored: {entries}", "desktop.settings.localHistory.help": "Local history keeps versions of a project's files as you save and edit them, in Lithe's own data folder. Ignore rules only keep files out of local history; the project tree still shows them.", "desktop.settings.localHistory.wildcardHelp": "One pattern per line, matched against the path inside the project, for example `*.log` or `**/generated/`.", - "desktop.settings.localHistory.builtInsHelp": "Built-in rules are listed here too. Delete one to keep that folder out of local history after Apply; it then shows as a \"!\" line, and deleting that line turns the rule back on.", + "desktop.settings.localHistory.builtInsHelp": "Folders hidden from the project tree are listed here too: Lithe's own, such as `**/.git/`, and those enabled plugins declare, such as a build's output folder. Files in a hidden folder are never recorded, even after you delete its line. A deleted line shows as a \"!\" line after Apply; delete that line to restore the rule.", "desktop.settings.localHistory.regexHelp": "One per line, case-insensitive, matched anywhere in the project-relative path with `/` separators, for example `^build/` or `(test|spec)/`.", "desktop.settings.localHistory.invalidLimit": "Enter the limit as a whole number of megabytes, 1 or more, or leave it empty for the default.", "desktop.settings.editor.tabLimit": "Tab limit", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 2806663b9e..8778e80ff9 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -11016,7 +11016,7 @@ "desktop.settings.network.ignoredExclusions": "以下排除项不是支持的格式,已忽略:{entries}", "desktop.settings.localHistory.help": "本地历史在你保存和编辑项目文件时保留各个版本,存放在 Lithe 自己的数据目录中。忽略规则只让文件不进入本地历史,项目树仍然显示它们。", "desktop.settings.localHistory.wildcardHelp": "每行一条规则,按项目内的路径匹配,例如 `*.log` 或 `**/generated/`。", - "desktop.settings.localHistory.builtInsHelp": "内置规则也列在这里。删除其中一行,应用后该目录不再记入本地历史,并以 `!` 开头的行显示;删除这行 `!` 行即可重新开启该规则。", + "desktop.settings.localHistory.builtInsHelp": "项目树中隐藏的目录也列在这里:Lithe 自己的目录(例如 `**/.git/`),以及已启用插件声明的目录(例如构建输出目录)。隐藏目录里的文件始终不记入本地历史,删掉对应的行也一样。删掉的行在应用后显示为以“!”开头的行;删除这一行即可恢复该规则。", "desktop.settings.localHistory.regexHelp": "每行一条,不区分大小写,在以 `/` 分隔的项目内相对路径中任意位置匹配,例如 `^build/` 或 `(test|spec)/`。", "desktop.settings.localHistory.invalidLimit": "上限请填写不小于 1 的整数(单位 MB),留空则使用默认值。", "desktop.settings.editor.tabLimit": "标签数量上限", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index 535cec290c..13c9ce4e65 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -15837,7 +15837,7 @@ }, { "id": "desktop.settings.localHistory.builtInsHelp", - "description": "Settings > General > Local History: the built-in ignore rules are lines of the wildcard list; deleting one keeps its folder out of history, and deleting its \"!\" line turns it back on", + "description": "Settings > General > Local History: the default ignore rules, the folders hidden from the project tree (Lithe's own and those enabled plugins declare), are lines of the wildcard list; their files are never recorded even when a line is deleted, a deleted line shows as a \"!\" line, and deleting that line restores it", "platforms": [ "desktop" ] diff --git a/shared/platform-feature-matrix/features/file-explorer.json b/shared/platform-feature-matrix/features/file-explorer.json index d1ca5f83b3..540c8a4306 100644 --- a/shared/platform-feature-matrix/features/file-explorer.json +++ b/shared/platform-feature-matrix/features/file-explorer.json @@ -12,6 +12,10 @@ "desktop/internal/workbench/filetree_test.go", "desktop/internal/core/workspace.go", "desktop/internal/core/workspace_tree_test.go", + "desktop/internal/core/workspace_visibility.go", + "desktop/internal/core/workspace_visibility_test.go", + "desktop/internal/workbench/hidden_directories.go", + "desktop/internal/workbench/hidden_directories_test.go", "desktop/internal/workbench/filetree_watch.go", "desktop/internal/workbench/filetree_actions.go", "desktop/internal/workbench/filetree_actions_test.go", @@ -28,6 +32,10 @@ "desktop/internal/workbench/filetree_test.go", "desktop/internal/core/workspace.go", "desktop/internal/core/workspace_tree_test.go", + "desktop/internal/core/workspace_visibility.go", + "desktop/internal/core/workspace_visibility_test.go", + "desktop/internal/workbench/hidden_directories.go", + "desktop/internal/workbench/hidden_directories_test.go", "desktop/internal/workbench/filetree_watch.go", "desktop/internal/workbench/filetree_actions.go", "desktop/internal/workbench/filetree_actions_test.go", @@ -36,8 +44,8 @@ ] }, "owner": "Workspace", - "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 后改为跟随焦点。", + "verification": "项目树磁盘与 Git 目录查询使用独立有界 I/O 限时;运行 TestProjectTreeDirectoryReadsAllowNativeIO 和 TestProjectTreeDirectoryReadCancelsWhenProjectCloses,验证超过纯计算限时仍可加载、关闭项目取消请求且旧结果不恢复项目。macOS 和 Windows 无头测试覆盖目录选择、展开、键盘、虚拟绘制、长文件名滚动、外部新增删除、空目录变化、超过 128 个目录、隐藏路径过滤、视口锚定、过期读取以及与搜索共享监听的关闭和重试;真实 Core 测试覆盖共享自然排序样例,以及插件声明的隐藏目录:任意层级、忽略 ASCII 大小写,被拒的清单不生效,清空后重新显示。运行 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 上跳过);原生窗口验收待做。 插件声明的隐藏目录(2026-11-16,#1856,Lithe-core-rust #72):运行 scripts/desktop/desktop-go.sh test ./internal/workbench -run 'TestPluginDeclaredFolders|TestHiddenFolders' -count=1 和 scripts/desktop/desktop-go.sh test ./internal/core -run TestWorkspaceVisibility -count=1;实机启用一个在 layout.hiddenDirectoryNames 声明目录的构建插件后,每个打开的项目标签页的项目树都不再显示这些目录、搜索也不再命中其中的文件,禁用或卸载插件后重新显示;原生窗口验收待做。", + "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 后改为跟随焦点。 2026-11-16 起(#1856,Lithe-core-rust #72)Core 自身只隐藏 .git、.worktree、.worktrees、.DS_Store 和 .lithe;构建产物、缓存和 VCS 元数据目录由启用的插件声明(构建系统的 layout.hiddenDirectoryNames、VCS 提供者的目录标记),宿主读取插件语言时一并交给 Core(workspace.configureVisibility),名单变化后每个打开的标签页重读已展开的目录,排除目录图标也只认这份名单。宿主不再内置 target、build、out、node_modules、.idea、.venv、__pycache__ 等名称,没有对应插件的生态不再隐藏这些目录。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { diff --git a/shared/platform-feature-matrix/features/git-repository-discovery.json b/shared/platform-feature-matrix/features/git-repository-discovery.json index 8518452a69..9a234d6e4b 100644 --- a/shared/platform-feature-matrix/features/git-repository-discovery.json +++ b/shared/platform-feature-matrix/features/git-repository-discovery.json @@ -9,6 +9,7 @@ "evidence": [ ".agents/notes/implemented/process/2026-09-24-cross-platform-feature-parity-matrix.md", "desktop/internal/core/workspace.go", + "desktop/internal/workbench/hidden_directories.go", "desktop/internal/workbench/gitreview_tools.go", "desktop/internal/workbench/gitreview_tools_view.go" ] @@ -19,13 +20,14 @@ "evidence": [ ".agents/notes/implemented/process/2026-09-24-cross-platform-feature-parity-matrix.md", "desktop/internal/core/workspace.go", + "desktop/internal/workbench/hidden_directories.go", "desktop/internal/workbench/gitreview_tools.go", "desktop/internal/workbench/gitreview_tools_view.go" ] }, "owner": "Git", - "verification": "打开含 .build/checkouts、macos/.build/checkouts、.cache、node_modules 与可见嵌套仓库的项目,确认 Git 状态和引用只包含主仓库及可见源码仓库;.worktrees 和 .worktree 中的真实工作树仍可发现,其构建缓存仍被排除。直接打开隐藏仓库及其源码子目录应能使用 Git。", - "notes": "Viva:Commit 面板的变更行右键/双击接入 Core 封装,对话框已实现;见 desktop/internal/workbench/gitreview*.go。未覆盖项见 PR 描述。", + "verification": "打开含 .build/checkouts、macos/.build/checkouts、.cache、一个已启用插件声明的隐藏目录(例如构建插件声明的输出目录)与可见嵌套仓库的项目,确认 Git 状态和引用只包含主仓库及可见源码仓库;.worktrees 和 .worktree 中的真实工作树仍可发现,其构建缓存仍被排除。直接打开隐藏仓库及其源码子目录应能使用 Git。", + "notes": "Viva:Commit 面板的变更行右键/双击接入 Core 封装,对话框已实现;见 desktop/internal/workbench/gitreview*.go。未覆盖项见 PR 描述。 2026-11-16 起(#1856,Lithe-core-rust #72)自动发现跳过以点开头的目录(.worktree、.worktrees 除外)和默认隐藏目录:Core 自己的加上已启用插件声明的,由 desktop/internal/workbench/hidden_directories.go 在读取插件语言时交给 Core;Core 不再内置 node_modules、target、build、DerivedData 等名称,没有对应插件时这些目录里的仓库会被发现。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { diff --git a/shared/platform-feature-matrix/features/history-snapshots.json b/shared/platform-feature-matrix/features/history-snapshots.json index 2a4b03d897..cdd5ac10f6 100644 --- a/shared/platform-feature-matrix/features/history-snapshots.json +++ b/shared/platform-feature-matrix/features/history-snapshots.json @@ -32,8 +32,8 @@ ] }, "owner": "Local History", - "verification": "Viva:运行 desktop-go.sh test ./internal/workbench/ -run TestLocalHistory,覆盖两份快照的“与上一条比较”(只读 Diff 标签页、两侧以快照时间命名、Core 给出一增一删)、与当前比较时取编辑器未保存文本(关闭自动保存,磁盘不含该修改)、文本相同时只在窗口提示、快照写入客户端数据目录。本地历史设置:desktop-go.sh test ./internal/workbench/ -run TestLocalHistorySettings 用真实 Core 验证已保存的通配符与正则规则让匹配文件不被记录、预览按输入行号报告无效正则与命中规则(通配符、正则、内置文件夹)、越界测试路径返回 invalid_request、占用按 Core 限定后的上限(5MB 取 10MB、默认 100MB)回报、清空后用量归零且快照消失;./internal/settingswindow/ -run TestLocalHistoryCard 覆盖设置页显示占用/上限与内置规则、按原样逐行发送预览、测试路径结论与 Git 对照、上限非整数拒绝应用、应用时去空白去空行并按新上限重新统计、还原、清空先确认、取消不清空、失败提示与重试、无项目提示。旧客户端基线:编辑同一文件多次,比较快照时间、内容 Diff 和文件范围。 macOS 外部变更和目录操作按批记录历史,仅首个成功快照触发全库过期清理;验证跳过文件、连续批次、取消及单文件保存,4000 文件变化后 CPU 回落且历史仍可读取。 编辑同一文件多次,比较快照时间、内容 Diff 和文件范围。存储上限:Rust 测试覆盖基线跳过生成目录与嵌套仓库、保存时清理旧版本留下的排除目录基线、超过 100MB 先淘汰旧基线再淘汰编辑和标签、基线预算 50MB。忽略规则:Rust 测试覆盖通配符与正则忽略新记录但保留已有历史、正则不区分大小写且无效或空正则不匹配、预览报告无效正则行和命中规则(隐藏、通配符含内置文件夹、正则)、拒绝越界路径、占用统计与清空项目历史。内置项可改:Rust 测试覆盖内置文件夹以 `**/名称/` 通配符规则生效、命中时报告该规则、`!**/名称/` 或 `!名称` 关闭内置项后重新记录;隐藏路径的 `!` 条目关闭内置隐藏目录。上限可配:Rust 测试覆盖默认 100MB、配置值生效并限定在 10MB–100GB、基线预算为上限一半。Git 对照:Rust 测试覆盖测试路径在 Git 仓库中返回是否被 .gitignore 忽略、非仓库返回空。 PR #1615 回归:关闭内置隐藏项和历史忽略项后,添加无关通配符仍可预览及记录;清空前取消并等待已有保存和外部变更任务,清空代次拒绝在途批次续写,清空后新保存可记录;隐藏路径变化纳入预览请求身份并重新计算结果。 容量输入仅接受完整非负整数与可选 MB 后缀,指数、负数、字母、溢出等无效输入不改变已保存值;回车和失焦均验证恢复或范围限定。清空失败显示中英错误与需再次确认的重试入口,回读剩余用量;重试成功清除错误并显示新用量。 PR #1597 历史迁移回归:文件与目录已有历史后排除索引,再重命名或移动,按历史元数据迁移精确路径和后代,保留内容、ID及相对后缀,同名前缀兄弟不变;工作区回归使用真实文件操作与空索引候选,不能为迁移历史重新纳入索引。目标平台原生历史界面验收仍待完成。 记录时机统一:两端都按 Core 的 history.planEvent 记录,保存与自动保存先记被替换的文本、写入成功后立即再记保存后的文本,恢复先记当前文本。Windows 重命名或移动文件及目录(含拖放与剪切粘贴)后调用 history.relocate 迁移历史,验证旧路径无残留、新路径沿用原有快照。", - "notes": "Viva:本地历史窗口列出文件的快照(时间、事件、标签),选中后预览该快照文本,可恢复、重命名、删除;“与上一条比较”和“与当前比较”打开只读 Diff 标签页,由 Core 的 diff.compareTexts 比较,当前文本取已打开编辑器中的未保存内容,否则读磁盘,文件已删除时按空文本比较,两侧相同时在窗口中提示而不打开标签页。快照存在客户端自己的数据目录(<数据目录>/LocalHistory/<项目路径哈希>,与 Shelf 相同),不写旧版 Lithe 的数据目录。设置 › 通用 › 本地历史:显示本项目占用/上限(二进制单位,上限取 Core 限定后的值)与确认后清空(失败可重试);每个项目上限以 MB 输入,留空用 Core 默认值;通配符与正则忽略规则每行一条,应用后随每次记录交给 Core;Core 的内置规则只读列在通配符下方,以 `!**/名称/` 一行关闭某个内置项(不像旧 macOS 那样把内置项合并进文本框,避免在 Go 重写 Core 的关闭匹配);测试路径随输入(200ms 防抖)由 Core history.ignorePreview 判断是否记录及 Git 是否忽略,无效正则按行号提示。Viva 桌面端尚无“隐藏路径”设置,隐藏判断沿用 Core 默认的隐藏目录。未迁移:全项目时间线、手动创建标记条目。", + "verification": "Viva:运行 desktop-go.sh test ./internal/workbench/ -run TestLocalHistory,覆盖两份快照的“与上一条比较”(只读 Diff 标签页、两侧以快照时间命名、Core 给出一增一删)、与当前比较时取编辑器未保存文本(关闭自动保存,磁盘不含该修改)、文本相同时只在窗口提示、快照写入客户端数据目录。本地历史设置:desktop-go.sh test ./internal/workbench/ -run TestLocalHistorySettings 用真实 Core 验证已保存的通配符与正则规则让匹配文件不被记录、预览按输入行号报告无效正则与命中规则(通配符、正则),默认规则含 Core 自己的目录和插件声明的目录且其中的文件按隐藏报告、越界测试路径返回 invalid_request、占用按 Core 限定后的上限(5MB 取 10MB、默认 100MB)回报、清空后用量归零且快照消失;./internal/settingswindow/ -run TestLocalHistoryCard 覆盖设置页显示占用/上限与内置规则、按原样逐行发送预览、测试路径结论与 Git 对照、上限非整数拒绝应用、应用时去空白去空行并按新上限重新统计、还原、清空先确认、取消不清空、失败提示与重试、无项目提示。旧客户端基线:编辑同一文件多次,比较快照时间、内容 Diff 和文件范围。 macOS 外部变更和目录操作按批记录历史,仅首个成功快照触发全库过期清理;验证跳过文件、连续批次、取消及单文件保存,4000 文件变化后 CPU 回落且历史仍可读取。 编辑同一文件多次,比较快照时间、内容 Diff 和文件范围。存储上限:Rust 测试覆盖基线跳过生成目录与嵌套仓库、保存时清理旧版本留下的排除目录基线、超过 100MB 先淘汰旧基线再淘汰编辑和标签、基线预算 50MB。忽略规则:Rust 测试覆盖通配符与正则忽略新记录但保留已有历史、正则不区分大小写且无效或空正则不匹配、预览报告无效正则行和命中规则(隐藏、通配符含内置文件夹、正则)、拒绝越界路径、占用统计与清空项目历史。内置项可改:Rust 测试覆盖内置文件夹以 `**/名称/` 通配符规则生效、命中时报告该规则、`!**/名称/` 或 `!名称` 关闭内置项后重新记录;隐藏路径的 `!` 条目关闭内置隐藏目录。上限可配:Rust 测试覆盖默认 100MB、配置值生效并限定在 10MB–100GB、基线预算为上限一半。Git 对照:Rust 测试覆盖测试路径在 Git 仓库中返回是否被 .gitignore 忽略、非仓库返回空。 PR #1615 回归:关闭内置隐藏项和历史忽略项后,添加无关通配符仍可预览及记录;清空前取消并等待已有保存和外部变更任务,清空代次拒绝在途批次续写,清空后新保存可记录;隐藏路径变化纳入预览请求身份并重新计算结果。 容量输入仅接受完整非负整数与可选 MB 后缀,指数、负数、字母、溢出等无效输入不改变已保存值;回车和失焦均验证恢复或范围限定。清空失败显示中英错误与需再次确认的重试入口,回读剩余用量;重试成功清除错误并显示新用量。 PR #1597 历史迁移回归:文件与目录已有历史后排除索引,再重命名或移动,按历史元数据迁移精确路径和后代,保留内容、ID及相对后缀,同名前缀兄弟不变;工作区回归使用真实文件操作与空索引候选,不能为迁移历史重新纳入索引。目标平台原生历史界面验收仍待完成。 记录时机统一:两端都按 Core 的 history.planEvent 记录,保存与自动保存先记被替换的文本、写入成功后立即再记保存后的文本,恢复先记当前文本。Windows 重命名或移动文件及目录(含拖放与剪切粘贴)后调用 history.relocate 迁移历史,验证旧路径无残留、新路径沿用原有快照。", + "notes": "Viva:本地历史窗口列出文件的快照(时间、事件、标签),选中后预览该快照文本,可恢复、重命名、删除;“与上一条比较”和“与当前比较”打开只读 Diff 标签页,由 Core 的 diff.compareTexts 比较,当前文本取已打开编辑器中的未保存内容,否则读磁盘,文件已删除时按空文本比较,两侧相同时在窗口中提示而不打开标签页。快照存在客户端自己的数据目录(<数据目录>/LocalHistory/<项目路径哈希>,与 Shelf 相同),不写旧版 Lithe 的数据目录。设置 › 通用 › 本地历史:显示本项目占用/上限(二进制单位,上限取 Core 限定后的值)与确认后清空(失败可重试);每个项目上限以 MB 输入,留空用 Core 默认值;通配符与正则忽略规则每行一条,应用后随每次记录交给 Core;Core 的默认规则作为通配符列表开头的行显示,删掉一行应用后保存并显示为 `!**/名称/`,删掉 `!` 行即恢复(关闭匹配由 Core 判断,宿主只比较行文本);测试路径随输入(200ms 防抖)由 Core history.ignorePreview 判断是否记录及 Git 是否忽略,无效正则按行号提示。Viva 桌面端尚无“隐藏路径”设置,隐藏判断沿用 Core 默认的隐藏目录。未迁移:全项目时间线、手动创建标记条目。 2026-11-16 起(#1856,Lithe-core-rust #72)默认规则就是项目树的默认隐藏目录:Core 自己的 .git、.worktree、.worktrees,加上已启用插件声明的目录(构建系统的 layout.hiddenDirectoryNames 等);Core 不再内置 node_modules、.venv、target、.claude、DerivedData 等名称,没有对应插件时这些目录会被记录。Viva 没有“隐藏路径”设置,默认规则对应的目录始终隐藏,删掉对应的行也不会开始记录,设置页 ⓘ 说明已按此改写(此前的说明把删除行的效果写反了)。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": {