fix: over-fetch in find_usages so definition filtering doesn't shrink results - #101
Merged
Conversation
… results find_usages requested exactly `limit` fused hits, then filtered out the symbol's own definition. Since the definition is typically a top hit for the "code that uses or references X" query, callers received limit-1 (or zero, at limit=1) results even when more usages existed just beyond the fetch window. Fetch `limit + USAGE_OVERFETCH` hits before filtering, then slice to `limit`. The buffer is 5 rather than 1 because a single name can produce several definition hits (overloads, same class name across services). Replaces the test that asserted the undercount as a known limitation. Fixes #74 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #74
Problem
find_usagesasked the store for exactlylimitfused hits, then filtered out any hit whosesymbol_nameequals the searched symbol — i.e. the symbol's own definition, which is not a usage.Because the definition is almost always a top hit for the query
"code that uses or references X"(it is the most semantically similar thing to its own name), the caller ended up withlimit - 1results even when more real usages existed just past the fetch window. Atlimit=1it reported "No usages found" for symbols with plenty of usages.Fix
Fetch
limit + USAGE_OVERFETCHhits before filtering, then slice tolimit.The buffer is 5 rather than 1 because a single name can legitimately produce several definition hits — overloaded methods, or the same class name present in more than one indexed service.
Tests
tests/tools/test_search.pycontainedtest_find_usages_can_undercount_when_all_fetched_hits_are_self_matches, which asserted the undercount as a documented known limitation. It is replaced by two tests:limit + USAGE_OVERFETCHFull suite: 293 passed.
🤖 Generated with Claude Code