internal/lsp: add back check that a package was found for a given file

Added this check in golang.org/cl/161077 and unintentionally removed it in
golang.org/cl/161497.

Change-Id: I66bd2b616f4b41c25f134f6e9457c97bbcd3f72b
Reviewed-on: https://go-review.googlesource.com/c/162398
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Rebecca Stambler 2019-02-13 13:03:16 -05:00
parent dbb4d4be53
commit 740235f6c0
1 changed files with 7 additions and 0 deletions

View File

@ -121,6 +121,7 @@ func (v *View) parse(uri source.URI) error {
} }
return err return err
} }
var foundPkg bool // true if we found the package for uri
for _, pkg := range pkgs { for _, pkg := range pkgs {
imp := &importer{ imp := &importer{
entries: make(map[string]*entry), entries: make(map[string]*entry),
@ -150,12 +151,18 @@ func (v *View) parse(uri source.URI) error {
continue continue
} }
fURI := source.ToURI(tok.Name()) fURI := source.ToURI(tok.Name())
if fURI == uri {
foundPkg = true
}
f := imp.v.getFile(fURI) f := imp.v.getFile(fURI)
f.token = tok f.token = tok
f.ast = file f.ast = file
f.pkg = pkg f.pkg = pkg
} }
} }
if !foundPkg {
return fmt.Errorf("no package found for %v", uri)
}
return nil return nil
} }