feat(search): fs.search 文件名搜索优先用 fd/rg,缺失/失败回退 JS 遍历
issue #203:十万级目录下纯 JS 递归遍历是秒级,10 万条访问预算一顶结果 还被静默截断。现在启动后惰性探测一次本机 fd / rg(每个候选 `--version` 500ms 内验证通过才算数,进程内缓存),探到就用引擎输出,探不到或运行失败 整段回退原来的遍历(导出为 `searchFilesPlain`);坏二进制在进程内禁用, 超时只降级本次(树大 ≠ 二进制坏)。 为什么按 dev 现状重写而不是机械解冲突(PR #303 的落点全部复核过): - **#801 的必填 `dirs` 是语义级冲突,必须扩引擎契约**。dev 的 `FsSearchResult` 多了 `dirs`(`TreePanel` 用它把命中行当目录导航,否则 `fs.read` 报 “is a directory”),而 PR 的引擎侧只产出 `{paths, truncated}`,`searchFilesPlain` 的空查询也还在返回两字段形状; 照搬会让 #801 修的 bug 在引擎路径上静默回退。收口:fd 用第二次 `--type d` 调用取目录子集(fd 自己不做标注),rg 由文件路径倒推匹配的 目录段(`deriveRgMatches`),dispatch 再把 `dirs` 收敛成 `matches` 的 子集。残留差异只有**空目录在 rg 下不可见**(没有文件路径能带上它)。 - **rg 的路径级 glob 补成三个**:PR 的 `**/*<q>*/**` 缺一个直接子文件 (`util/helper.ts` 是最常见形态),只加 `**` 会让这类目录命中在 rg-only 机器上凭空消失;`**/*<q>/*` + `**/*<q>/**` 两条并用(对真实 rg 15 实测:单用任一条都丢结果)。 - **`bundledRgCandidates` 的路径推导按真机布局改写**:npm/pnpm 把 `@vscode/ripgrep-<platform>-<arch>` 提升到 `@deepseek-ai` 的**同级**, 不存在 `<root>/@deepseek-ai/dsh/node_modules/@vscode/...`;候选根改成 「从 CLI 入口(argv[1])向上逐级 `node_modules`」+ 各包管理器全局前缀, 桌面壳那种「自带依赖树 + 外部 node」的布局才探得到捆绑 rg(实测命中)。 - **丢掉 abort 形参**:`src/index.ts` 的生产路径不传 signal(PR 里也只有 测试在用),单为测试保留一条贯穿三层的通道不划算;引擎子进程由 15s 内部超时兜底。 - **文档锚点按 dev 重锚**:README 的 v0.12.3 条目已随发布历史迁到 CHANGELOG(新增 Unreleased 条目),AGENTS §2 的引擎门禁入口挂到现有 ci-windows 段落,指南 §14 参考实现行补 `src/search-engines.ts`。 - 未新增任何依赖:`@vscode/ripgrep` 只作为**路径**探测,不做模块导入。 Windows 侧由既有 ci-windows lane 承载:`choco install fd ripgrep` 把真 二进制放进 PATH,套件后 `pnpm check:engines`(`scripts/win-engine-check.mjs --assert`,import `src/search-engines.ts` 取插件自己的 argv)断言 `--path-separator /` 的输出不含 `\`/CR、非 ASCII 文件名命中;引擎缺失则 跳过(fd 在 ubuntu lane 与多数开发机上都没有)。 测试:`tests/search-engines.spec.ts`(探测缓存 / 运行失败禁用 / 超时不禁 用 / argv 对称性与噪声目录排除 / `deriveRgMatches` / 捆绑 rg 候选推导 / 真引擎在场时的端到端——缺席即返回),`tests/fs-search.spec.ts` 拆成 「直接钉遍历」+「注入假引擎的 dispatch 组」(引擎优先、`dirs` 透传与 子集收敛、预算透传、运行失败回退并禁用)。真机核对:本仓库上 rg 路径与 JS 遍历对 `locales` / `util` / `client` / `src` / `e2e` 五个查询的 matches 与 dirs **逐项一致**。 Refs #303 Co-authored-by: Cold Cloud <64406210+yanzhaohui1999@users.noreply.github.com>
This commit is contained in:
1 parent
3bd5e1947b
commit
194099e7f3
11 files changed
+1367
-55
No files matched your search
@@ -63,6 +63,12 @@ jobs:
|
||||
# runs the same typecheck / test / build / consumer-type-surface steps on
|
||||
# a real Windows runtime. The plugin-mount lane (real DSH + Playwright
|
||||
# Chromium) stays ubuntu-only and is deliberately NOT mirrored here.
|
||||
#
|
||||
# It also carries the search-engine gate: real fd/ripgrep binaries land on
|
||||
# PATH (choco) before the suite runs, and the output-shape assertions run
|
||||
# against them afterwards. Windows is where the engine output format bites
|
||||
# hardest (backslash separators, CR line endings, console code pages);
|
||||
# docs/ci-windows.md holds the red lines.
|
||||
ci-windows:
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 30
|
||||
@@ -90,6 +96,12 @@ jobs:
|
||||
run: |
|
||||
git config --global user.name "dsh-better-sidebar-ci"
|
||||
git config --global user.email "ci@dsh.invalid"
|
||||
# Real engine binaries for the output-shape assertions below. The probe
|
||||
# inside src/search-engines.ts reads PATH, so the whole suite runs with
|
||||
# engines present here; the specs never depend on that (they inject
|
||||
# their own probes, and the one real-engine case skips when absent).
|
||||
- name: Install fd / ripgrep (choco)
|
||||
run: choco install fd ripgrep -y --no-progress
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
- name: Typecheck
|
||||
@@ -122,6 +134,13 @@ jobs:
|
||||
run: pnpm build
|
||||
- name: Check consumer type surface
|
||||
run: pnpm check:consumer-types
|
||||
# Output-shape assertions on the REAL engine binaries installed above:
|
||||
# the plugin's own argv must produce '/'-separated, CR-free paths and
|
||||
# hit a non-ASCII file name. An engine that is absent skips (so the
|
||||
# script stays runnable on a dev machine); an assertion failure exits
|
||||
# non-zero.
|
||||
- name: Engine output-shape assertions (real fd/rg)
|
||||
run: pnpm check:engines
|
||||
|
||||
# Pack the plugin as an npm tarball, mount it into a REAL DSH instance
|
||||
# through the official `dsh plugin --profile web add` channel, and render
|
||||
|
||||
Reference in new issue
Block a user