mirror of
https://github.com/golang/go
synced 2024-11-18 09:04:49 -07:00
internal/lsp/cache: handle invalid analysis Pos
The nilness analysis gives us diagnostics with invalid start Pos. We can just ignore those and log them. Add a missing error check while I'm in here. Change-Id: I4a205f253a9e47ec1513ff6299479f52e414a48c Reviewed-on: https://go-review.googlesource.com/c/tools/+/216724 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
520188d60f
commit
e1fd5825ff
21
internal/lsp/cache/analysis.go
vendored
21
internal/lsp/cache/analysis.go
vendored
@ -19,6 +19,7 @@ import (
|
||||
"golang.org/x/tools/internal/lsp/telemetry"
|
||||
"golang.org/x/tools/internal/memoize"
|
||||
"golang.org/x/tools/internal/telemetry/log"
|
||||
"golang.org/x/tools/internal/telemetry/tag"
|
||||
errors "golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
@ -319,13 +320,15 @@ func runAnalysis(ctx context.Context, fset *token.FileSet, analyzer *analysis.An
|
||||
return data
|
||||
}
|
||||
data.result, data.err = pass.Analyzer.Run(pass)
|
||||
if data.err == nil {
|
||||
if got, want := reflect.TypeOf(data.result), pass.Analyzer.ResultType; got != want {
|
||||
data.err = errors.Errorf(
|
||||
"internal error: on package %s, analyzer %s returned a result of type %v, but declared ResultType %v",
|
||||
pass.Pkg.Path(), pass.Analyzer, got, want)
|
||||
return data
|
||||
}
|
||||
if data.err != nil {
|
||||
return data
|
||||
}
|
||||
|
||||
if got, want := reflect.TypeOf(data.result), pass.Analyzer.ResultType; got != want {
|
||||
data.err = errors.Errorf(
|
||||
"internal error: on package %s, analyzer %s returned a result of type %v, but declared ResultType %v",
|
||||
pass.Pkg.Path(), pass.Analyzer, got, want)
|
||||
return data
|
||||
}
|
||||
|
||||
// disallow calls after Run
|
||||
@ -339,8 +342,8 @@ func runAnalysis(ctx context.Context, fset *token.FileSet, analyzer *analysis.An
|
||||
for _, diag := range diagnostics {
|
||||
srcErr, err := sourceError(ctx, fset, pkg, diag)
|
||||
if err != nil {
|
||||
data.err = err
|
||||
return data
|
||||
log.Error(ctx, "unable to compute analysis error position", err, tag.Of("category", diag.Category), telemetry.Package.Of(pkg.ID()))
|
||||
continue
|
||||
}
|
||||
data.diagnostics = append(data.diagnostics, srcErr)
|
||||
}
|
||||
|
@ -61,6 +61,9 @@ func (r Range) IsPoint() bool {
|
||||
// It will fill in all the members of the Span, calculating the line and column
|
||||
// information.
|
||||
func (r Range) Span() (Span, error) {
|
||||
if !r.Start.IsValid() {
|
||||
return Span{}, fmt.Errorf("start pos is not valid")
|
||||
}
|
||||
f := r.FileSet.File(r.Start)
|
||||
if f == nil {
|
||||
return Span{}, fmt.Errorf("file not found in FileSet")
|
||||
|
Loading…
Reference in New Issue
Block a user