Skip to content

Commit

Permalink
internal/lsp: check InRange before calling token.Offset
Browse files Browse the repository at this point in the history
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 <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
  • Loading branch information
stamblerre committed Sep 8, 2021
1 parent e5f719f commit 0a6f080
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/lsp/source/hover.go
Expand Up @@ -341,7 +341,9 @@ func HoverInfo(ctx context.Context, s Snapshot, pkg Package, obj types.Object, p
tok2 := s.FileSet().File(node.Pos())
var spec ast.Spec
for _, s := range node.Specs {
if tok2.Offset(s.Pos()) <= offset && offset <= tok2.Offset(s.End()) {
// 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
}
Expand Down

0 comments on commit 0a6f080

Please sign in to comment.