88 "slices"
99
1010 genslices "github.com/life4/genesis/slices"
11+ conciter "github.com/sourcegraph/conc/iter"
1112 "github.com/sourcegraph/log"
1213 "github.com/sourcegraph/scip/bindings/go/scip"
1314 orderedmap "github.com/wk8/go-ordered-map/v2"
@@ -380,19 +381,21 @@ func syntacticUsagesImpl(
380381 }
381382 }
382383
383- results := [][]SyntacticMatch {}
384-
384+ tasks := make ([]orderedmap.Pair [core.RepoRelPath , candidateFile ], 0 , candidateMatches .Len ())
385385 for pair := candidateMatches .Oldest (); pair != nil ; pair = pair .Next () {
386- // We're assuming the upload we found earlier contains the relevant SCIP document
386+ tasks = append (tasks , * pair )
387+ }
388+ results := conciter .Map (tasks , func (pair * orderedmap.Pair [core.RepoRelPath , candidateFile ]) []SyntacticMatch {
389+ // We're assuming the index we found earlier contains the relevant SCIP document
387390 // see NOTE(id: single-syntactic-upload)
388- syntacticMatches , _ , err := findSyntacticMatchesForCandidateFile (ctx , trace , mappedIndex , pair .Key , pair .Value )
391+ syntacticMatches , _ , err := findSyntacticMatchesForCandidateFile (ctx , trace , mappedIndex , ( * pair ) .Key , ( * pair ) .Value )
389392 if err != nil {
390393 // TODO: Errors that are not "no index found in the DB" should be reported
391394 // TODO: Track metrics about how often this happens (GRAPH-693)
392- continue
395+ return [] SyntacticMatch {}
393396 }
394- results = append ( results , syntacticMatches )
395- }
397+ return syntacticMatches
398+ })
396399 return SyntacticUsagesResult {Matches : slices .Concat (results ... )}, PreviousSyntacticSearch {
397400 MappedIndex : mappedIndex ,
398401 SymbolName : symbolName ,
@@ -425,14 +428,16 @@ func searchBasedUsagesImpl(
425428 if err != nil {
426429 trace .Warn ("Failed to run symbol search, will not mark any search-based usages as definitions" , log .Error (err ))
427430 }
428-
429- results := [][]SearchBasedMatch {}
431+ tasks := make ([]orderedmap.Pair [core.RepoRelPath , candidateFile ], 0 , candidateMatches .Len ())
430432 for pair := candidateMatches .Oldest (); pair != nil ; pair = pair .Next () {
433+ tasks = append (tasks , * pair )
434+ }
435+
436+ results := conciter .Map (tasks , func (pair * orderedmap.Pair [core.RepoRelPath , candidateFile ]) []SearchBasedMatch {
431437 if index , ok := syntacticIndex .Get (); ok {
432438 _ , searchBasedMatches , err := findSyntacticMatchesForCandidateFile (ctx , trace , index , pair .Key , pair .Value )
433439 if err == nil {
434- results = append (results , searchBasedMatches )
435- continue
440+ return searchBasedMatches
436441 } else {
437442 trace .Info ("findSyntacticMatches failed, skipping filtering search-based results" , log .Error (err ))
438443 }
@@ -445,7 +450,7 @@ func searchBasedUsagesImpl(
445450 IsDefinition : candidateSymbols .Contains (pair .Key , rg ),
446451 })
447452 }
448- results = append ( results , matches )
449- }
453+ return matches
454+ })
450455 return slices .Concat (results ... ), nil
451456}
0 commit comments