Skip to content

x/tools/gopls: Support external imports source #74353

Open
@podtserkovskiy

Description

@podtserkovskiy

gopls version

I'd like to propose a discussion on adding support for an alternative method of loading the index for "Organize Imports" and unimported completions in gopls.

Background:
The pre-gopls v0.19.0 implementation, ImportsSourceGoimports, relies on the packages.Load("./...") query executed by gopls at startup. While this works with third-party build systems, it is inefficient for large monorepos. Our gopackagesdriver is intentionally restricted from scanning the entire monorepo due to its size, as it would not complete in a reasonable time.

Current Situation:
With the release of gopls v0.19.0, ImportsSourceGopls was introduced to scan the GOMODCACHE directory. However, this approach is incompatible with build systems like Buck or Bazel, which manage dependencies differently.

Proposal:
I propose introducing ImportsSourceExternal, which would allow users to provide an external binary to generate the imports index. This would enable support for unimported symbol completions in our monorepo and could be particularly beneficial for Bazel users, as the deprecation of ImportsSourceGoimports may disrupt these features for them.
The current index-file format is straightforward for an external tool to produce.

Implementation:
To run gopls with a custom build system, users would need to set two environment variables: GOPACKAGESDRIVER and GOPLS_IMPORTS_SOURCE (example name).

Questions:

  • How does this idea resonate with you?
  • Have you considered similar approaches?

Looking forward to your thoughts and any additional insights you might have!

go env

~

What did you do?

~

What did you see happen?

~

What did you expect to see?

~

Editor and settings

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions