Skip to content

Fall back to full file content for local regex filtering - #154

Merged
shouze merged 2 commits into
fix/plain-text-quote-validationfrom
fix/regex-local-filter-full-content
Aug 23, 2026
Merged

Fall back to full file content for local regex filtering#154
shouze merged 2 commits into
fix/plain-text-quote-validationfrom
fix/regex-local-filter-full-content

Conversation

@shouze

@shouze shouze commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #148.

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 the new optional CodeMatch.fileContent field (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 are introduced, and behaviour is unchanged when fileContent is absent or when the fragment already matches.

How did you verify your code works?

  • Added regression tests in src/aggregate.test.ts covering the fallback path, the no-match case, the already-matching-fragment case (no behaviour change), and the fileContent-absent backward-compatibility case.
  • Ran the full suite, lint, format check and knip; all green.

@shouze shouze changed the title Fall back to full file content for local regex filtering (#148) Fall back to full file content for local regex filtering Aug 23, 2026
@shouze
shouze force-pushed the fix/regex-local-filter-full-content branch from 0a9020d to a3953c8 Compare August 23, 2026 13:58
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be

95.96%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.59%100%100%93.91%323–327, 388, 405, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.37%100%100%99.32%320
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

1 similar comment
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be

95.96%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.59%100%100%93.91%323–327, 388, 405, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.37%100%100%99.32%320
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

@shouze
shouze marked this pull request as ready for review August 23, 2026 14:06
Copilot AI lite review requested due to automatic review settings August 23, 2026 14:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/aggregate.ts Outdated
Comment thread src/aggregate.ts Outdated
Comment on lines +170 to +174
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;
Comment thread src/api.ts Outdated
Comment thread src/api.ts Outdated
@shouze
shouze force-pushed the fix/regex-local-filter-full-content branch from a3953c8 to 322e43c Compare August 23, 2026 14:26
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be

95.96%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.59%100%100%93.91%323–327, 388, 405, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.37%100%100%99.32%320
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

1 similar comment
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be

95.96%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.59%100%100%93.91%323–327, 388, 405, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.37%100%100%99.32%320
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

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
@shouze
shouze force-pushed the fix/regex-local-filter-full-content branch from 322e43c to a818982 Compare August 23, 2026 14:36
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be

95.96%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.59%100%100%93.91%323–327, 388, 405, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.39%100%100%99.34%329
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

1 similar comment
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be

95.96%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.59%100%100%93.91%323–327, 388, 405, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.39%100%100%99.34%329
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

- 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)
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/regex-local-filter-full-content into fix/plain-text-quote-validation will be

95.99%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.62%100%100%93.94%328–332, 393, 410, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.39%100%100%99.34%329
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

@shouze
shouze merged commit 74867ab into main Aug 23, 2026
5 checks passed
@shouze
shouze deleted the fix/regex-local-filter-full-content branch August 23, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local regex filter should not depend solely on the possibly truncated API fragment

2 participants