Skip to content

Commit 0f7ccee

Browse files
jakeleventhalclaude
andcommitted
Address review feedback for the project search overlays
Server - Whole-word matching now greps the bare pattern and filters match ranges by VS Code-style word boundaries, fixing widened highlight spans and dropped adjacent occurrences that consuming (?:^|\W) boundaries caused - Cap grep matches per file (100) so one dense file cannot fill the page - Split the workspace index into path-only and content variants; content indexing now initializes only when content search is used - Entries search accepts an empty query (bounded frecency-ordered listing); content search queries preserve whitespace on the wire - Startup keybinding backfill appends only the defaults that fit instead of evicting the user's oldest custom rules Web - File line reveal retries until contents and line metrics exist and briefly guards the target scroll position against programmatic resets, fixing content-search results opening at the top of the file - Explorer reveal expands slash-keyed directory ancestors, keeps the drag controller's selection cache fresh, and no longer closes an active tree search when the selection originated inside the tree - Content search gates Enter while results are stale and renders result rows in growing windows instead of mounting all 500 at once - File picker's empty state uses the bounded file-only server search (recent files first) instead of transferring the full listing - Command palette exposes "Go to file" and "Search project contents" actions and resolves shortcuts with the complete when-clause context - Content search atoms moved out of the shared client-runtime surface (web-only); dropped the unconsumed EnvironmentApi.searchContents Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 12d9699 commit 0f7ccee

15 files changed

Lines changed: 551 additions & 206 deletions

File tree

‎apps/server/src/keybindings.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,19 +547,24 @@ const make = Effect.gen(function* () {
547547
});
548548
}
549549

550-
const nextConfig = [...customConfig, ...missingDefaults];
551-
const cappedConfig =
552-
nextConfig.length > MAX_KEYBINDINGS_COUNT
553-
? nextConfig.slice(-MAX_KEYBINDINGS_COUNT)
554-
: nextConfig;
555-
if (nextConfig.length > MAX_KEYBINDINGS_COUNT) {
556-
yield* Effect.logWarning("truncating keybindings config to max entries", {
550+
// Startup backfill must never evict persisted user rules: append only
551+
// the defaults that fit and skip the rest.
552+
const availableSlots = Math.max(0, MAX_KEYBINDINGS_COUNT - customConfig.length);
553+
const defaultsToAppend = missingDefaults.slice(0, availableSlots);
554+
const skippedDefaults = missingDefaults.slice(availableSlots);
555+
if (skippedDefaults.length > 0) {
556+
yield* Effect.logWarning("skipping default keybinding backfill at max entries", {
557557
path: keybindingsConfigPath,
558558
maxEntries: MAX_KEYBINDINGS_COUNT,
559+
commands: skippedDefaults.map((rule) => rule.command),
559560
});
560561
}
562+
if (defaultsToAppend.length === 0) {
563+
yield* Cache.invalidate(resolvedConfigCache, resolvedConfigCacheKey);
564+
return;
565+
}
561566

562-
yield* writeConfigAtomically(cappedConfig);
567+
yield* writeConfigAtomically([...customConfig, ...defaultsToAppend]);
563568
yield* Cache.invalidate(resolvedConfigCache, resolvedConfigCacheKey);
564569
}),
565570
);

‎apps/server/src/workspace/WorkspaceEntries.test.ts‎

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,27 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceEntries", (it) => {
223223
}),
224224
);
225225

226+
it.effect("answers an empty file-filtered query with a bounded file listing", () =>
227+
Effect.gen(function* () {
228+
const cwd = yield* makeTempDir({ prefix: "t3code-workspace-empty-query-" });
229+
yield* writeTextFile(cwd, "src/index.ts");
230+
yield* writeTextFile(cwd, "README.md");
231+
232+
const result = yield* searchWorkspaceEntries({
233+
cwd,
234+
query: "",
235+
limit: 10,
236+
kind: "file",
237+
});
238+
239+
const paths = result.entries.map((entry) => entry.path);
240+
expect(paths).toHaveLength(2);
241+
expect(paths).toContain("src/index.ts");
242+
expect(paths).toContain("README.md");
243+
expect(result.entries.every((entry) => entry.kind === "file")).toBe(true);
244+
}),
245+
);
246+
226247
it.effect("returns only directories for the directory filter", () =>
227248
Effect.gen(function* () {
228249
const cwd = yield* makeTempDir({ prefix: "t3code-workspace-directory-filter-" });
@@ -384,37 +405,72 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceEntries", (it) => {
384405
}),
385406
);
386407

