mirror of
https://github.com/golang/go
synced 2024-11-05 17:36:15 -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:
parent
79994da4ae
commit
b24f3822ec
13
internal/lsp/cache/check.go
vendored
13
internal/lsp/cache/check.go
vendored
@ -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.
|
// Type checking errors are handled via the config, so ignore them here.
|
||||||
_ = check.Files(files)
|
_ = check.Files(files)
|
||||||
|
|
||||||
for _, e := range rawErrors {
|
// We don't care about a package's errors unless we have parsed it in full.
|
||||||
srcErr, err := sourceError(ctx, pkg, e)
|
if cph.mode == source.ParseFull {
|
||||||
if err != nil {
|
for _, e := range rawErrors {
|
||||||
return nil, err
|
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
|
return pkg, nil
|
||||||
|
15
internal/lsp/cache/errors.go
vendored
15
internal/lsp/cache/errors.go
vendored
@ -62,6 +62,9 @@ func sourceError(ctx context.Context, pkg *pkg, e interface{}) (*source.Error, e
|
|||||||
msg = e.Msg
|
msg = e.Msg
|
||||||
kind = source.TypeError
|
kind = source.TypeError
|
||||||
spn, err = typeErrorRange(ctx, fset, pkg, e.Pos)
|
spn, err = typeErrorRange(ctx, fset, pkg, e.Pos)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
case *analysis.Diagnostic:
|
case *analysis.Diagnostic:
|
||||||
spn, err = span.NewRange(fset, e.Pos, e.End).Span()
|
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)
|
posn := fset.Position(pos)
|
||||||
ph, _, err := pkg.FindFile(ctx, span.FileURI(posn.Filename))
|
ph, _, err := pkg.FindFile(ctx, span.FileURI(posn.Filename))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return span.Span{}, err
|
return spn, nil // ignore errors
|
||||||
}
|
}
|
||||||
file, m, _, err := ph.Cached(ctx)
|
file, m, _, err := ph.Cached(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return span.Span{}, err
|
return spn, nil
|
||||||
}
|
}
|
||||||
path, _ := astutil.PathEnclosingInterval(file, pos, pos)
|
path, _ := astutil.PathEnclosingInterval(file, pos, pos)
|
||||||
if len(path) > 0 {
|
if len(path) > 0 {
|
||||||
if s, err := span.NewRange(fset, path[0].Pos(), path[0].End()).Span(); err == nil {
|
if spn, err := span.NewRange(fset, path[0].Pos(), path[0].End()).Span(); err == nil {
|
||||||
return s, nil
|
return spn, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s, err := spn.WithOffset(m.Converter)
|
s, err := spn.WithOffset(m.Converter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return span.Span{}, err
|
return spn, nil // ignore errors
|
||||||
}
|
}
|
||||||
data, _, err := ph.File().Read(ctx)
|
data, _, err := ph.File().Read(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return span.Span{}, err
|
return spn, nil // ignore errors
|
||||||
}
|
}
|
||||||
start := s.Start()
|
start := s.Start()
|
||||||
offset := start.Offset()
|
offset := start.Offset()
|
||||||
|
Loading…
Reference in New Issue
Block a user