1
0
mirror of https://github.com/golang/go synced 2024-11-26 04:17:59 -07:00

go/types: improve the positioning of broken import errors

The heuristic gopls uses to guess error spans can get tripped-up on
certain valid characters in an import path (for example '-').

Update the error for broken imports to capture the full import path
span, so that gopls doesn't need to rely on heuristics.

Change-Id: Ieb8e0dce11933643f701b32271ff5f3477fecaaa
Reviewed-on: https://go-review.googlesource.com/c/go/+/300169
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Rob Findley 2021-03-09 14:22:38 -05:00 committed by Robert Findley
parent 48ddf70128
commit 142a76530c

View File

@ -130,7 +130,7 @@ func (check *Checker) filename(fileNo int) string {
return fmt.Sprintf("file[%d]", fileNo)
}
func (check *Checker) importPackage(pos token.Pos, path, dir string) *Package {
func (check *Checker) importPackage(at positioner, path, dir string) *Package {
// If we already have a package for the given (path, dir)
// pair, use it instead of doing a full import.
// Checker.impMap only caches packages that are marked Complete
@ -170,7 +170,7 @@ func (check *Checker) importPackage(pos token.Pos, path, dir string) *Package {
imp = nil // create fake package below
}
if err != nil {
check.errorf(atPos(pos), _BrokenImport, "could not import %s (%s)", path, err)
check.errorf(at, _BrokenImport, "could not import %s (%s)", path, err)
if imp == nil {
// create a new fake package
// come up with a sensible package name (heuristic)
@ -254,7 +254,7 @@ func (check *Checker) collectObjects() {
return
}
imp := check.importPackage(d.spec.Path.Pos(), path, fileDir)
imp := check.importPackage(d.spec.Path, path, fileDir)
if imp == nil {
return
}