Skip to content

Commit 3bc713c

Browse files
committed
const for maxsuggestions
1 parent bdde686 commit 3bc713c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pkg/suggestion/suggestion.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"github.com/wavetermdev/waveterm/pkg/wshrpc"
2424
)
2525

26+
const MaxSuggestions = 50
27+
2628
type MockDirEntry struct {
2729
NameStr string
2830
IsDirVal bool
@@ -285,7 +287,7 @@ func fetchBookmarkSuggestions(_ context.Context, data wshrpc.FetchSuggestionsDat
285287
return scoredEntries[i].origIndex < scoredEntries[j].origIndex
286288
})
287289

288-
// Build up to 50 suggestions.
290+
// Build up to MaxSuggestions suggestions.
289291
var suggestions []wshrpc.SuggestionType
290292
for _, entry := range scoredEntries {
291293
var display, subText string
@@ -309,7 +311,7 @@ func fetchBookmarkSuggestions(_ context.Context, data wshrpc.FetchSuggestionsDat
309311
}
310312
suggestion.IconSrc = faviconcache.GetFavicon(entry.bookmark.Url)
311313
suggestions = append(suggestions, suggestion)
312-
if len(suggestions) >= 50 {
314+
if len(suggestions) >= MaxSuggestions {
313315
break
314316
}
315317
}
@@ -416,12 +418,9 @@ func fetchFileSuggestions(_ context.Context, data wshrpc.FetchSuggestionsData) (
416418
})
417419
}
418420

419-
// Build up to 50 suggestions.
421+
// Build up to MaxSuggestions suggestions
420422
var suggestions []wshrpc.SuggestionType
421-
for i, candidate := range scoredEntries {
422-
if i >= 50 {
423-
break
424-
}
423+
for _, candidate := range scoredEntries {
425424
fileName := candidate.ent.Name()
426425
fullPath := filepath.Join(baseDir, fileName)
427426
suggestionFileName := filepath.Join(queryPrefix, fileName)
@@ -439,10 +438,13 @@ func fetchFileSuggestions(_ context.Context, data wshrpc.FetchSuggestionsData) (
439438
Display: suggestionFileName,
440439
FileName: suggestionFileName,
441440
FileMimeType: fileutil.DetectMimeTypeWithDirEnt(fullPath, candidate.ent),
442-
MatchPos: scoredEntries[i].positions,
441+
MatchPos: candidate.positions,
443442
Score: candidate.score,
444443
}
445444
suggestions = append(suggestions, s)
445+
if len(suggestions) >= MaxSuggestions {
446+
break
447+
}
446448
}
447449

448450
return &wshrpc.FetchSuggestionsResponse{

0 commit comments

Comments
 (0)