mirror of
https://github.com/golang/go
synced 2024-11-18 10:54:40 -07:00
internal/lsp/source: sort cached package completions by relevance
Cached packages are probably more relevant than uncached packages, but we still need to go in relevance order, since we'll stop adding results after we hit the cap. Fixes golang/go#38461. (Hopefully.) Change-Id: I555dd5f7568baa8d69760ed5836341a474e94346 Reviewed-on: https://go-review.googlesource.com/c/tools/+/231619 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
6a7cf6184f
commit
7527cb292c
@ -849,8 +849,11 @@ func (c *completer) unimportedMembers(ctx context.Context, id *ast.Ident) error
|
||||
return nil
|
||||
})
|
||||
}
|
||||
sort.Slice(paths, func(i, j int) bool {
|
||||
return relevances[paths[i]] > relevances[paths[j]]
|
||||
})
|
||||
|
||||
for path, relevance := range relevances {
|
||||
for _, path := range paths {
|
||||
pkg := known[path]
|
||||
if pkg.GetTypes().Name() != id.Name {
|
||||
continue
|
||||
@ -862,7 +865,7 @@ func (c *completer) unimportedMembers(ctx context.Context, id *ast.Ident) error
|
||||
if imports.ImportPathToAssumedName(path) != pkg.GetTypes().Name() {
|
||||
imp.name = pkg.GetTypes().Name()
|
||||
}
|
||||
c.packageMembers(ctx, pkg.GetTypes(), unimportedScore(relevance), imp)
|
||||
c.packageMembers(ctx, pkg.GetTypes(), unimportedScore(relevances[path]), imp)
|
||||
if len(c.items) >= unimportedMemberTarget {
|
||||
return nil
|
||||
}
|
||||
@ -1134,8 +1137,11 @@ func (c *completer) unimportedPackages(ctx context.Context, seen map[string]stru
|
||||
return nil
|
||||
})
|
||||
}
|
||||
sort.Slice(paths, func(i, j int) bool {
|
||||
return relevances[paths[i]] > relevances[paths[j]]
|
||||
})
|
||||
|
||||
for path, relevance := range relevances {
|
||||
for _, path := range paths {
|
||||
pkg := known[path]
|
||||
if _, ok := seen[pkg.GetTypes().Name()]; ok {
|
||||
continue
|
||||
@ -1152,7 +1158,7 @@ func (c *completer) unimportedPackages(ctx context.Context, seen map[string]stru
|
||||
}
|
||||
c.found(ctx, candidate{
|
||||
obj: types.NewPkgName(0, nil, pkg.GetTypes().Name(), pkg.GetTypes()),
|
||||
score: unimportedScore(relevance),
|
||||
score: unimportedScore(relevances[path]),
|
||||
imp: imp,
|
||||
})
|
||||
count++
|
||||
|
Loading…
Reference in New Issue
Block a user