Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit ece951a

Browse files
[Backport 5.3.9104] Context: fix bug with result limits (#62054)
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 <[email protected]>
1 parent e2cf4ee commit ece951a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

internal/codycontext/context.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ func (c *CodyContextClient) getKeywordContext(ctx context.Context, args GetConte
302302
mu.Lock()
303303
defer mu.Unlock()
304304

305+
// Another caller may have already hit the limit, but we haven't yet responded
306+
// to the cancellation. Return immediately in this case.
307+
if len(collected) >= limit {
308+
return
309+
}
310+
305311
for _, res := range e.Results {
306312
if fm, ok := res.(*result.FileMatch); ok {
307313
collected = append(collected, filter(fileMatchToContextMatches(fm))...)

0 commit comments

Comments
 (0)