mirror of https://github.com/golang/go.git
internal/lsp: remove the TODO and add a test for the hover panic
Fixes golang/go#48249 Change-Id: I86da0f185f414848bf89243737668f1d427c3e4c Reviewed-on: https://go-review.googlesource.com/c/tools/+/348969 Trust: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
c163c3172e
commit
295a39ba3c
|
|
@ -99,3 +99,17 @@ func main() {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Tests that hovering does not trigger the panic in golang/go#48249.
|
||||
func TestPanicInHoverBrokenCode(t *testing.T) {
|
||||
testenv.NeedsGo1Point(t, 13)
|
||||
const source = `
|
||||
-- main.go --
|
||||
package main
|
||||
|
||||
type Example struct`
|
||||
Run(t, source, func(t *testing.T, env *Env) {
|
||||
env.OpenFile("main.go")
|
||||
env.Editor.Hover(env.Ctx, "main.go", env.RegexpSearch("main.go", "Example"))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -342,7 +342,6 @@ func HoverInfo(ctx context.Context, s Snapshot, pkg Package, obj types.Object, p
|
|||
var spec ast.Spec
|
||||
for _, s := range node.Specs {
|
||||
// Avoid panics by guarding the calls to token.Offset (golang/go#48249).
|
||||
// TODO(rstambler): Investigate this further and adjust if needed.
|
||||
if InRange(tok2, s.Pos()) && InRange(tok2, s.End()) && tok2.Offset(s.Pos()) <= offset && offset <= tok2.Offset(s.End()) {
|
||||
spec = s
|
||||
break
|
||||
|
|
|
|||
Loading…
Reference in New Issue