Repository navigation
feat: Complete /usages endpoint (Closes #15) - #57
Conversation
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>
There was a problem hiding this comment.
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 /usageshandler with request/response schemas, result classification, filtering, sorting, and metadata counts. - Extend
MockSearchtest utilities withTestSearchMatchto 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. |
- 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>
|
@copilot re-review please — addressed all review findings: Major fixes:
Minor fixes: |
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>
- 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>
/usagesendpointcontent_contains_symbolwith word-boundary + case-insensitive matching/usagesto match/search