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
Expand Up @@ -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,所以这套默认规则对所有平台生效。规则按名字匹配,其他名称的虚拟环境不会因此自动识别。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 实现一次。
Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -260,7 +262,7 @@ Gradle 的 `offline` 和 `userHome` 是用户自己选的值,不是猜测,

### 只允许宿主管理的运行时

最有吸引力的地方:运行时发现全部由宿主掌控。不采用,因为这会把 .NET、Erlang、Dart 这类工具挡在外面。现在 `java`、`node`、`go` 由宿主管理,其余运行时由插件自己描述可执行文件和版本探测。
最有吸引力的地方:运行时发现全部由宿主掌控。不采用,因为这会把 .NET、Erlang、Dart 这类工具挡在外面。现在没有宿主管理的运行时:运行时要么由插件描述可执行文件和版本探测,要么交给同 ID 的工具定义(2026-11-16 起 `go`、`node` 也一样)。

## 后果

Expand Down
Original file line number Diff line number Diff line change
@@ -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),其中仍有价值的理由已并入上文。
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## 先说结论

工作区的 Git 列表不应自动纳入 `.build/checkouts` 等缓存中的依赖仓库。
自动发现默认跳过隐藏目录和内置构建目录,但保留工作树容器及用户显式打开的目录。
自动发现默认跳过隐藏目录和默认隐藏目录(Core 自己的,加上已启用插件声明的构建、缓存目录),但保留工作树容器及用户显式打开的目录。
切换仓库时,历史请求、分支选择和提交选择必须一起切换,不能把旧仓库的引用传给新仓库。

## 问题
Expand All @@ -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` 时仍然管理这个仓库;
Expand Down
1 change: 0 additions & 1 deletion desktop/internal/core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
11 changes: 11 additions & 0 deletions desktop/internal/core/repository_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand All @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion desktop/internal/core/workspace_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
27 changes: 0 additions & 27 deletions desktop/internal/core/workspace_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
39 changes: 39 additions & 0 deletions desktop/internal/core/workspace_visibility.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading
Loading