internal/lsp: revert to old method of computing error ranges
The approach of using ASTs to determine error ranges had more
complications than I anticipated. Revert it for now to go back to the
old user experience, while we consider a better approach.
Change-Id: I5b23f0147c26089330f8a4bbf7b6914ae66cf59a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/204561
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/internal/lsp/cache/errors.go b/internal/lsp/cache/errors.go
index 315f157..57740ff 100644
--- a/internal/lsp/cache/errors.go
+++ b/internal/lsp/cache/errors.go
@@ -3,14 +3,12 @@
import (
"bytes"
"context"
- "go/ast"
"go/scanner"
"go/token"
"go/types"
"strings"
"golang.org/x/tools/go/analysis"
- "golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/lsp/source"
@@ -166,16 +164,10 @@
if err != nil {
return spn, nil // ignore errors
}
- file, m, _, err := ph.Cached()
+ _, m, _, err := ph.Cached()
if err != nil {
return spn, nil
}
- path, _ := astutil.PathEnclosingInterval(file, pos, pos)
- if len(path) > 0 {
- 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 spn, nil // ignore errors
@@ -208,15 +200,6 @@
return span.Span{}, errors.Errorf("no token.File for %s", ph.File().Identity().URI)
}
pos := tok.Pos(posn.Offset)
- path, _ := astutil.PathEnclosingInterval(file, pos, pos)
- if len(path) > 0 {
- switch n := path[0].(type) {
- case *ast.BadDecl, *ast.BadExpr, *ast.BadStmt:
- if s, err := span.NewRange(fset, n.Pos(), n.End()).Span(); err == nil {
- return s, nil
- }
- }
- }
return span.NewRange(fset, pos, pos).Span()
}