Skip to content

Commit

Permalink
[gopls-release-branch.0.6] all: merge master into gopls-release-branc…
Browse files Browse the repository at this point in the history
…h.0.6

9b8df07 internal/lsp: enable -mod=readonly in workspace module mode
f1f686b internal/lsp: re-enable upgrades for individual dependencies
d8a2a07 go/packages: improve go invocation errors
19db92e internal/lsp/cache: remove mod upgrade code
0cef57b internal/lsp/protocol: use a pointer for code action's disabled field
db4c57d gopls/internal/regtest: split regtests up into multiple packages
f871472 internal/lsp/cache: lock in snapshot.knownFilesInDir
c2bea79 internal/lsp/source: make it an error to rename embedded fields
514964b gopls/internal/hooks: improve license file test
68bf78a internal/lsp/cmd: improve help output of gopls subcommands
4922717 go/analysis/passes/fieldalignment: delete doc style comments in fix
917f61d gopls/internal/regtest: automate counting of editor notifications to await
2972602 internal/lsp: correct links provided in critical error pop-ups
e13398c internal/lsp: display current diagnostics in the debug server
cf1022a gopls: factor out advanced documentation from the README
87bc10f gopls: mention workspaces and build systems in the README
ce34e26 internal/lsp: don't show context cancellation in the progress bar
bec622c gopls: merge README and user.md
7e51fbd gopls/internal/regtest: re-enable android builder

Change-Id: I0e262f49306c7b44d89d994dfa89659fe04b6724
  • Loading branch information
