1
0
mirror of https://github.com/golang/go synced 2024-11-18 18:54:42 -07:00

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>
This commit is contained in:
Rebecca Stambler 2019-10-31 18:10:46 -04:00
parent 5be387d313
commit 229318561b

View File

@ -3,14 +3,12 @@ package cache
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 @@ func typeErrorRange(ctx context.Context, fset *token.FileSet, pkg *pkg, pos toke
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 @@ func scannerErrorRange(ctx context.Context, fset *token.FileSet, pkg *pkg, posn
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()
}