Problem#
While the content index is still building, content search falls back to git grep. That path cut each line to 512 characters before it looked for matches. On longer lines (minified JS, JSON, CSS) this caused three problems:
- A whole-word match past column 512 was dropped from whole-word results.
- A word cut at column 512 (
token of tokenized) counted as a whole word.
- Regex results got empty
[512, 512] ranges, or ranges cut off at 512, from git's byte offsets past the cut.
Change#
The fallback now matches and checks whole words on the full line. It still shows the first 512 characters and keeps only the ranges that fit inside them, which is what fff does with its own 512 cap.
Regex ranges are found by their text, starting from git's first column, so a long line with many matches stays linear. This also keeps highlights in two cases:
- CRLF lines whose match runs into the
\r.
- Lines with invalid UTF-8 before the match.
When git runs outside a UTF-8 locale and matches part of a character, the range falls back to git's byte column, as before.
Once the index is ready, fff still drops whole-word hits past its cap, because it returns no range for them. This PR does not change that.
Scope#
This is a bug fix in one function, searchContentsWithGit. There is no issue for it: the wrong results reproduce directly in the existing git grep warmup test against a real repository, shown below.
Verification#
An AI agent ran each check below.
vp test run src/workspace/WorkspaceSearchIndex.test.ts: 18/18 pass. New assertions extend the existing git grep warmup test. They cover long lines (whole-word, regex, split words, a multi-byte prefix), CRLF regex ranges, a bare \r match, invalid UTF-8, a -o record whose column no longer points at its text, and a partial-character match under LC_ALL=C. Each one fails on main, except the LC_ALL=C case, which main already passes; it keeps the fallback working.
vp run check:changed: format, lint, knip, typecheck and tests pass.
- Real git 2.53 on a file with the lines
" " * 600 + "token", " " * 507 + "tokenized" and "é token " + "d" * 600 + " token". Each entry is the line number and its match ranges:
| Search | 8222562 (main) | 9468077 (this PR) |
|---|
whole-word token | line 2 [507,512] (a split word), line 3 [2,7]; line 1 missing | line 1 [], line 3 [2,7] |
regex whole-word tok+en | same as above | same as above |
regex tok+en\w* | line 1 [512,512], line 2 [507,512], line 3 [2,7] | line 1 [], line 2 [], line 3 [2,7] |
- A 2M-character line with 500k regex matches maps its ranges in about 50 ms. A literal search that isn't whole-word still only scans the shown 512 characters.
Not checked: the fff indexed path, which this PR does not touch.
Generated with Claude Opus 5.5 in T3 Code Nightly
Walkthrough
Git-backed workspace content search now converts match positions to JavaScript string ranges and handles CRLF lines and displayed-line limits. Tests cover stale Git columns, invalid UTF-8 bytes, partial multibyte matches, and long lines.
Changes: Content search ranges
apps/server/src/workspace/WorkspaceSearchIndex.ts,apps/server/src/workspace/WorkspaceSearchIndex.test.tslocateRegexMatchesconverts Git byte columns and match lengths to JavaScript string-index ranges. Tests cover stale columns and matches involving invalid or multibyte UTF-8.apps/server/src/workspace/WorkspaceSearchIndex.ts,apps/server/src/workspace/WorkspaceSearchIndex.test.tsEstimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Suggested reviewers:
juliusmarmingeMerge Risk:
Low · up to
a6b59Merge Risk: 🔵 Low · up to
a6b59Content search while indexing now checks long lines in full. Very long lines with many whole-word matches may cost extra CPU time, but results stay correct. The risk is low, and an optional follow-up can bound the allocation.
Pre-merge checks:
4
Full details: Title check
Explanation
The title "fix(server): content search while indexing checks long lines in full" matches the main change: the git grep fallback used while the index builds now matches and checks whole words on the full line instead of the 512-character prefix. It is a conventional commit title in plain language and names the component and the behavior changed.
Full details: Description check
Explanation
The description follows the template's sections: Problem, Change, Scope, and Verification. The Problem section gives the expected behavior and the three concrete failures on long lines. The Change section explains the fix and its limits, including the unchanged fff indexed path. The Scope section states this is a bug fix in one function and explains why no issue is linked. The Verification section lists focused test results, a real-git comparison table, a timing result, and what was not checked. It also names the agent and model, as the template requests. The template's HTML comments are removed, which is acceptable. One minor gap: the Scope section gives a reason for having no issue, which the template allows for small obvious fixes, so this is acceptable.
Finishing Touches
Generate unit tests (beta)