diff --git a/internal/lsp/source/hover.go b/internal/lsp/source/hover.go index 10fb5417ae..f7fb3cb690 100644 --- a/internal/lsp/source/hover.go +++ b/internal/lsp/source/hover.go @@ -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 }