Gopls: Contributing

Contributions are welcome! However, development is fast moving, and we are limited in our capacity to review contributions. So, before sending a CL, please please please:

When you send a CL, it should include:

During code review, please address all reviewer comments. Some comments result in straightforward code changes; others demand a more complex response. When a reviewer asks a question, the best response is often not to respond to it directly, but to change the code to avoid raising the question, for example by making the code self-explanatory. It’s fine to disagree with a comment, point out a reviewer’s mistake, or offer to address a comment in a follow-up change, leaving a TODO comment in the current CL. But please don’t dismiss or quietly ignore a comment without action, as it may lead reviewers to repeat themselves, or to serious problems being neglected.

For more detail, see the Go project’s contribution guidelines.

Finding issues

All gopls issues are labeled as such (see the gopls label). Issues that are suitable for contributors are additionally tagged with the help-wanted label.

Before you begin working on an issue, please leave a comment that you are claiming it.

Getting started

Most of the gopls logic is in the golang.org/x/tools/gopls/internal directory. See design/implementation.md for an overview of the code organization.

Build

To build a version of gopls with your changes applied:

cd /path/to/tools/gopls
go install

To confirm that you are testing with the correct gopls version, check that your gopls version looks like this:

$ gopls version
golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@(devel)

Getting help

The best way to contact the gopls team directly is via the #gopls-dev channel on the gophers slack. Please feel free to ask any questions about your contribution or about contributing in general.

Error handling

It is important for the user experience that, whenever practical, minor logic errors in a particular feature don’t cause the server to crash.

The representation of a Go program is complex. The import graph of package metadata, the syntax trees of parsed files, and their associated type information together form a huge API surface area. Even when the input is valid, there are many edge cases to consider, and this grows by an order of magnitude when you consider missing imports, parse errors, and type errors.

What should you do when your logic must handle an error that you believe “can’t happen”?

Note also that panicking is preferable to log.Fatal because it allows VS Code’s crash reporting to recognize and capture the stack.

Bugs reported through bug.Errorf and friends are retrieved using the gopls bug command, which opens a GitHub Issue template and populates it with a summary of each bug and its frequency. The text of the bug is rather fastidiously printed to stdout to avoid sharing user names and error message strings (which could contain project identifiers) with GitHub. Users are invited to share it if they are willing.

Testing

The normal command you should use to run the tests after a change is:

gopls$ go test -short ./...

(The -short flag skips some slow-running ones. The trybot builders run the complete set, on a wide range of platforms.)

Gopls tests are a mix of two kinds.

Don’t hesitate to reach out to the gopls team if you need help.

CI

When you mail your CL and you or a fellow contributor assigns the Run-TryBot=1 label in Gerrit, the TryBots will run tests in both the golang.org/x/tools and golang.org/x/tools/gopls modules, as described above.

Furthermore, an additional “gopls-CI” pass will be run by Kokoro, which is a Jenkins-like Google infrastructure for running Dockerized tests. This allows us to run gopls tests in various environments that would be difficult to add to the TryBots. Notably, Kokoro runs tests on older Go versions that are no longer supported by the TryBots. Per that policy, support for these older Go versions is best-effort, and test failures may be skipped rather than fixed.

Kokoro runs are triggered by the Run-TryBot=1 label, just like TryBots, but unlike TryBots they do not automatically re-run if the “gopls-CI” result is removed in Gerrit. To force a re-run of the Kokoro CI on a CL containing the Run-TryBot=1 label, you can reply in Gerrit with the comment “kokoro rerun”.

Debugging

The easiest way to debug your change is to run a single gopls test with a debugger.

See also Troubleshooting.

Documentation

Each CL that adds or changes a feature should include, in addition to a test that exercises the new behavior:

The release note should go in the file named for the forthcoming release, for example release/v0.16.0.md. (Create the file if your feature is the first to be added after a release.)

Design documentation


The source files for this documentation can be found beneath golang.org/x/tools/gopls/doc.