зеркало из https://github.com/golang/tools.git
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:
Родитель
45abd40133
Коммит
bb8aefc696
|
@ -91,7 +91,13 @@ func (v *View) checkMetadata(ctx context.Context, f *File) ([]packages.Error, er
|
|||
if err == nil {
|
||||
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 {
|
||||
// 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()
|
||||
defer f.view.mu.Unlock()
|
||||
if f.pkg == nil || len(f.view.contentChanges) > 0 {
|
||||
errs, err := f.view.parse(ctx, f)
|
||||
if err != nil {
|
||||
if errs, err := f.view.parse(ctx, f); err != nil {
|
||||
// Create diagnostics for errors if we are able to.
|
||||
if len(errs) > 0 {
|
||||
return &Package{errors: errs}
|
||||
|
|
Загрузка…
Ссылка в новой задаче