TypeScript
fix(server): project content search finds matches past a line's first 512 characters (#29167)
Alex Southwell8430db67328c
diff --git a/apps/server/src/workspace/WorkspaceEntries.test.ts b/apps/server/src/workspace/WorkspaceEntries.test.tsindex d861935fe17..154a260eea0 100644--- a/apps/server/src/workspace/WorkspaceEntries.test.ts+++ b/apps/server/src/workspace/WorkspaceEntries.test.ts@@ -675,6 +675,29 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {}),);+ it.effect("keeps matches past the truncated part of a long line", () =>+ Effect.gen(function* () {+ const cwd = yield* makeTempDir({ prefix: "t3code-workspace-content-long-line-" });+ yield* writeTextFile(cwd, "dist/app.min.js", `${"x".repeat(600)} needleSuffix\n`);++ const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;+ const search = (wholeWord: boolean) =>+ workspaceEntries.searchContents({+ cwd,+ query: "needle",+ limit: 100,+ caseSensitive: true,+ wholeWord,+ useRegex: false,+ });++ expect((yield* search(false)).matches).toEqual([+ expect.objectContaining({ path: "dist/app.min.js", lineNumber: 1 }),+ ]);+ expect((yield* search(true)).matches).toEqual([]);+ }),+ );+it.effect("keeps answering from the live index when a refresh outlasts the scan wait", () =>Effect.gen(function* () {const cwd = yield* makeTempDir({ prefix: "t3code-workspace-content-refresh-" });diff --git a/apps/server/src/workspace/WorkspaceSearchIndex.ts b/apps/server/src/workspace/WorkspaceSearchIndex.tsindex d5539e2f4e7..8b8782b2005 100644--- a/apps/server/src/workspace/WorkspaceSearchIndex.ts+++ b/apps/server/src/workspace/WorkspaceSearchIndex.ts@@ -505,7 +505,8 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (const matchRanges = mapContentMatchRanges(match.lineContent, match.matchRanges).filter((range) => !input.wholeWord || isWholeWordRange(match.lineContent, range),);- if (matchRanges.length === 0) continue;+ // fff reports hits past its 512-char lineContent cap with no ranges, so whole words can't be verified there.+ if (input.wholeWord && matchRanges.length === 0) continue;matches.push({path: toPosixPath(match.relativePath),lineNumber: match.lineNumber,