Repository: go
Issue: x/tools/gopls: Hover: panic in lookup{ObjectByName,DocLinkSymbol}
Labels: NeedsInvestigation,gopls,Tools,gopls/telemetry-wins

```
#!stacks
("bug.Reportf" || "runtime.sigpanic") &&
   ("lookupObjectByName" || "lookupDocLinkSymbol")
```
Issue created by [stacks](https://pkg.go.dev/golang.org/x/tools/gopls/internal/telemetry/cmd/stacks).

```go
func lookupObjectByName(pkg *cache.Package, pgf *parsego.File, name string) types.Object {
	scope := pkg.Types().Scope()
	fileScope := pkg.TypesInfo().Scopes[pgf.File]
	pkgName, suffix, _ := strings.Cut(name, ".")
	obj, ok := fileScope.Lookup(pkgName).(*types.PkgName) // <--- panic
```
Variant after the function was renamed:
```go
func lookupDocLinkSymbol(pkg *cache.Package, pgf *parsego.File, name string) types.Object {
	scope := pkg.Types().Scope()

	prefix, suffix, _ := strings.Cut(name, ".")

	// Try treating the prefix as a package name,
	// allowing for non-renaming and renaming imports.
	fileScope := pkg.TypesInfo().Scopes[pgf.File]
	if fileScope == nil {
		// This is theoretically possible if pgf is a GoFile but not a
		// CompiledGoFile. However, we do not know how to produce such a package
		// without using an external GoPackagesDriver.
		// See if this is the source of golang/go#70635
		if slices.Contains(pkg.CompiledGoFiles(), pgf) {
			bug.Reportf("missing file scope for compiled file")  //  <--- reached
		} else {
			bug.Reportf("missing file scope for non-compiled file")
		}
```

This stack `l9BGAQ` was [reported by telemetry](https://storage.googleapis.com/prod-telemetry-merged/2024-09-18.json):

- `crash/crash`
- [`runtime.gopanic:+69`](https://cs.opensource.google/go/go/+/go1.23.0:src/runtime/panic.go;l=804)
- `runtime.panicmem:=262`
- [`runtime.sigpanic:+19`](https://cs.opensource.google/go/go/+/go1.23.0:src/runtime/signal_unix.go;l=900)
- [`go/types.(*Scope).Lookup:+10`](https://cs.opensource.google/go/go/+/go1.23.0:src/go/types/scope.go;l=83)
- [`golang.org/x/tools/gopls/internal/golang.lookupObjectByName:+4`](https://cs.opensource.google/go/x/tools/+/gopls/v0.16.1:gopls/internal/golang/comment.go;l=148)
- [`golang.org/x/tools/gopls/internal/golang.parseDocLink:+58`](https://cs.opensource.google/go/x/tools/+/gopls/v0.16.1:gopls/internal/golang/comment.go;l=129)
- [`golang.org/x/tools/gopls/internal/golang.hover:+43`](https://cs.opensource.google/go/x/tools/+/gopls/v0.16.1:gopls/internal/golang/hover.go;l=177)
- [`golang.org/x/tools/gopls/internal/golang.Hover:+4`](https://cs.opensource.google/go/x/tools/+/gopls/v0.16.1:gopls/internal/golang/hover.go;l=109)
- [`golang.org/x/tools/gopls/internal/server.(*server).Hover:+30`](https://cs.opensource.google/go/x/tools/+/gopls/v0.16.1:gopls/internal/server/hover.go;l=51)
- [`golang.org/x/tools/gopls/internal/protocol.serverDispatch:+335`](https://cs.opensource.google/go/x/tools/+/gopls/v0.16.1:gopls/internal/protocol/tsserver.go;l=503)
- [`golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5`](https://cs.opensource.google/go/x/tools/+/gopls/v0.16.1:gopls/internal/protocol/protocol.go;l=160)
- [`golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52`](https://cs.opensource.google/go/x/tools/+/gopls/v0.16.1:gopls/internal/lsprpc/lsprpc.go;l=509)
- [`golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2`](https://cs.opensource.google/go/x/tools/+/gopls/v0.16.1:internal/jsonrpc2/handler.go;l=35)
- [`golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3`](https://cs.opensource.google/go/x/tools/+/gopls/v0.16.1:internal/jsonrpc2/handler.go;l=103)
- `runtime.goexit:+0`
```
golang.org/x/tools/gopls@v0.16.1 go1.23.0 linux/amd64 vscode (1)
```
Dups: z79pXw p3-DZQ