mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00: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:
parent
5be387d313
commit
229318561b
19
internal/lsp/cache/errors.go
vendored
19
internal/lsp/cache/errors.go
vendored
@ -3,14 +3,12 @@ package cache
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"go/ast"
|
|
||||||
"go/scanner"
|
"go/scanner"
|
||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/tools/go/analysis"
|
"golang.org/x/tools/go/analysis"
|
||||||
"golang.org/x/tools/go/ast/astutil"
|
|
||||||
"golang.org/x/tools/go/packages"
|
"golang.org/x/tools/go/packages"
|
||||||
"golang.org/x/tools/internal/lsp/protocol"
|
"golang.org/x/tools/internal/lsp/protocol"
|
||||||
"golang.org/x/tools/internal/lsp/source"
|
"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 {
|
if err != nil {
|
||||||
return spn, nil // ignore errors
|
return spn, nil // ignore errors
|
||||||
}
|
}
|
||||||
file, m, _, err := ph.Cached()
|
_, m, _, err := ph.Cached()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return spn, 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)
|
s, err := spn.WithOffset(m.Converter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return spn, nil // ignore errors
|
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)
|
return span.Span{}, errors.Errorf("no token.File for %s", ph.File().Identity().URI)
|
||||||
}
|
}
|
||||||
pos := tok.Pos(posn.Offset)
|
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()
|
return span.NewRange(fset, pos, pos).Span()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user