Fall back to full file content for local regex filtering - #154
Conversation
0a9020d to
a3953c8
Compare
|
Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 similar comment
|
Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
Adds full-file fallback support for local regex filtering when GitHub fragments are insufficient.
Changes:
- Adds optional
CodeMatch.fileContent. - Propagates fetched raw content.
- Implements full-content fallback matching and context extraction.
- Adds regression and compatibility tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Review comments |
|---|---|
src/types.ts |
Adds optional raw-content support; no issues noted. |
src/api.ts |
Moderate: avoid retaining raw content for non-regex queries (3 votes). Nit: add API tests for propagation and failed fetches (4 votes). |
src/aggregate.ts |
Moderate: avoid repeated full-prefix rescans (3 votes). Moderate: preserve matches spanning beyond the display window (4 votes). |
src/aggregate.test.ts |
Adds fallback and compatibility coverage; no issues noted. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| updatedTextMatches = [...findMatchLines(fileContent, globalRe)] | ||
| .map((matchLine) => { | ||
| const { fragment, fragmentStartLine } = sliceContextWindow(fileContent, matchLine); | ||
| const segs = recomputeSegments(fragment, globalRe, fragmentStartLine); | ||
| return segs.length > 0 ? { fragment, matches: segs } : null; |
a3953c8 to
322e43c
Compare
|
Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 similar comment
|
Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
aggregate() previously tested the local regex filter only against TextMatch.fragment, the truncated excerpt returned by the GitHub API. If that excerpt did not cover the full portion matched by the regex, the repository was silently dropped even though the actual file matched. fetchAllResults() already downloads the raw file content from raw.githubusercontent.com to resolve absolute line numbers; it now propagates that content into CodeMatch.fileContent (src/types.ts) instead of discarding it. aggregate() falls back to matching against fileContent, and builds a small context window around each match for display, only when none of the API-provided fragments matched. No new network calls, and behaviour is unchanged when fileContent is absent or when the fragment already matches. Closes #148
322e43c to
a818982
Compare
|
Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 similar comment
|
Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- aggregate.ts: replace the O(n*m) prefix-rescan findMatchLines/sliceContextWindow pair with fallbackMatchesFromFullContent, which finds every match in a single forward pass over the full file content and expands the display window to always contain the match's full span, so matches longer than the +/-2 line window (or reached via lookaround) are no longer silently dropped. - api.ts: fetchAllResults now only retains raw fileContent on CodeMatch when the new keepFileContent flag is set, avoiding keeping every downloaded file in memory for ordinary (non-regex) queries. - github-code-search.ts: pass keepFileContent=true only when a regex filter is active. - Add regression tests: aggregate.test.ts covers matches spanning beyond the context window and multiple distinct matches; api.test.ts covers the fileContent handoff from fetchAllResults (success, failure, opt-out). See #154 (comment) See #154 (comment) See #154 (comment) See #154 (comment)
|
Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
What does this PR do?
Closes #148.
aggregate()previously tested the local regex filter only againstTextMatch.fragment, the truncated excerpt returned by the GitHub API. If that excerpt did not cover the full portion matched by the regex, the repository was silently dropped even though the actual file matched.fetchAllResults()already downloads the raw file content from raw.githubusercontent.com to resolve absolute line numbers; it now propagates that content into the new optionalCodeMatch.fileContentfield (src/types.ts) instead of discarding it.aggregate()falls back to matching againstfileContent, and builds a small context window around each match for display, only when none of the API-provided fragments matched. No new network calls are introduced, and behaviour is unchanged whenfileContentis absent or when the fragment already matches.How did you verify your code works?
src/aggregate.test.tscovering the fallback path, the no-match case, the already-matching-fragment case (no behaviour change), and thefileContent-absent backward-compatibility case.