stamblerre committed Feb 1, 2021
2 parents 84af7dd + 9b8df07 commit 4d4ee95
Show file tree
Hide file tree
Showing 81 changed files with 1,193 additions and 1,013 deletions.
1 change: 1 addition & 0 deletions go/analysis/passes/fieldalignment/fieldalignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func fieldalignment(pass *analysis.Pass, node *ast.StructType, typ *types.Struct
// TODO: Preserve comment, for now get rid of them.
// See https://github.com/golang/go/issues/20744
f.Comment = nil
f.Doc = nil
if len(f.Names) <= 1 {
flat = append(flat, f)
continue
Expand Down
9 changes: 9 additions & 0 deletions go/analysis/passes/fieldalignment/testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ type NoNameBad struct { // want "struct of size 20 could be 16"
y int32
z byte
}

type WithComments struct { // want "struct of size 8 could be 4"
// doc style comment
a uint32 // field a comment
b [0]byte // field b comment
// other doc style comment

// and a last comment
}
5 changes: 5 additions & 0 deletions go/analysis/passes/fieldalignment/testdata/src/a/a.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ type NoNameBad struct {
x byte
z byte
}

type WithComments struct {
b [0]byte
a uint32
}
8 changes: 4 additions & 4 deletions go/packages/golist.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"fmt"
"go/types"
exec "golang.org/x/sys/execabs"
"io/ioutil"
"log"
"os"
Expand All @@ -23,6 +22,7 @@ import (
"sync"
"unicode"

exec "golang.org/x/sys/execabs"
"golang.org/x/tools/go/internal/packagesdriver"
"golang.org/x/tools/internal/gocommand"
"golang.org/x/xerrors"
Expand Down Expand Up @@ -865,7 +865,7 @@ func (state *golistState) invokeGo(verb string, args ...string) (*bytes.Buffer,
if gocmdRunner == nil {
gocmdRunner = &gocommand.Runner{}
}
stdout, stderr, _, err := gocmdRunner.RunRaw(cfg.Context, inv)
stdout, stderr, friendlyErr, err := gocmdRunner.RunRaw(cfg.Context, inv)
if err != nil {
// Check for 'go' executable not being found.
if ee, ok := err.(*exec.Error); ok && ee.Err == exec.ErrNotFound {
Expand All @@ -886,7 +886,7 @@ func (state *golistState) invokeGo(verb string, args ...string) (*bytes.Buffer,

// Related to #24854
if len(stderr.String()) > 0 && strings.Contains(stderr.String(), "unexpected directory layout") {
return nil, fmt.Errorf("%s", stderr.String())
return nil, friendlyErr
}

// Is there an error running the C compiler in cgo? This will be reported in the "Error" field
Expand Down Expand Up @@ -999,7 +999,7 @@ func (state *golistState) invokeGo(verb string, args ...string) (*bytes.Buffer,
// TODO(matloob): Remove these once we can depend on go list to exit with a zero status with -e even when
// packages don't exist or a build fails.
if !usesExportData(cfg) && !containsGoFile(args) {
return nil, fmt.Errorf("go %v: %s: %s", args, exitErr, stderr)
return nil, friendlyErr
}
}
return stdout, nil
Expand Down
118 changes: 72 additions & 46 deletions gopls/README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,99 @@
# gopls documentation
# `gopls`, the Go language server

[![PkgGoDev](https://pkg.go.dev/badge/golang.org/x/tools/gopls)](https://pkg.go.dev/golang.org/x/tools/gopls)

gopls (pronounced: "go please") is the official [language server] for the Go language.
`gopls` (pronounced "Go please") is the official Go [language server] developed
by the Go team. It provides IDE features to any [LSP]-compatible editor.

## Status
<!--TODO(rstambler): Add gifs here.-->

It is currently in **alpha**, so it is **not stable**.
You should not need to interact with `gopls` directly--it will be automatically
integrated into your editor. The specific features and settings vary slightly
by editor, so we recommend that you proceed to the [documentation for your
editor](#editors) below.

You can see more information about the status of gopls and its supported features [here](doc/status.md).
## Editors

## Roadmap
To get started with `gopls`, install an LSP plugin in your editor of choice.

The current goal is a fully stable build with the existing feature set, aiming
for the first half of 2020, with release candidates earlier in the year.
* [VSCode](https://github.com/golang/vscode-go/blob/master/README.md)
* [Vim / Neovim](doc/vim.md)
* [Emacs](doc/emacs.md)
* [Atom](https://github.com/MordFustang21/ide-gopls)
* [Sublime Text](doc/subl.md)
* [Acme](https://github.com/fhs/acme-lsp)

This will be the first build that we recommend people use, and will be tagged as the 1.0 version.
You can see the set of things being worked on in the [1.0 milestone], in general
we are focused on stability, specifically, making sure we have a reliable service that produces an experience in module mode that is not a retrograde step from the old tools in GOPATH mode.
If you use `gopls` with an editor that is not on this list, please let us know
by [filing an issue](#new-issue) or [modifying this documentation](doc/contributing.md).

There is also considerable effort being put into testing in order to make sure that we both have a stable service and also that we do not regress after launch.
## Installation

While we may continue to accept contributions for new features, they may be turned off behind a configuration flag if they are not yet stable. See the [gopls unplanned] milestone for deprioritized features.
For the most part, you should not need to install or update `gopls`. Your
editor should handle that step for you.

This is just a milestone for gopls itself. We work with editor integrators to make sure they can use the latest builds of gopls, and will help them use the 1.0 version as soon as it is ready, but that does not imply anything about the stability, supported features or version of the plugins.
If you do want to get the latest stable version of `gopls`, change to any
directory that is both outside of your `GOPATH` and outside of a module (a temp
directory is fine), and run:

## Using
```sh
GO111MODULE=on go get golang.org/x/tools/gopls@latest
```

In general you should not need to know anything about gopls, it should be integrated into your editor for you.
**NOTE**: Do not use the `-u` flag, as it will update your dependencies to
incompatible versions.

To install for your specific editor you can follow the following instructions
Learn more in the [advanced installation
instructions](doc/advanced.md#installing-unreleased-versions).

* [VSCode](doc/vscode.md)
* [Vim / Neovim](doc/vim.md)
* [Emacs](doc/emacs.md)
* [Acme](doc/acme.md)
* [Sublime Text](doc/subl.md)
* [Atom](doc/atom.md)
## Setting up your workspace

`gopls` supports both Go module and GOPATH modes, but if you are working with
multiple modules or uncommon project layouts, you will need to specifically
configure your workspace. See the [Workspace document](doc/workspace.md) for
information on supported workspace layouts.

## Configuration

You can configure `gopls` to change your editor experience or view additional
debugging information. Configuration options will be made available by your
editor, so see your [editor's instructions](#editors) for specific details. A
full list of `gopls` settings can be found in the [Settings documentation](doc/settings.md).

See the [user guide](doc/user.md) for more information, including the how to install gopls by hand if you need.
### Environment variables

## Issues
`gopls` inherits your editor's environment, so be aware of any environment
variables you configure. Some editors, such as VS Code, allow users to
selectively override the values of some environment variables.

If you are having issues with gopls, please first check the [known issues](doc/status.md#known-issues) before following the [troubleshooting](doc/troubleshooting.md#steps) guide.
If that does not give you the information you need, reach out to us.
## Troubleshooting

You can chat with us on:
* the golang-tools [mailing list]
* the #gopls [slack channel] on the gophers slack
If you are having issues with `gopls`, please follow the steps described in the
[troubleshooting guide](doc/troubleshooting.md).

If you think you have an issue that needs fixing, or a feature suggestion, then please make sure you follow the steps to [file an issue](doc/troubleshooting.md#file-an-issue) with the right information to allow us to address it.
## Supported Go versions and build systems

If you need to talk to us directly (for instance to file an issue with confidential information in it) you can reach out directly to [@stamblerre] or [@ianthehat].
`gopls` follows the
[Go Release Policy](https://golang.org/doc/devel/release.html#policy),
meaning that it officially supports the last 2 major Go releases. Though we
try not to break older versions, we do not prioritize issues only affecting
legacy Go releases.

## More information
`gopls` currently only supports the `go` command, so if you are using a
different build system, `gopls` will not work well. Bazel support is currently
blocked on
[bazelbuild/rules_go#512](https://github.com/bazelbuild/rules_go/issues/512).

If you want to know more about it, have an unusual use case, or want to contribute, please read the following documents
## Additional information

* [Using gopls](doc/user.md)
* [Troubleshooting and reporting issues](doc/troubleshooting.md)
* [Integrating gopls with an editor](doc/integrating.md)
* [Contributing to gopls](doc/contributing.md)
* [Design requirements and decisions](doc/design.md)
* [Implementation details](doc/implementation.md)
* [Features](doc/features.md)
* [Command-line interface](doc/command-line.md)
* [Advanced topics](doc/advanced.md)
* [Contributing to `gopls`](doc/contributing.md)
* [Integrating `gopls` with an editor](doc/design/integrating.md)
* [Design requirements and decisions](doc/design/design.md)
* [Implementation details](doc/design/implementation.md)
* [Open issues](https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+label%3Agopls)

[language server]: https://langserver.org
[mailing list]: https://groups.google.com/forum/#!forum/golang-tools
[slack channel]: https://gophers.slack.com/messages/CJZH85XCZ
[@stamblerre]: https://github.com/stamblerre "Rebecca Stambler"
[@ianthehat]: https://github.com/ianthehat "Ian Cottrell"
[1.0 milestone]: https://github.com/golang/go/milestone/112
[gopls unplanned]: https://github.com/golang/go/milestone/124
[LSP]: https://microsoft.github.io/language-server-protocol/
[Gophers Slack]: https://gophers.slack.com/
7 changes: 0 additions & 7 deletions gopls/doc/acme.md

This file was deleted.

37 changes: 37 additions & 0 deletions gopls/doc/advanced.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Advanced topics

This documentation is for advanced `gopls` users, who may want to test
unreleased versions or try out special features.

## Installing unreleased versions

To get a specific version of `gopls` (for example, to test a prerelease
version), run:

```sh
GO111MODULE=on go get golang.org/x/tools/gopls@vX.Y.Z
```

Where `vX.Y.Z` is the desired version.

### Unstable versions

To update `gopls` to the latest **unstable** version, use:

```sh
GO111MODULE=on go get golang.org/x/tools/gopls@master golang.org/x/tools@master
```

## Working on the Go source distribution

If you are working on the [Go project] itself, the `go` command that `gopls`
invokes will have to correspond to the version of the source you are working
on. That is, if you have checked out the Go project to `$HOME/go`, your `go`
command should be the `$HOME/go/bin/go` executable that you built with
`make.bash` or equivalent.

You can achieve this by adding the right version of `go` to your `PATH`
(`export PATH=$HOME/go/bin:$PATH` on Unix systems) or by configuring your
editor.

[Go project]: https://go.googlesource.com/go
7 changes: 0 additions & 7 deletions gopls/doc/atom.md

This file was deleted.

6 changes: 6 additions & 0 deletions gopls/doc/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ Identifier: `gopls.go_get_package`
go_get_package runs `go get` to fetch a package.


### **Check for upgrades**
Identifier: `gopls.check_upgrades`

check_upgrades checks for module upgrades.


### **Add dependency**
Identifier: `gopls.add_dependency`

Expand Down
4 changes: 2 additions & 2 deletions gopls/doc/contributing.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Documentation for contributors

This documentation augments the general documentation for contributing to the
x/tools repository, described at the [repository root](../CONTRIBUTING.md).
x/tools repository, described at the [repository root](../../CONTRIBUTING.md).

Contributions are welcome, but since development is so active, we request that
you file an issue and claim it before starting to work on something. Otherwise,
Expand Down Expand Up @@ -96,7 +96,7 @@ 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](user.md#supported-go-versions) that are no longer supported
[older Go versions](../README.md#supported-go-versions) that are no longer supported
by the TryBots.

## Debugging
Expand Down
8 changes: 4 additions & 4 deletions gopls/doc/daemon.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ will use the same shared daemon.

**Q: Why am I not saving as much memory as I expected when using a shared gopls?**

A: As described in [implementation.md](implementation.md), gopls has a concept
of view/session/cache. Each session and view map onto exactly one editor
session (because they contain things like edited but unsaved buffers). The
cache contains things that are independent of any editor session, and can
A: As described in [implementation.md](design/implementation.md), gopls has a
concept of view/session/cache. Each session and view map onto exactly one
editor session (because they contain things like edited but unsaved buffers).
The cache contains things that are independent of any editor session, and can
therefore be shared.

When, for example, three editor session are sharing a single gopls process,
Expand Down
2 changes: 1 addition & 1 deletion gopls/doc/emacs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Installing `gopls`

To use `gopls` with Emacs, you must first
[install the `gopls` binary](user.md#installation) and ensure that the directory
[install the `gopls` binary](../README.md#installation) and ensure that the directory
containing the resulting binary (either `$(go env GOBIN)` or `$(go env
GOPATH)/bin`) is in your `PATH`.

Expand Down
4 changes: 2 additions & 2 deletions gopls/doc/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ VS Code users should follow [their troubleshooting guide](https://github.com/gol

1. Verify that your project is in good shape by working with it outside of your editor. Running a command like `go build ./...` in the workspace directory will compile everything. For modules, `go mod tidy` is another good check, though it may modify your `go.mod`.
1. Check that your editor isn't showing any diagnostics that indicate a problem with your workspace. They may appear as diagnostics on a Go file's package declaration, diagnostics in a go.mod file, or as a status or progress message. Problems in the workspace configuration can cause many different symptoms. See the [workspace setup instructions](workspace.md) for help.
1. Make sure `gopls` is up to date by following the [installation instructions](user.md#installing), then [restarting gopls](#restart-gopls).
1. Make sure `gopls` is up to date by following the [installation instructions](../README.md#installation), then [restarting gopls](#restart-gopls).
1. Optionally, [ask for help](#ask-for-help) on Gophers Slack.
1. Finally, [report the issue](#file-an-issue) to the `gopls` developers.

Expand Down Expand Up @@ -41,7 +41,7 @@ You may have to change your editor's configuration to pass a `-logfile` flag to

To increase the level of detail in your logs, start `gopls` with the `-rpc.trace` flag. To start a debug server that will allow you to see profiles and memory usage, start `gopls` with `serve --debug=localhost:6060`. You will then be able to view debug information by navigating to `localhost:6060`.

If you are unsure of how to pass a flag to `gopls` through your editor, please see the [documentation for your editor](user.md#editors).
If you are unsure of how to pass a flag to `gopls` through your editor, please see the [documentation for your editor](../README.md#editors).

## Debug memory usage

Expand Down
Loading

0 comments on commit 4d4ee95

Please sign in to comment.