Add query title heading and matched token to output#127
Conversation
- buildMarkdownOutput now prepends '# Results for "query"' (H1) with optional qualifiers (· including archived · excluding templates). In regex mode the query is displayed in backticks. - Each match line appended with the exact matched token in backticks when TextMatchSegment.text is available (e.g. \`: \`useFlag\`\`). - buildJsonOutput adds matchedText field to each match entry alongside the existing line/col fields (omitted when location is unavailable). - repo-only mode also gets the H1 heading before the repo list. - New exported buildQueryTitle(query, options) in src/output.ts. - 78 tests pass (new describe + updated snapshots in output.test.ts). - README.md and docs updated to reflect new output format. Closes #126
|
Coverage after merging feat/output-query-title-matched-token into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
🔦 Lighthouse Report
|
There was a problem hiding this comment.
Pull request overview
Adds more self-describing non-interactive outputs by introducing a query title heading and surfacing the matched token per result line (Markdown) / per match entry (JSON), aligning with issue #126.
Changes:
- Add
buildQueryTitle()and prepend# Results for ...to Markdown output (bothrepo-and-matchesandrepo-only). - Append matched token to each Markdown match line and include
matchedTextin JSON match objects when segment data exists. - Update tests and documentation examples to reflect the new output.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/output.ts | Adds buildQueryTitle(); updates Markdown/JSON builders to include query title + matched token. |
| src/output.test.ts | Adds unit tests for buildQueryTitle() and updates/extends output expectations. |
| docs/usage/output-formats.md | Updates output examples and adds a “Query title” section. |
| docs/usage/non-interactive-mode.md | Updates example output to include the new heading and matched token. |
| README.md | Updates feature description for structured output and adds “Regex search” to the feature list/table. |
…ge-case tests - Add mdInlineCode() helper using variable-length backtick fence (CommonMark §6.1) so regex patterns containing backticks produce valid inline code spans. Reuse for seg.text in match lines. - buildQueryTitle: use mdInlineCode() for regex queries (fixes embedded backticks) and JSON.stringify() for plain queries (escapes embedded " and converts \n so the heading always stays on a single line). - Fix JSDoc example: '# Results for \`useFlag/i\`' → '# Results for \`/useFlag/i\`'. - buildJsonOutput: guard matchedText behind seg.text non-empty check, matching markdown behaviour and preventing '"matchedText": ""' in JSON output. - Add edge-case tests: plain query with embedded quotes, plain query with newline, regex with embedded backtick, empty seg.text omitted from JSON.
|
Coverage after merging feat/output-query-title-matched-token into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Use VS Code-ready path:line:col as link text and anchor the URL to the | ||
| // line when location info is available (GitHub #Lline deeplink). | ||
| // Position is fragment-relative (GitHub Code Search API does not return | ||
| // absolute line numbers). | ||
| const seg = m.textMatches[0]?.matches[0]; |
There was a problem hiding this comment.
The inline comment says the segment position is fragment-relative, but api.ts now attempts to resolve absolute file line numbers by fetching raw content (falling back to fragment-relative when that fails). Updating this comment to reflect the current behavior would prevent confusion when interpreting seg.line/seg.col.
- output.ts: update inline comment — seg.line/seg.col are now absolute file line numbers resolved by api.ts (not fragment-relative) - output-formats.md: replace nested-backtick prose with fenced code block example to avoid malformed Markdown rendering - output-formats.md: reword Query title section to distinguish format (Markdown/JSON) from output-type (repo-only/repo-and-matches) - output-formats.md: remove #L2 anchor from JSON example url field — buildJsonOutput() emits m.htmlUrl without anchoring to line - README.md: qualify matchedText/line/col as 'when segment data is available' to avoid overstating the JSON schema guarantee
|
Coverage after merging feat/output-query-title-matched-token into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Closes #126
What
Two improvements to the
--no-interactiveoutput (markdown and JSON).1. Query title heading
Every output now starts with a
# Results forH1 heading. Qualifiers are appended when active:Appears in both
repo-and-matchesandrepo-onlymodes.2. Matched token inline in each result line
Markdown — before:
Markdown — after:
JSON — before:
{ "path": "src/foo.ts", "url": "...", "line": 3, "col": 5 }JSON — after:
{ "path": "src/foo.ts", "url": "...", "line": 3, "col": 5, "matchedText": "useFeatureFlag" }Both fields fall back gracefully when location/segment data is unavailable (no API change required —
TextMatchSegment.textalready existed).Changes
src/output.tsbuildQueryTitle()+ updatedbuildMarkdownOutput/buildJsonOutputsrc/output.test.tsdescribe("buildQueryTitle")(6 cases) + updated snapshotsdocs/usage/output-formats.mddocs/usage/non-interactive-mode.mdREADME.mdVerification