@@ -12,13 +12,15 @@ import (
12
12
"go/doc/comment"
13
13
"go/token"
14
14
"go/types"
15
+ "slices"
15
16
"strings"
16
17
17
18
"golang.org/x/tools/gopls/internal/cache"
18
19
"golang.org/x/tools/gopls/internal/cache/parsego"
19
20
"golang.org/x/tools/gopls/internal/protocol"
20
21
"golang.org/x/tools/gopls/internal/settings"
21
22
"golang.org/x/tools/gopls/internal/util/astutil"
23
+ "golang.org/x/tools/gopls/internal/util/bug"
22
24
"golang.org/x/tools/gopls/internal/util/safetoken"
23
25
)
24
26
@@ -154,6 +156,18 @@ func lookupDocLinkSymbol(pkg *cache.Package, pgf *parsego.File, name string) typ
154
156
// Try treating the prefix as a package name,
155
157
// allowing for non-renaming and renaming imports.
156
158
fileScope := pkg .TypesInfo ().Scopes [pgf .File ]
159
+ if fileScope == nil {
160
+ // This is theoretically possible if pgf is a GoFile but not a
161
+ // CompiledGoFile. However, we do not know how to produce such a package
162
+ // without using an external GoPackagesDriver.
163
+ // See if this is the source of golang/go#70635
164
+ if slices .Contains (pkg .CompiledGoFiles (), pgf ) {
165
+ bug .Reportf ("missing file scope for compiled file" )
166
+ } else {
167
+ bug .Reportf ("missing file scope for non-compiled file" )
168
+ }
169
+ return nil
170
+ }
157
171
pkgname , ok := fileScope .Lookup (prefix ).(* types.PkgName ) // ok => prefix is imported name
158
172
if ! ok {
159
173
// Handle renaming import, e.g.
0 commit comments