gopls/internal/lsp/source: filter intermediate test variants

This change ensures that intermediate test variant (ITV) packages
are filtered out before type checking in all calls to PackageForFile
or TypeCheck. There should never be any need to type check ITVs
in practice: they contain identical syntax to the regular package,
but differ in their import metadata. Technically this may affect
types of selectors (fields/methods) but we choose to ignore that
as it is bad programming and expensive to accommodate.

Details:
- MetadataForFile now sorts primarily by narrowest and
  secondarily by ITVs.
- source.NarrowestMetadataForFile is a convenience wrapper
  that selects the first non-ITV element.
- PackageForFile now always chooses the narrowest,
  and is renamed NarrowestPackageForFile.
  The sole use of widest, from renameOrdinary, was inlined.
  (One other was replaced by narrowest.)
- The PackageSelector enum (narrowes/widest) is gone.
- TODOs added to think about ITVs in the implicitly
  type checking methods.

Fixes golang/go#57795

Change-Id: Id1e95990bcbc830594d2d5acec7b4f93bc01a501
Reviewed-on: https://go-review.googlesource.com/c/tools/+/487095
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
diff --git a/gopls/internal/lsp/source/workspace_symbol.go b/gopls/internal/lsp/source/workspace_symbol.go
index 17c3a24..6ad1bf6 100644
--- a/gopls/internal/lsp/source/workspace_symbol.go
+++ b/gopls/internal/lsp/source/workspace_symbol.go
@@ -331,17 +331,13 @@
 			if seen[uri] {
 				continue
 			}
-			mds, err := snapshot.MetadataForFile(ctx, uri)
+			meta, err := NarrowestMetadataForFile(ctx, snapshot, uri)
 			if err != nil {
 				event.Error(ctx, fmt.Sprintf("missing metadata for %q", uri), err)
 				continue
 			}
-			if len(mds) == 0 {
-				// TODO: should use the bug reporting API
-				continue
-			}
 			seen[uri] = true
-			work = append(work, symbolFile{uri, mds[0], syms})
+			work = append(work, symbolFile{uri, meta, syms})
 		}
 	}