Repository navigation
fix(search): 在文件中查找只列内容行,并固定能搜到各种编码、大文件和 CRLF 的 Core (#2198) - #2205
Merged
Merged
Conversation
- 项目搜索请求带 maxFileResults: 0,文件名匹配不再占满 200 条上限、挤掉内容行 - WorkspaceSearchRequest 新增可选 MaxFileResults - Core 固定版本升到 ce628c7(Lithe-core-rust#116):搜索按编辑器的编码识别读文件、 上限 16 MiB、跳过二进制、CRLF 行尾不算行内容 - 回归测试:大量同名文件时只列内容行;GBK 和 CRLF 文件能用正则搜到,打开结果光标落在匹配处 - Agent Note 与功能矩阵(search-project、search-replace)同步 Closes #2198
1 task done
xiaoyumuxi
marked this pull request as ready for review
November 19, 2026 11:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
“在文件中查找”(Cmd/Ctrl+Shift+F)经常漏掉明明存在的内容。#2198 用探针复现了四个原因:
workspace.search时没传maxFileResults。Core 会先收集文件名匹配,文件名含查询词的文件一多(例如搜handler,项目里有 200 多个handler*.go),200 条结果全是文件名,一条内容行都不剩。\r留在行里,foo$这类正则在 Windows 换行的文件里匹配不到。第 2–4 条已在 Lithe-core-rust#116 修复并合入(ce628c7),本 PR 修第 1 条,并把 Core 固定版本升到 ce628c7。
改动 / Changes
desktop/internal/workbench/search.go):项目搜索请求带maxFileResults: 0。和 IDEA 的 Find in Files 一样,结果只列包含查询词的行;文件名含查询词的文件不再出结果,也不再占用 200 条上限。查文件名请用全局搜索的“文件”。desktop/internal/core/workspace.go):WorkspaceSearchRequest新增可选的MaxFileResults *int(json:"maxFileResults,omitempty")。nil时行为不变,0表示只要内容匹配。现在只有项目搜索在用它。scripts/desktop/build-desktop-core.sh):PINNED_CORE_REVISION从 0b6da27 升到 Lithe-core-rustmain的 ce628c7([Feature] 添加本地文件历史的记录 #116),注释写明了新带进来的 Core PR。desktop/internal/workbench/search_test.go):TestProjectSearchListsContentLinesWhenManyFileNamesMatch:250 个handler*.go加一个内容含handler的文件,结果只能是那一行内容。TestProjectSearchFindsLinesInEveryFileTheEditorOpens:用正则Needle417$搜 GBK 文件和 CRLF 文件,两个文件都要命中。打开 GBK 那条结果后,光标要落在匹配处(第 0 行第 10 字节),确认 Core 和编辑器对同一文件的解码一致。.agents/notes/implemented/feature/2026-11-08-viva-project-search.md):写明项目搜索只列内容行、搜索读哪些文件由 Core 决定;补一条被否方案“文件名匹配排在内容行之后”。search-project:备注写明本次修复;验证动作补上“大量同名文件、GBK/UTF-16、2–16 MiB 日志、CRLF”的核对步骤。search-replace:备注写明替换在 CRLF 上的行为和只替换 UTF-8 文件的限制。search-project两端仍是partial,search-replace两端仍是implemented。没有做原生验收,验证状态保持pending。不在本 PR 范围内 / Out of scope
replacementText按 UTF-8 写回,直接替换会改掉文件编码。有未保存修改的已打开文档按编辑器内容替换,不受这个限制。按原编码写回在 [Feature] 全局搜索对齐 IntelliJ IDEA:分页分组、搜索范围、未保存内容、随处搜索名称匹配 #2199 跟进。类型专属:fix
复现与根因
handler*.go的项目里,在文件中查找handler。实际只列出 200 个文件名,没有一条内容行;期望列出所有含handler的行。foo$搜 CRLF 文件,实际都没有结果;期望命中。desktop/internal/workbench/search.go)调用workspace.search就没有传maxFileResults,Core 的文件名循环先跑,把共用的maxResults用完了。read_to_string读文件,上限 2 MB,分行后没有去掉\r。已在 Core [Feature] 添加本地文件历史的记录 #116 修复。检查项
desktop/internal/workbench/search_test.go的TestProjectSearchListsContentLinesWhenManyFileNamesMatch,修复前输出search_test.go:70: got 200 results, want only the content line。TestProjectSearchFindsLinesInEveryFileTheEditorOpens依赖新 Core;同样的 GBK 和 CRLF 场景在 Core [Feature] 添加本地文件历史的记录 #116 的回归测试里已验证修复前失败、修复后通过。WorkspaceSearchRequest{只在项目搜索一处构造;全局搜索走workspace.searchEverywhere,不受影响;替换流程不使用搜索结果。.agents/notes/implemented/bug-fix/记录:行为约束写进了项目搜索的现有 Agent Note(feature/2026-11-08-viva-project-search.md),并补了被否方案,没有另开 bug-fix 笔记。范围检查 / Scope checks
功能矩阵 / Feature matrix
shared/platform-feature-matrix/features/<id>.json:search-project.json和search-replace.json的备注和验证动作已更新;没有运行原生验证,两端验证状态保持pending./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh;改了平台实现路径的,还运行了./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD.artifacts/下生成的矩阵视图插件归属 / Plugin ownership
develop-lithe第三节“插件归属与宿主零依赖”的自查命令,结果为空shared/i18n/;没有改构建资源说明UI 验证 / UI evidence
N/A:没有改布局、控件、样式或文案。结果行的渲染不变,只是不再出现文件名行;行为由无头测试覆盖。
统一日志系统 / Structured logging
N/A:没有新增或改动生命周期、终态、降级或失败路径的日志。
界面文案 / i18n
N/A:没有新增或修改用户可见文案。仍运行了两项 i18n 检查,均通过(见“验证”)。
逻辑归属 / Logic placement
性能与内存 / Performance and memory
本机 Apple M4,在
desktop/下运行../scripts/desktop/desktop-go.sh test ./internal/core -run '^$' -bench '^BenchmarkWorkspaceSearchIndex$' -count=5。这个基准建 2000 个小 Go 文件,搜needle,maxResults设为 200。改动前把PINNED_CORE_REVISION临时改回 0b6da27,先单独编译一次再计时;测完已改回 ce628c7。表里是 5 轮的中位数:两项差异都在 5 轮的波动范围内,内存和分配次数不变。
maxFileResults: 0后,Core 跳过文件名收集,工作量只会变少。基准没有设这个字段,所以这部分没体现在数字里。editor-bench.sh。设置 / Settings
N/A:没有改设置。
插件契约 / Plugin contract
rust/contracts/rust-core-api.md),字段不变scripts/desktop/build-desktop-core.sh的PINNED_CORE_REVISION已升到 Coremain的 ce628c7发行包与资源 / Bundle and resources
./scripts/desktop/verify/verify-runtime-bundle-immutability.sh通过无用代码与重构 / Dead code and refactoring
search_view.go、search.go里处理Line == nil的分支保留:searchMatchLabel和openSearchResult接收的是通用的WorkspaceSearchMatch,这些分支是对 Core 返回值的防御验证 / Verification
TestProjectSearchListsContentLinesWhenManyFileNamesMatchgot 200 results, want only the content linedesktop/下../scripts/desktop/desktop-go.sh test -count=1 ./...workbench256 s。localshell的TestClosingAnIntegratedShellHangsUpTheShellAndItsJobs在全量并发负载下失败一次(the shell's job … outlived the closed terminal by 5s);单独-count=3重跑和整包重跑都通过。本改动没有碰终端代码desktop-go.sh test -race -count=1 ./internal/workbench/ ./internal/core/.agents/skills/write-stable-tests/scripts/test-stability-macos.sh --package ./internal/workbench/ --filter <两个新测试>gofmt -l、desktop-go.sh vet ./internal/core/ ./internal/workbench/BenchmarkWorkspaceSearchIndex改动前后对比./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD.agents/skills/write-stable-tests/scripts/verify-test-stability.sh --base origin/mainnode scripts/i18n/generate-i18n.mjs --check、node scripts/i18n/verify-app-language-localization.mjs./scripts/desktop/verify/verify-runtime-bundle-immutability.sh./scripts/agent-notes/verify-agent-notes.shdevelop-lithe第三节插件归属自查命令未能执行的检查和原因:
pending。提交前确认 / Final checks
main(f4c6943b3),目标分支maingo test退出,没有进程残留