fix(fs-search): direct-open for pasted paths + fragment path matching (#879)
A query carrying a path separator can never match an entry NAME — names
never contain separators — so pasting any path into the search box was
structurally guaranteed to return {matches:[],truncated:true} while the
walk burned its full 100k-visit budget (measured: 1.9s on a Rust repo
whose two worktree forests alone held 97k entries; real directories were
never reached).
searchFiles now routes by query shape, all three modalities sharing one
result contract:
- A query naming one path (absolute, ~/…, ./x, ../x) resolves through
resolveTarget — the SAME primitive fs.read uses, so ~ expands (#713),
dot-anchored spellings join onto the session cwd, and win32
WSL/dsh-remote namespaces reinterpret — then stats the target. The hit
is the RESOLVED path (resolve() strips shell-completion trailing
separators, which the client's exact-string row comparisons could never
match); a missing target answers empty immediately. Directory targets
ride the #801 dirs contract. The exclude pref does not apply: a pasted
path is explicit intent, same as the fs.read the click performs.
- A separator-carrying relative fragment (records/exp1) matches by
root-relative PATH in the walk; the engines are name matchers (fd has
no --full-path here, rg's globs are single-segment) so argv
construction is untouched.
- Plain name queries are unchanged, and no NAME query is stolen: on
POSIX a backslash is a name character (the ~\ gesture counts only on
win32; util.ts~ / ~$doc.docx / .env stay name queries).
SKIP_DIR_NAMES gains the budget-eating forests seen in the wild:
.worktrees/.worktree (git worktree layouts), target, venv/.venv and
__pycache__ — shared by the walk and both engine argvs as before.
Client: a directory hit OUTSIDE the cwd (newly reachable via the paste
branch) only clears the query — the tree is cwd-rooted, and the old
ancestorDirs call synthesized junk expanded entries for foreign paths.
Verified: vitest fs-search/smoke/search-persist suites green; full run
2171 passed with one failure proven pre-existing on the clean tree
(git.spec checkout case, host git lacks --end-of-options; #841);
typecheck/lint clean.
This commit is contained in:
1 parent
4e51e0789c
commit
0d9fee85b8
12 files changed
+471
-56
No files matched your search
@@ -31,7 +31,7 @@ import { IconUploadOutline16 } from './icons.tsx'
|
||||
import type { OpenInApp } from './open-in-app.ts'
|
||||
import type { OpenWithTarget } from './open-with.ts'
|
||||
import { t } from './locales.ts'
|
||||
import { resolveSidebarPath } from './paths.ts'
|
||||
import { isWithinWorkspace, resolveSidebarPath } from './paths.ts'
|
||||
import { IconButton } from './ui/index.ts'
|
||||
import { UploadOverlay } from './UploadOverlay.tsx'
|
||||
import {
|
||||
@@ -230,9 +230,14 @@ export function TreePanel(props: {
|
||||
* paths are touched — and clear the query so the tree, not the parked
|
||||
* results panel, is what the user sees next.
|
||||
*/
|
||||
// A directory hit OUTSIDE the cwd (a pasted absolute path from the
|
||||
// direct-open branch) has no tree rows to expand: the tree is cwd-rooted,
|
||||
// and `ancestorDirs` would synthesize cwd-length prefixes of a foreign
|
||||
// path that toggle nothing and persist as junk `expanded` entries. Such a
|
||||
// row only clears the query.
|
||||
const openSearchDir = (rel: string): void => {
|
||||
const target = resolveSidebarPath(cwd, rel)
|
||||
if (cwd !== undefined) {
|
||||
if (cwd !== undefined && isWithinWorkspace(cwd, target)) {
|
||||
for (const path of [...ancestorDirs(cwd, [target]), target]) {
|
||||
if (!expanded.includes(path)) onToggle(path)
|
||||
}
|
||||
|
||||
+10
-6
@@ -356,12 +356,16 @@ export const api = {
|
||||
*/
|
||||
fsTrees: (scope: SessionScope, paths: readonly string[], exclude?: readonly string[], signal?: AbortSignal) =>
|
||||
call<{ levels: FsLevel[] }>('fs.trees', scopePayload(scope, { paths: [...paths], exclude }), signal),
|
||||
/** Global recursive file-name search rooted at the session cwd (the editor
|
||||
* side panel's search box); matches are cwd-relative '/'-separated paths,
|
||||
* and `dirs` names the subset that is a directory (the list navigates the
|
||||
* tree for those — `fs.read` refuses a directory). `exclude` carries the
|
||||
* explorerExclude pref: matched entries never match and are never
|
||||
* descended (host-side, in lockstep with the tree). */
|
||||
/** Global recursive file search rooted at the session cwd (the editor
|
||||
* side panel's search box). A name query matches cwd-relative
|
||||
* '/'-separated paths; a separator-carrying fragment matches by PATH;
|
||||
* a query naming one path (absolute, `~/…`, `./x`, `../x`) is stat'ed
|
||||
* through the same resolution fs.read uses and yields the RESOLVED
|
||||
* absolute target as the single match. `dirs` names the subset that is a
|
||||
* directory (the list navigates the tree for those — `fs.read` refuses a
|
||||
* directory). `exclude` carries the explorerExclude pref: matched entries
|
||||
* never match and are never descended (host-side, in lockstep with the
|
||||
* tree; a pasted direct-open path is explicit intent and skips it). */
|
||||
fsSearch: (scope: SessionScope, query: string, exclude?: readonly string[], signal?: AbortSignal) =>
|
||||
call<{ matches: string[]; dirs: string[]; truncated: boolean }>('fs.search', scopePayload(scope, { query, exclude }), signal),
|
||||
fsRead: (scope: SessionScope, path: string, signal?: AbortSignal) =>
|
||||
|
||||
Reference in new issue
Block a user