Skip to content

Make it possible to index Go stdlib#244

Draft
jupblb wants to merge 5 commits into
mainfrom
michal/go
Draft

Make it possible to index Go stdlib#244
jupblb wants to merge 5 commits into
mainfrom
michal/go

Conversation

@jupblb
Copy link
Copy Markdown
Collaborator

@jupblb jupblb commented May 7, 2026

No description provided.

jupblb added 5 commits May 6, 2026 17:16
Changes required to successfully index large Go source trees that mix
in-tree dependencies (vendored), build-constrained packages, and
generated files outside the module root. The motivating case is
github.com/golang/go itself, but every change is generic.

- Bump golang.org/x/tools v0.43.0 -> v0.44.0. v0.43.0 calls log.Fatalf
  inside packages.Load when the loader is asked to import a vendored
  stdlib package that has no type information, which made indexing of
  GOROOT/src impossible. v0.44.0 contains the upstream fix that turns
  this into a recoverable error.

- internal/index/scip.go: skip packages with no syntax files ("unsafe"
  pseudo-package, build-constrained packages such as
  internal/runtime/wasitest with zero matching .go files for the host
  platform). Also tolerate packages whose syntax files were all skipped
  (see visitors change below) via a new firstSyntaxWithDocument helper.

- internal/loader/loader.go: promote in-tree dependencies to project
  packages. `go list ./...` deliberately excludes vendor/ directories,
  so vendored packages would otherwise be loaded only as dependencies
  and never indexed even though their source lives in the tree. Detect
  in-tree-ness via Syntax (with CompiledGoFiles / GoFiles fallbacks)
  because some loaders, including the stdlib's vendored packages
  loaded via export data, leave GoFiles empty.

- internal/visitors/visitors.go: drop syntax files whose path is
  outside the module root. The Go test driver writes _testmain.go
  shims into $GOCACHE for every <pkg>.test package; those paths
  resolve to ../../../Library/Caches/... and shouldn't be in the
  index.

- internal/visitors/visitor_file.go: when resolving an ImportSpec to
  its loaded package, try the source-level import path first and only
  fall back to pkgName.Imported().Path(). pkg.Imports is keyed by the
  source-level string; a vendor-rewritten resolved path (e.g.
  vendor/golang.org/x/crypto/chacha20) misses every entry and produced
  "Could not find node" warnings that dropped all import references
  to vendored packages.
Adds the Go source tree as a matrix target. Two pieces of plumbing
allow it to share the existing job:

- A new optional matrix.module_root field threads through
  setup-go's cache-dependency-path, scip-go's --module-root, and
  scip stats's --project-root, defaulting to '.' when unset so
  every other entry behaves exactly as before.

- A 3-line GOROOT-export step gated on matrix.name == 'golang'.
  Without it, scip-go silently indexes the runner's system stdlib
  while reporting paths under target/src/, producing an index that
  is missing target's vendor/golang.org/x/... files and includes
  spurious files from the system Go.
- isInTree: check the first parsed syntax file only; all files in a
  Go package share a directory, so a single check is sufficient.
- visitor_file: look up imports directly by the source-level import
  path (pkg.Imports is keyed that way for vendored imports).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant