Skip to content

feat: Complete /usages endpoint (Closes #15) - #57

Merged
clafollett merged 5 commits into
mainfrom
feature/issue-15-usages-endpoint
Apr 3, 2026
Merged

clafollett merged 5 commits into
mainfrom
feature/issue-15-usages-endpoint

Conversation

@clafollett

@clafollett clafollett commented Apr 3, 2026 •

Copy link
Copy Markdown
Owner
  • Implement /usages endpoint
  • Add content_contains_symbol with word-boundary + case-insensitive matching
  • Add connection/unavailability error handling in /usages to match /search
  • All 31 unit tests passing, clippy clean

clafollett and others added 2 commits April 3, 2026 15:45
Finish the /usages endpoint that finds definitions and references of a
symbol across the indexed codebase:

- Handler validates input, searches via semantic search, classifies
  results as definitions (name match + kind) or references (content
  contains symbol)
- Sorts definitions before references, then by similarity
- Supports usage_type filter (all/definitions/references)
- Add TestSearchMatch to MockSearch for richer test data with names/kinds
- 9 new tests covering definitions, references, sorting, filtering,
  validation, and metadata counts
- Fix clippy lints (arithmetic_side_effects, ref_option, type_complexity,
  similar_names, missing_errors_doc)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Finish the /usages endpoint that finds definitions and references of a
symbol across the indexed codebase:

- Handler validates input, searches via semantic search, classifies
  results as definitions (name match + kind) or references (content
  contains symbol)
- Sorts definitions before references, then by similarity
- Supports usage_type filter (all/definitions/references)
- Add TestSearchMatch to MockSearch for richer test data with names/kinds
- 9 new tests covering definitions, references, sorting, filtering,
  validation, and metadata counts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 3, 2026 19:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new /usages API endpoint to the Codetriever search routes to locate and classify symbol usages (definitions vs references) across indexed code, and exposes it via OpenAPI. It also extends the search test mock utilities to support richer fixtures needed by the new endpoint’s tests.

Changes:

  • Implement POST /usages handler with request/response schemas, result classification, filtering, sorting, and metadata counts.
  • Extend MockSearch test utilities with TestSearchMatch to provide name/kind-aware search fixtures.
  • Register the new endpoint in routing and OpenAPI; apply minor formatting-only clippy cleanups in parsing tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/codetriever-search/src/searching/test_utils.rs Adds TestSearchMatch and MockSearch::with_matches for richer test fixtures.
crates/codetriever-search/src/lib.rs Re-exports TestSearchMatch under test_mocks when test utils are enabled.
crates/codetriever-parsing/src/chunking/service.rs Formatting-only changes in tests (asserts/line wrapping).
crates/codetriever-api/src/routes/search.rs Adds /usages endpoint (schemas, handler, and comprehensive tests) and wires route.
crates/codetriever-api/src/openapi.rs Registers /usages path and schemas in the OpenAPI spec.

Comment thread crates/codetriever-api/src/routes/search.rs Outdated
Comment thread crates/codetriever-api/src/routes/search.rs
- Deduplicate extract_repo_commit: search_handler_impl now calls the
  shared helper instead of inlining identical logic
- Make is_reference case-insensitive to match is_definition behavior
- Overfetch 3x before post-filtering to compensate for semantic results
  that don't contain the literal symbol string
- Truncate usages to user_limit after sort
- Use f32::total_cmp for NaN-safe sorting
- Trim symbol whitespace before use in search and classification
- Fix invalid_query error to pass usage_type not symbol on validation
- Add warn! log for invalid usage_type (consistent with other paths)
- Remove dead skip_serializing_if on Deserialize-only request structs
- Replace test that re-implemented extraction logic with one that calls
  extract_repo_commit directly, plus None case
- Add test_usages_definition_not_double_counted_as_reference
- Add doc warning to MockSearch::with_results about name: None

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@clafollett

Copy link
Copy Markdown
Owner Author

@copilot re-review please — addressed all review findings:

Major fixes:

  1. Deduplicated extract_repo_commit — search_handler_impl now calls shared helper
  2. is_reference now case-insensitive (matches is_definition behavior)
  3. Overfetch 3x before post-filtering, truncate to user_limit after sort

Minor fixes:
4. invalid_query error now passes usage_type (not symbol) + added warn! log
5. Removed dead skip_serializing_if on Deserialize-only request structs
6. Added test: definition not double-counted as reference
7. Symbol trimmed after validation, used throughout
8. Replaced meaningless repo/commit test with one testing extract_repo_commit directly
9. Added doc warning to MockSearch::with_results about name: None

Match /search endpoint behavior — map "unavailable" and "connection"
errors to 503 instead of 500 for consistent client experience.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread crates/codetriever-api/src/routes/search.rs
Comment thread crates/codetriever-api/src/routes/search.rs Outdated
Comment thread docs/code-reviews/2026-04-03-usages-endpoint-review.md Outdated
- Recompute def_count/ref_count after truncation so metadata stays
  consistent (definitions + references == total_usages)
- Precompute symbol_lower once per request instead of allocating
  lowercase strings per is_reference call
- Update review doc to reflect all 12 issues resolved

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@clafollett
clafollett merged commit ebb6c3c into main Apr 3, 2026
2 checks passed
@clafollett
clafollett deleted the feature/issue-15-usages-endpoint branch April 3, 2026 22:41
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.

2 participants