1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:44:46 -07:00

internal/lsp: fix minor bug in the PackageHandle function

Test variants and test mains can result in multiple packages being
loaded for a single ID. Handle this case in the PackageHandle function
instead of returning an error.

Change-Id: Ic0024c5bded162a3e78a9cdcb9566449f3683e35
Reviewed-on: https://go-review.googlesource.com/c/tools/+/213457
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Rebecca Stambler 2020-01-06 13:14:29 -05:00
parent 774c71fcf1
commit 7be0a674c9

View File

@ -95,10 +95,19 @@ func (s *snapshot) PackageHandle(ctx context.Context, pkgID string) (source.Pack
if err != nil {
return nil, err
}
if len(phs) > 1 {
return nil, errors.Errorf("more than one package for %s", id)
var result *packageHandle
for _, ph := range phs {
if ph.m.id == id {
if result != nil {
return nil, errors.Errorf("multiple package handles for the same ID: %s", id)
}
result = ph
}
}
return phs[0], nil
if result == nil {
return nil, errors.Errorf("no PackageHandle for %s", id)
}
return result, nil
}
func (s *snapshot) packageHandles(ctx context.Context, scope interface{}, meta []*metadata) ([]*packageHandle, error) {