internal/lsp: return errors when we can't find a package
This will allow us to surface these errors as diagnostics. Change-Id: Ic8ad11ba43c08be6f391c0e2aa95015183461133 Reviewed-on: https://go-review.googlesource.com/c/tools/+/173780 Reviewed-by: Ian Cottrell <iancottrell@google.com> Run-TryBot: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
45abd40133
commit
bb8aefc696
|
@ -91,7 +91,13 @@ func (v *View) checkMetadata(ctx context.Context, f *File) ([]packages.Error, er
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = fmt.Errorf("no packages found for %s", f.filename)
|
err = fmt.Errorf("no packages found for %s", f.filename)
|
||||||
}
|
}
|
||||||
return nil, err
|
// Return this error as a diagnostic to the user.
|
||||||
|
return []packages.Error{
|
||||||
|
{
|
||||||
|
Msg: err.Error(),
|
||||||
|
Kind: packages.ListError,
|
||||||
|
},
|
||||||
|
}, err
|
||||||
}
|
}
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
// If the package comes back with errors from `go list`, don't bother
|
// If the package comes back with errors from `go list`, don't bother
|
||||||
|
|
|
@ -89,8 +89,7 @@ func (f *File) GetPackage(ctx context.Context) source.Package {
|
||||||
f.view.mu.Lock()
|
f.view.mu.Lock()
|
||||||
defer f.view.mu.Unlock()
|
defer f.view.mu.Unlock()
|
||||||
if f.pkg == nil || len(f.view.contentChanges) > 0 {
|
if f.pkg == nil || len(f.view.contentChanges) > 0 {
|
||||||
errs, err := f.view.parse(ctx, f)
|
if errs, err := f.view.parse(ctx, f); err != nil {
|
||||||
if err != nil {
|
|
||||||
// Create diagnostics for errors if we are able to.
|
// Create diagnostics for errors if we are able to.
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
return &Package{errors: errs}
|
return &Package{errors: errs}
|
||||||
|
|
Loading…
Reference in New Issue