387-
it.effect("matches punctuation-ended literal queries as whole words", () =>
408+
it.effect("filters whole-word matches by word boundaries without widening ranges", () =>
409+
Effect.gen(function* () {
410+
const cwd = yield* makeTempDir({ prefix: "t3code-workspace-content-whole-word-" });
411+
yield* writeTextFile(cwd, "src/words.ts", "note notes denote\nfootnote note\n");
412+
413+
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
414+
const result = yield* workspaceEntries.searchContents({
415+
cwd,
416+
query: "note",
417+
limit: 100,
418+
caseSensitive: true,
419+
wholeWord: true,
420+
useRegex: false,
421+
});
422+
423+
// "notes", "denote", and "footnote" are word-adjacent and excluded;
424+
// ranges cover exactly the query, never boundary characters.
425+
expect(result.matches).toEqual([
426+
expect.objectContaining({
427+
path: "src/words.ts",
428+
lineNumber: 1,
429+
matchRanges: [{ start: 0, end: 4 }],
430+
}),
431+
expect.objectContaining({
432+
path: "src/words.ts",
433+
lineNumber: 2,
434+
matchRanges: [{ start: 9, end: 13 }],
435+
}),
436+
]);
437+
}),
438+
);
439+
440+
it.effect("matches punctuation-edged whole-word queries including adjacent occurrences", () =>
388441
Effect.gen(function* () {
389442
const cwd = yield* makeTempDir({ prefix: "t3code-workspace-content-punctuation-" });
390-
yield* writeTextFile(cwd, "src/words.ts", "foo- foo-bar foo-\n");
443+
yield* writeTextFile(cwd, "src/words.ts", "-foo- -foo- -foo-\n");
391444

392445
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
393446
const result = yield* workspaceEntries.searchContents({
394447
cwd,
395-
query: "foo-",
448+
query: "-foo-",
396449
limit: 100,
397450
caseSensitive: true,
398451
wholeWord: true,
399452
useRegex: false,
400453
});
401454

455+
// Consuming-boundary regex would swallow the separating spaces and
456+
// drop the middle occurrence; boundary post-filtering keeps all three.
402457
expect(result.matches).toHaveLength(1);
403458
expect(result.matches[0]).toMatchObject({
404459
path: "src/words.ts",
405460
lineNumber: 1,
406461
matchRanges: [
407-
{ start: 0, end: 4 },
408-
{ start: 13, end: 17 },
462+
{ start: 0, end: 5 },
463+
{ start: 6, end: 11 },
464+
{ start: 12, end: 17 },
409465
],
410466
});
411467
}),
412468
);
413469

414-
it.effect("matches punctuation-ended regex queries as whole words", () =>
470+
it.effect("matches punctuation-edged regex queries as whole words", () =>
415471
Effect.gen(function* () {
416472
const cwd = yield* makeTempDir({ prefix: "t3code-workspace-content-regex-punctuation-" });
417-
yield* writeTextFile(cwd, "src/words.ts", "foo- foo-bar foo-\n");
473+
yield* writeTextFile(cwd, "src/words.ts", "foo- foo-\nafoo-b\n");
418474

419475
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
420476
const result = yield* workspaceEntries.searchContents({
@@ -426,13 +482,43 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceEntries", (it) => {
426482
useRegex: true,
427483
});
428484

429-
// wholeWord + useRegex must not silently drop non-word-edged patterns like "foo-"
485+
// wholeWord + useRegex must not silently drop non-word-edged patterns
486+
// like "foo-", and "afoo-" is excluded because 'a'/'f' are both word
487+
// characters at the match's left edge.
430488
expect(result.matches).toHaveLength(1);
431489
expect(result.matches[0]).toMatchObject({
432490
path: "src/words.ts",
433491
lineNumber: 1,
492+
matchRanges: [
493+
{ start: 0, end: 4 },
494+
{ start: 5, end: 9 },
495+
],
496+
});
497+
}),
498+
);
499+
500+
it.effect("caps matches per file so one dense file cannot fill the page", () =>
501+
Effect.gen(function* () {
502+
const cwd = yield* makeTempDir({ prefix: "t3code-workspace-content-per-file-cap-" });
503+
yield* writeTextFile(cwd, "src/dense.ts", "needle\n".repeat(300));
504+
yield* writeTextFile(cwd, "src/other.ts", "needle\n");
505+
506+
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
507+
const result = yield* workspaceEntries.searchContents({
508+
cwd,
509+
query: "needle",
510+
limit: 500,
511+
caseSensitive: true,
512+
wholeWord: false,
513+
useRegex: false,
434514
});
435-
expect(result.matches[0]?.matchRanges).toHaveLength(2);
515+
516+
const byPath = new Map<string, number>();
517+
for (const match of result.matches) {
518+
byPath.set(match.path, (byPath.get(match.path) ?? 0) + 1);
519+
}
520+
expect(byPath.get("src/dense.ts")).toBe(100);
521+
expect(byPath.get("src/other.ts")).toBe(1);
436522
}),
437523
);
438524

‎apps/server/src/workspace/WorkspaceEntries.ts‎

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -154,33 +154,37 @@ export const make = Effect.gen(function* () {
154154
const normalizedCwd = yield* normalizeWorkspaceRoot(cwd).pipe(
155155
Effect.orElseSucceed(() => cwd),
156156
);
157-
if (!(yield* RcMap.has(workspaceSearchIndexes.rcMap, normalizedCwd))) {
158-
return;
159-
}
160-
const recoverRefreshFailure = (
161-
cause:
162-
| WorkspaceSearchIndex.WorkspaceSearchIndexCreateFailed
163-
| WorkspaceSearchIndex.WorkspaceSearchIndexScanTimedOut
164-
| WorkspaceSearchIndex.WorkspaceSearchIndexRefreshFailed,
165-
) =>
166-
Effect.gen(function* () {
167-
yield* Effect.logWarning("Failed to refresh workspace search index", {
168-
cwd,
169-
cause,
157+
for (const variant of WorkspaceSearchIndex.WORKSPACE_SEARCH_INDEX_VARIANTS) {
158+
const indexKey = WorkspaceSearchIndex.workspaceSearchIndexKey(normalizedCwd, variant);
159+
if (!(yield* RcMap.has(workspaceSearchIndexes.rcMap, indexKey))) {
160+
continue;
161+
}
162+
const recoverRefreshFailure = (
163+
cause:
164+
| WorkspaceSearchIndex.WorkspaceSearchIndexCreateFailed
165+
| WorkspaceSearchIndex.WorkspaceSearchIndexScanTimedOut
166+
| WorkspaceSearchIndex.WorkspaceSearchIndexRefreshFailed,
167+
) =>
168+
Effect.gen(function* () {
169+
yield* Effect.logWarning("Failed to refresh workspace search index", {
170+
cwd,
171+
variant,
172+
cause,
173+
});
174+
yield* workspaceSearchIndexes.invalidate(indexKey);
170175
});
171-
yield* workspaceSearchIndexes.invalidate(normalizedCwd);
172-
});
173-
yield* Effect.gen(function* () {
174-
const searchIndex = yield* WorkspaceSearchIndex.WorkspaceSearchIndex;
175-
yield* searchIndex.refresh();
176-
}).pipe(
177-
Effect.provide(workspaceSearchIndexes.get(normalizedCwd)),
178-
Effect.catchTags({
179-
WorkspaceSearchIndexCreateFailed: recoverRefreshFailure,
180-
WorkspaceSearchIndexScanTimedOut: recoverRefreshFailure,
181-
WorkspaceSearchIndexRefreshFailed: recoverRefreshFailure,
182-
}),
183-
);
176+
yield* Effect.gen(function* () {
177+
const searchIndex = yield* WorkspaceSearchIndex.WorkspaceSearchIndex;
178+
yield* searchIndex.refresh();
179+
}).pipe(
180+
Effect.provide(workspaceSearchIndexes.get(indexKey)),
181+
Effect.catchTags({
182+
WorkspaceSearchIndexCreateFailed: recoverRefreshFailure,
183+
WorkspaceSearchIndexScanTimedOut: recoverRefreshFailure,
184+
WorkspaceSearchIndexRefreshFailed: recoverRefreshFailure,
185+
}),
186+
);
187+
}
184188
},
185189
);
186190

@@ -242,7 +246,13 @@ export const make = Effect.gen(function* () {
242246
return yield* Effect.gen(function* () {
243247
const searchIndex = yield* WorkspaceSearchIndex.WorkspaceSearchIndex;
244248
return yield* searchIndex.search(normalizedQuery, input.limit, input.kind);
245-
}).pipe(Effect.provide(workspaceSearchIndexes.get(normalizedCwd)));
249+
}).pipe(
250+
Effect.provide(
251+
workspaceSearchIndexes.get(
252+
WorkspaceSearchIndex.workspaceSearchIndexKey(normalizedCwd, "paths"),
253+
),
254+
),
255+
);
246256
},
247257
);
248258

@@ -253,7 +263,13 @@ export const make = Effect.gen(function* () {
253263
return yield* Effect.gen(function* () {
254264
const searchIndex = yield* WorkspaceSearchIndex.WorkspaceSearchIndex;
255265
return yield* searchIndex.searchContents(input);
256-
}).pipe(Effect.provide(workspaceSearchIndexes.get(normalizedCwd)));
266+
}).pipe(
267+
Effect.provide(
268+
workspaceSearchIndexes.get(
269+
WorkspaceSearchIndex.workspaceSearchIndexKey(normalizedCwd, "content"),
270+
),
271+
),
272+
);
257273
});
258274

259275
const list: WorkspaceEntries["Service"]["list"] = Effect.fn("WorkspaceEntries.list")(
@@ -262,7 +278,13 @@ export const make = Effect.gen(function* () {
262278
return yield* Effect.gen(function* () {
263279
const searchIndex = yield* WorkspaceSearchIndex.WorkspaceSearchIndex;
264280
return yield* searchIndex.list();
265-
}).pipe(Effect.provide(workspaceSearchIndexes.get(normalizedCwd)));
281+
}).pipe(
282+
Effect.provide(
283+
workspaceSearchIndexes.get(
284+
WorkspaceSearchIndex.workspaceSearchIndexKey(normalizedCwd, "paths"),
285+
),
286+
),
287+
);
266288
},
267289
);
268290

0 commit comments

Comments
 (0)