Skip to content

Commit cf92b39

Browse files
committed
internal/lsp: check InRange before calling token.Offset
This shows up every now and then--maybe we need a wrapper function around token.Offset to check the range. Updates golang/go#48249 Change-Id: I9c60bc7cc61fcfb2f4e8c6963586d8b8fbb21835 Reviewed-on: https://go-review.googlesource.com/c/tools/+/348429 Trust: Rebecca Stambler <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> Reviewed-by: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> (cherry picked from commit 0a6f080) Reviewed-on: https://go-review.googlesource.com/c/tools/+/348530
1 parent 7f77468 commit cf92b39

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

internal/lsp/source/hover.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ func HoverInfo(ctx context.Context, s Snapshot, pkg Package, obj types.Object, p
341341
tok2 := s.FileSet().File(node.Pos())
342342
var spec ast.Spec
343343
for _, s := range node.Specs {
344-
if tok2.Offset(s.Pos()) <= offset && offset <= tok2.Offset(s.End()) {
344+
// Avoid panics by guarding the calls to token.Offset (golang/go#48249).
345+
// TODO(rstambler): Investigate this further and adjust if needed.
346+
if InRange(tok2, s.Pos()) && InRange(tok2, s.End()) && tok2.Offset(s.Pos()) <= offset && offset <= tok2.Offset(s.End()) {
345347
spec = s
346348
break
347349
}

0 commit comments

Comments
 (0)