1
0
mirror of https://github.com/golang/go synced 2024-11-05 15:06:09 -07:00

internal/lsp: fix fallback and error handling logic

We don't need to worry about a package's errors unless it is the
top-level package. Also fix some fallback logic in the type error range
computation.

Change-Id: Ib26b5e25bd70193ea24ec4a197811eedf69b0e2c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202622
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Rebecca Stambler 2019-10-22 17:27:17 -04:00
parent 79994da4ae
commit b24f3822ec
2 changed files with 17 additions and 11 deletions

View File

@ -336,12 +336,15 @@ func (imp *importer) typeCheck(ctx context.Context, cph *checkPackageHandle) (*p
// Type checking errors are handled via the config, so ignore them here.
_ = check.Files(files)
for _, e := range rawErrors {
srcErr, err := sourceError(ctx, pkg, e)
if err != nil {
return nil, err
// We don't care about a package's errors unless we have parsed it in full.
if cph.mode == source.ParseFull {
for _, e := range rawErrors {
srcErr, err := sourceError(ctx, pkg, e)
if err != nil {
return nil, err
}
pkg.errors = append(pkg.errors, srcErr)
}
pkg.errors = append(pkg.errors, srcErr)
}
return pkg, nil

View File

@ -62,6 +62,9 @@ func sourceError(ctx context.Context, pkg *pkg, e interface{}) (*source.Error, e
msg = e.Msg
kind = source.TypeError
spn, err = typeErrorRange(ctx, fset, pkg, e.Pos)
if err != nil {
return nil, err
}
case *analysis.Diagnostic:
spn, err = span.NewRange(fset, e.Pos, e.End).Span()
@ -162,25 +165,25 @@ func typeErrorRange(ctx context.Context, fset *token.FileSet, pkg *pkg, pos toke
posn := fset.Position(pos)
ph, _, err := pkg.FindFile(ctx, span.FileURI(posn.Filename))
if err != nil {
return span.Span{}, err
return spn, nil // ignore errors
}
file, m, _, err := ph.Cached(ctx)
if err != nil {
return span.Span{}, err
return spn, nil
}
path, _ := astutil.PathEnclosingInterval(file, pos, pos)
if len(path) > 0 {
if s, err := span.NewRange(fset, path[0].Pos(), path[0].End()).Span(); err == nil {
return s, nil
if spn, err := span.NewRange(fset, path[0].Pos(), path[0].End()).Span(); err == nil {
return spn, nil
}
}
s, err := spn.WithOffset(m.Converter)
if err != nil {
return span.Span{}, err
return spn, nil // ignore errors
}
data, _, err := ph.File().Read(ctx)
if err != nil {
return span.Span{}, err
return spn, nil // ignore errors
}
start := s.Start()
offset := start.Offset()