diff --git a/.agents/notes/implemented/feature/2026-11-08-viva-project-search.md b/.agents/notes/implemented/feature/2026-11-08-viva-project-search.md index 17d257e42..e2545f701 100644 --- a/.agents/notes/implemented/feature/2026-11-08-viva-project-search.md +++ b/.agents/notes/implemented/feature/2026-11-08-viva-project-search.md @@ -22,9 +22,13 @@ Viva 的项目搜索侧栏调用 Rust Core 搜索本地工作区,而不是在 事件丢失时先重新注册,避免重建后继续使用已失效的监听。注册失败会记录日志并 提示用户,后续每次查询重建索引,用户可手动刷新。刷新按钮始终强制重建。 关闭搜索面板时释放监听,重新打开后重新注册;关闭项目时等待已在运行的搜索 -结束,再异步释放 Core 索引。文件匹配、内容匹配、掩码、大小写、整词及正则 -均由 Core 决定。结果列表虚拟化,最多展示 200 项,达到上限时提示缩小范围; -点击内容结果会打开文件并跳到对应行,输入法组合期间不强行移动光标。 +结束,再异步释放 Core 索引。内容匹配、掩码、大小写、整词及正则均由 Core +决定,读取哪些文件也由 Core 决定:编辑器能当文本打开的文件都会搜(16 MiB 以内, +按 `file.read` 的编码识别解码,含 NUL 的二进制文件跳过),CRLF 行尾的 `\r` +不算行内容。项目搜索和 IDE 的 Find in Files 一样只列内容行,请求带 +`maxFileResults: 0`,文件名含查询词的文件不出结果,也不占用 200 条上限 +(#2198)。结果列表虚拟化,最多展示 200 项,达到上限时提示缩小范围; +点击内容结果会打开文件并跳到匹配处,输入法组合期间不强行移动光标。 全局搜索复用 Core 的 `workspace.searchEverywhere`,按 50 条分页并保留 Core 排序、打开文件的同分优先级与不透明游标;“全部”和“文件”查找文件名,“文本” @@ -43,6 +47,9 @@ Viva 的项目搜索侧栏调用 Rust Core 搜索本地工作区,而不是在 - 一直复用现有索引而不接文件监听,会在外部编辑后产生静默漏报,不能采用。 - 每次按键并行启动新查询会积累索引构建任务,浪费资源并可能发布旧结果;采用 输入合并、取消和单查询串行。 +- 项目搜索继续列出文件名匹配、只是排在内容行之后:Core 先收集文件名匹配,文件名 + 含查询词的文件一多就占满 200 条上限,内容行一条都不剩;IDE 的 Find in Files + 也不列文件名,查文件名用全局搜索的“文件”。被否。 ## 后果 diff --git a/desktop/internal/core/workspace.go b/desktop/internal/core/workspace.go index 0e19c2ace..d02defa38 100644 --- a/desktop/internal/core/workspace.go +++ b/desktop/internal/core/workspace.go @@ -323,6 +323,9 @@ type WorkspaceSearchRequest struct { RegularExpression bool `json:"regularExpression,omitempty"` FileMask string `json:"fileMask,omitempty"` MaxResults int `json:"maxResults"` + // MaxFileResults caps the file-name matches within MaxResults; nil leaves them + // capped only by MaxResults and zero asks for content matches alone. + MaxFileResults *int `json:"maxFileResults,omitempty"` // IncludeContentRanges asks for the untrimmed line and the match ranges of each // content match (WorkspaceSearchMatch.SourceLine and ContentMatchRanges). IncludeContentRanges bool `json:"includeContentRanges,omitempty"` diff --git a/desktop/internal/workbench/search.go b/desktop/internal/workbench/search.go index e46185eaf..ce8c7838f 100644 --- a/desktop/internal/workbench/search.go +++ b/desktop/internal/workbench/search.go @@ -268,7 +268,10 @@ func (a *App) runProjectSearch(p *project) { err := synchronizeSearchIndex(operation, kernel, root, full, paths) var matches []core.WorkspaceSearchMatch if err == nil { - matches, err = kernel.SearchWorkspace(operation, core.WorkspaceSearchRequest{Root: root, Query: query.text, FileMask: query.mask, CaseSensitive: query.matchCase, WholeWords: query.wholeWords, RegularExpression: query.regex, MaxResults: searchMaxResults, IncludeContentRanges: true}) + // Find in Files lists only lines, as the IDE's does; file names that contain + // the query would otherwise fill the result cap before any line. + noFileResults := 0 + matches, err = kernel.SearchWorkspace(operation, core.WorkspaceSearchRequest{Root: root, Query: query.text, FileMask: query.mask, CaseSensitive: query.matchCase, WholeWords: query.wholeWords, RegularExpression: query.regex, MaxResults: searchMaxResults, MaxFileResults: &noFileResults, IncludeContentRanges: true}) } return func(a *App) { a.finishProjectSearch(p, generation, matches, err, full || len(paths) > 0) } }) diff --git a/desktop/internal/workbench/search_test.go b/desktop/internal/workbench/search_test.go index abd9e9dac..772d8d600 100644 --- a/desktop/internal/workbench/search_test.go +++ b/desktop/internal/workbench/search_test.go @@ -48,6 +48,67 @@ func TestProjectSearchOpensMatchingLine(t *testing.T) { } } +// Find in Files lists the lines that contain the query, as the IDE's does: file names +// that contain it are not results, so many of them cannot use up the result cap. +func TestProjectSearchListsContentLinesWhenManyFileNamesMatch(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + h.app.searchView.delay = 0 + root := t.TempDir() + for i := range searchMaxResults + 50 { + if err := os.WriteFile(filepath.Join(root, fmt.Sprintf("handler%03d.go", i)), []byte("package main\n"), 0o600); err != nil { + t.Fatal(err) + } + } + if err := os.WriteFile(filepath.Join(root, "content.txt"), []byte("first\ncall handler here\n"), 0o600); err != nil { + t.Fatal(err) + } + h.open(root) + p := h.app.project + h.app.updateProjectSearch(p, searchQuery{text: "handler"}) + awaitDocumentState(t, h, func() bool { return !p.search.loading && (p.search.failed || len(p.search.matches) > 0) }) + if p.search.failed || len(p.search.matches) != 1 { + t.Fatalf("got %d results, want only the content line", len(p.search.matches)) + } + match := p.search.matches[0] + if match.Kind != "content" || match.Path != "content.txt" || match.Line == nil || *match.Line != 2 { + t.Fatalf("result = %+v, want content.txt line 2", match) + } +} + +// Find in Files searches every file the editor opens as text: a GBK file, and a CRLF line whose +// end `$` matches. A result opens at the match, so Core and the editor decode the file alike. +func TestProjectSearchFindsLinesInEveryFileTheEditorOpens(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + h.app.searchView.delay = 0 + root := t.TempDir() + // "中文 gbkNeedle417" in GBK, where U+4E2D is D6 D0 and U+6587 is CE C4. + gbk := filepath.Join(root, "gbk.txt") + if err := os.WriteFile(gbk, append([]byte{0xD6, 0xD0, 0xCE, 0xC4, ' '}, "gbkNeedle417\n"...), 0o600); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(root, "crlf.txt"), []byte("first\r\ncrlfNeedle417\r\n"), 0o600); err != nil { + t.Fatal(err) + } + h.open(root) + p := h.app.project + h.app.updateProjectSearch(p, searchQuery{text: "Needle417$", regex: true}) + awaitDocumentState(t, h, func() bool { return !p.search.loading && (p.search.failed || len(p.search.matches) > 0) }) + found := map[string]core.WorkspaceSearchMatch{} + for _, match := range p.search.matches { + found[match.Path] = match + } + crlf, gbkMatch := found["crlf.txt"], found["gbk.txt"] + if p.search.failed || len(found) != 2 || crlf.Line == nil || *crlf.Line != 2 || gbkMatch.Line == nil || *gbkMatch.Line != 1 { + t.Fatalf("results = %+v, want crlf.txt line 2 and gbk.txt line 1", p.search.matches) + } + h.app.openSearchResult(p, gbkMatch) + awaitDocumentState(t, h, func() bool { return p.docs.byPath(gbk) != nil }) + // The match starts after the two Han characters, the space and "gbk": 10 UTF-8 bytes. + if line, column := p.docs.byPath(gbk).view.Caret(); line != 0 || column != 10 { + t.Fatalf("opened at %d:%d, want 0:10 (zero-based, in bytes)", line, column) + } +} + type delayedSearchKernel struct { *testKernel started chan string diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index 7683c8d38..a5aabf265 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -27,7 +27,15 @@ native_path() { fi } -# Lithe-core-rust main at 0b6da27: #109, squash-merged into main: a canvas's on may list resize +# Lithe-core-rust main at ce628c7: #116, squash-merged into main: content search and its index read +# every file the editor opens as text (up to 16 MiB, decoded like file.read, binary files skipped) +# and match a CRLF line without its \r; replacement previews still read only strict UTF-8 up to +# 2 MiB. It is on top of #115 (929b8c6, documentation only), #112 (44d62e4, command test +# discovery: build.testDiscoveryPlan and build.decodeTestDiscovery), #111 (c481227, global +# toolchain provider queries resolved), #106 (509c2be, typed toolchain providers in the Rust SDK), +# #114 (a9539ed) and #113 (31657cc, the Go plugin backend SDK), which only changed plugin SDKs and +# documentation, and #110 (7b6a967, Core CI formatting check). +# Below them, Lithe-core-rust main at 0b6da27: #109, squash-merged into main: a canvas's on may list resize # beside viewport, which the desktop sends with the new width 400 ms after the width stops # changing; every view event carries width, the width the view's nodes are laid out in. It is on # top of #108 (9dea6aa), squash-merged into main: managedRuntimes 1 lists mirror URLs for runtime @@ -271,7 +279,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="0b6da2725ded74de7c3b62b49d12c1947dc0a38a" +PINNED_CORE_REVISION="ce628c7e00c5707a6321eaf9a3062402c980d208" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/platform-feature-matrix/features/search-project.json b/shared/platform-feature-matrix/features/search-project.json index c85095312..e512f94f2 100644 --- a/shared/platform-feature-matrix/features/search-project.json +++ b/shared/platform-feature-matrix/features/search-project.json @@ -22,7 +22,7 @@ ] }, "owner": "Search", - "verification": "使用同一项目和查询 fixture 对比命中路径、行号、列号和结果排序;在 macOS 深浅主题检查搜索框输入、焦点与失焦、工具按钮及文件类型图标;点击侧栏 Search 时第一个输入框不自动获得焦点,使用 Cmd+Shift+F 时仍获得焦点。 Search 查询与文件掩码、Database 连接搜索、Redis Key pattern 和 Nacos 配置/服务搜索均直接使用 Git Log 同源的全局唯一 LitheSearchFieldStyle;在深浅主题核对 36pt 外框、30pt 可见高度、4pt 圆角、1pt 常态边框、2pt 聚焦边框、3pt 外留白及 13pt 常规文字和提示色,确认无局部背景或原生边框叠加,并保留搜索、清除与键盘提交行为。 使用原生 NSHostingView 渲染验证共享 LitheSearchTextField 的占位文字在深浅主题均为 IDEA Component.infoForeground 对应的 #73767C、13pt 常规字重;空输入框单独绘制占位文字,避免 SwiftUI 原生 prompt 替换其颜色与字重,有内容时占位文字消失并保留原生编辑和主文字色。 中文输入法组词期间,即使绑定文本仍为空,共享 LitheSearchTextField 占位文字立即隐藏;取消组词或删空后恢复,确认中文后仍隐藏。原生 setMarkedText 回归覆盖明暗主题和两个输入框互不影响;保留焦点、键盘提交、搜索/过滤语义及占位字号颜色。原生背景观察视图卸载和移出窗口时清理通知,匹配当前窗口的字段编辑器及所属输入区域,不修改业务绑定。 共享搜索字段未聚焦时悬停立即显示文本编辑光标,离开或禁用时恢复箭头;保留中文组词、焦点及键盘动作。 macOS 项目树文件、目录、项目根和多选右键菜单均显示 Find in Files,调用已有项目范围搜索并聚焦查询框;验证编辑器选中文字预填与现有搜索规则。该菜单入口沿用整个项目范围。", + "verification": "使用同一项目和查询 fixture 对比命中路径、行号、列号和结果排序;在 macOS 深浅主题检查搜索框输入、焦点与失焦、工具按钮及文件类型图标;点击侧栏 Search 时第一个输入框不自动获得焦点,使用 Cmd+Shift+F 时仍获得焦点。 Search 查询与文件掩码、Database 连接搜索、Redis Key pattern 和 Nacos 配置/服务搜索均直接使用 Git Log 同源的全局唯一 LitheSearchFieldStyle;在深浅主题核对 36pt 外框、30pt 可见高度、4pt 圆角、1pt 常态边框、2pt 聚焦边框、3pt 外留白及 13pt 常规文字和提示色,确认无局部背景或原生边框叠加,并保留搜索、清除与键盘提交行为。 使用原生 NSHostingView 渲染验证共享 LitheSearchTextField 的占位文字在深浅主题均为 IDEA Component.infoForeground 对应的 #73767C、13pt 常规字重;空输入框单独绘制占位文字,避免 SwiftUI 原生 prompt 替换其颜色与字重,有内容时占位文字消失并保留原生编辑和主文字色。 中文输入法组词期间,即使绑定文本仍为空,共享 LitheSearchTextField 占位文字立即隐藏;取消组词或删空后恢复,确认中文后仍隐藏。原生 setMarkedText 回归覆盖明暗主题和两个输入框互不影响;保留焦点、键盘提交、搜索/过滤语义及占位字号颜色。原生背景观察视图卸载和移出窗口时清理通知,匹配当前窗口的字段编辑器及所属输入区域,不修改业务绑定。 共享搜索字段未聚焦时悬停立即显示文本编辑光标,离开或禁用时恢复箭头;保留中文组词、焦点及键盘动作。 macOS 项目树文件、目录、项目根和多选右键菜单均显示 Find in Files,调用已有项目范围搜索并聚焦查询框;验证编辑器选中文字预填与现有搜索规则。该菜单入口沿用整个项目范围。 在同一项目放入大量文件名含查询词的文件、GBK 与 UTF-16 文件、2–16 MiB 日志和 CRLF 文件,确认结果只有内容行、各文件都能命中、正则 `$` 在 CRLF 行尾生效,点击结果跳到匹配列。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -45,5 +45,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva 已接入 Core 项目搜索、掩码与选项、结果跳转和递归监听增量刷新;预览换行、右键入口、列位置、完整视觉对齐及 Windows 整机验收仍待完成。macOS 无头界面和 Windows 监听组件测试不替代两端完整验收。" + "notes": "Viva 已接入 Core 项目搜索、掩码与选项、结果跳转和递归监听增量刷新;结果只列内容行,文件名匹配不再占满 200 条上限;编辑器能打开的 GBK/GB18030、UTF-16、16 MiB 以内的文件和 CRLF 行尾都能搜到(#2198);预览换行、右键入口、列位置、完整视觉对齐及 Windows 整机验收仍待完成。macOS 无头界面和 Windows 监听组件测试不替代两端完整验收。" } diff --git a/shared/platform-feature-matrix/features/search-replace.json b/shared/platform-feature-matrix/features/search-replace.json index b3ac22e94..c34d3f703 100644 --- a/shared/platform-feature-matrix/features/search-replace.json +++ b/shared/platform-feature-matrix/features/search-replace.json @@ -52,5 +52,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva:Replace in Files 由 Core 根据文件和打开文档的未保存文本规划替换(workspace.replacePreview),用户确认预览后宿主应用;打开的文档在编辑器里作为一次可撤销编辑、由用户保存,关闭的文件重新读取、由 Core 替换(workspace.replaceText),仅在内容未变时写回;预览可取消。search_replace_menu_test.go 覆盖入口与预览。" + "notes": "Viva:Replace in Files 由 Core 根据文件和打开文档的未保存文本规划替换(workspace.replacePreview),用户确认预览后宿主应用;打开的文档在编辑器里作为一次可撤销编辑、由用户保存,关闭的文件重新读取、由 Core 替换(workspace.replaceText),仅在内容未变时写回;预览可取消。search_replace_menu_test.go 覆盖入口与预览。 替换预览按去掉 CRLF 行尾 \\r 的行匹配,写回时保留原换行符;按磁盘内容替换时只替换 2 MiB 以内的 UTF-8 文件,搜索能找到的 GBK、UTF-16 和更大的文件不进替换预览(#2199 跟进);有未保存修改的打开文档按编辑器内容替换,不受此限。" }