Skip to content

Commit

Permalink
[Backport 5.3.9104] Context: fix bug with result limits (#62054)
Browse files Browse the repository at this point in the history
Context: fix bug with result limits (#61806)

While writing eval scripts for Cody context, I noticed that when searching
multiple repos, we sometimes we return greater than the intended number of
results. This PR makes a small fix so we always respect the result limits.

(cherry picked from commit 6a4ac36)

Co-authored-by: Julie Tibshirani <julietibs@apache.org>
  • Loading branch information
sourcegraph-release-guild-bot and jtibshirani committed Apr 22, 2024
1 parent e2cf4ee commit ece951a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/codycontext/context.go
Expand Up @@ -302,6 +302,12 @@ func (c *CodyContextClient) getKeywordContext(ctx context.Context, args GetConte
mu.Lock()
defer mu.Unlock()

// Another caller may have already hit the limit, but we haven't yet responded
// to the cancellation. Return immediately in this case.
if len(collected) >= limit {
return
}

for _, res := range e.Results {
if fm, ok := res.(*result.FileMatch); ok {
collected = append(collected, filter(fileMatchToContextMatches(fm))...)
Expand Down

0 comments on commit ece951a

Please sign in to comment.