Граф коммитов

5658 Коммитов

Автор SHA1 Сообщение Дата
Rebecca Stambler 9a0e0bbb74 internal/lsp/source: allow users to set new options for network access
These options were added in CL 274532, but it's not possible for users
to actually set them.

Change-Id: I85642ada017f225d4d77e4dfc97fe13847f4091a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275442
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-04 21:17:34 +00:00
Rebecca Stambler 73cf035bae internal/lsp: fix handling of //-style comments in CRLF files
As part of the earlier changes, I didn't realize that multiple //-style
comments would be grouped as one *ast.Comment, even though they are
multiple comment tokens. Handle the possibility of multiple consecutive
comment tokens.

Fixes golang/go#42923

Change-Id: I6bc6cbdfb28a8e60c699288528566e406f27514c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275012
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-04 16:22:04 +00:00
Rebecca Stambler 6607ba8a66 internal/lsp/source: default experimentalDiagnosticsDelay to 250ms
We've been aiming to enable diagnostic debouncing by default, and now
that CL 269197 is merged, I think it's time to do that.

I know that the experimental setting had it at 200ms, but the 250ms was
specified in golang/go#42693, so I'm not sure which is preferable.

Also, fix a bug I introduced in CL 269197, which set alwaysAnalyze to
true for diagnoseChangedFiles. This should only be used for testing.

Add a requirement for 1.13 to one test that relies on good overlay
support (loading the file directly produced a different response from
the full workspace load).

Fixes golang/go#42693

Change-Id: I49b764a8d473a66a01ef0f2c6f4cbe2d512fd64e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274445
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-04 16:16:41 +00:00
Meng Zhuo a679dec0fd internal/lsp: force LANG setting while difftest
difftest using output of GNU diff, which will be translated based on
LANG settings.

Fixes golang/go#42962

Change-Id: Id4ae22da04077eb7cda7faace306fdbe1836ec60
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274992
Trust: Meng Zhuo <mzh@golangcn.org>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-04 13:55:11 +00:00
Rebecca Stambler 545788942d internal/lsp: separate the environment's value of GO111MODULE out
We adjust the value of GO111MODULE to "auto" when running the go
command, since it handles more edge cases. However, in some cases, we
may want to know the environment's actual value of GO111MODULE, so
separate out these two concepts.

Also, as of Go 1.13, `go env` reports GO111MODULE, so add it to the
environmentVariables, but only for Go versions >= 1.13.

Removed a regression test that doesn't seem very important--looks like
even `go env` will fail with GO111MODULE=on and a malformed GOPATH.
I don't think that it's important that `gopls` continue working in such
a case, since the go command will also fail.

Change-Id: I8147782222261a190d0f1017fe9f6043f2ac0cdb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275013
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-12-04 06:28:50 +00:00
Rob Findley 214da9f3da internal/lsp: update diagnostic snapshotID even if not published
The LSP server tracks the snapshot ID for which diagnostics were last
published, but this ID was not being updated if the publish was
suppressed when there are no changes, which can cause incorrect
diagnostics when snapshots are published out-of-order (a separate bug).

Fix this to update the snapshot ID when the current published
diagnostics match the latest computed diagnostics.

Fixes golang/go#42837

Change-Id: I3634e6f351a479aefa5c9423956720431590d814
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275238
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-04 05:15:55 +00:00
Rebecca Stambler 3949734706 tools, gopls: add pkg.go.dev badges to READMEs
Change-Id: I7f7390048ecd51a7c24c86c65fbc2722fc752270
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275233
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
2020-12-03 23:01:54 +00:00
Rebecca Stambler fe8bd3ca09 internal/lsp: move generated file check out of didModifyFiles
This check doesn't need to be super precise about the snapshot it uses,
and it's only needed in the case of a didChange. We can refactor this
code to simplify it a bit.

Change-Id: I360be78bed236cb188b32b17cc7515bc4a3e42ba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274451
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-12-03 22:54:36 +00:00
Pontus Leitzler 090fee60cc go/analysis/passes/fieldalignment: suggest fix for multi-named fields
Add support for providing a suggested fix when the struct have field
lines with multiple names, such as:

type s struct {
    b bool
    i1, i2 int
    a3 [3]bool
    _ [0]func()
}

This was a leftover from CL 270217.

Change-Id: Icccec5b8b4b82823cee33b7a84d0cccab38b6f45
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273346
Reviewed-by: Michael Matloob <matloob@golang.org>
Trust: Pontus Leitzler <leitzler@gmail.com>
2020-12-03 22:49:13 +00:00
Heschi Kreinick a1a1cbeaa5 gopls/doc: generate JSON too, store as composite literal
Combine the generation of the API json with the generation of the
documentation. This cuts out a step from the generation process, and
allows us to depend on third-party modules. Use litter to print a
composite literal instead of JSON text, which will diff and merge much
better.

The only real drawback is that you have to "go run" from the gopls
module to avoid adding the extra deps to tools.

Sorry about the copy and paste; there's relatively little actual code
change, just a bit in doMain and rewriteAPI.

Change-Id: Iac936d31b7e52651b3b33f27497cfdbd133f1e76
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274373
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-03 20:21:02 +00:00
Heschi Kreinick fa6651ede5 internal/lsp/source: allow opt-out from -mod=readonly, GOPROXY=off
The changes to require more explicit dependency management and network
access are very user-facing, and we may not fully understand their
implications. Allow users to roll them back with options for the moment.
Ideally we'll be able to remove them in a few months after things
stabilize.

Change-Id: I5a5ff7c9f3afa490b9945604109c4e3bd9bd7844
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274532
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-03 19:34:12 +00:00
Heschi Kreinick bd5d160bec internal/lsp: add go get quick fix on failing imports
With -mod=readonly set, we no longer automatically add new requires to
go.mod, even the temporary one. We have the go mod tidy code lens, but
that only works on saved files, even in 1.16 due to golang/go#42491.
Plus we may remove the code lens's network access in the future.

Add a simple quick fix for import errors that runs (the moral equivalent
of) go get on the missing import.

Change-Id: Id5764a37ce7db0dce5370da9d648462aefa2042b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274121
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-03 19:34:02 +00:00
Heschi Kreinick 43adb69d7e internal/lsp: disable network access for some go commands
For users with poor network connections, go command invocations that
access the network may hang up for long periods of time. Even for
users with good network connections, accessing proxy.golang.org or
github can take a few seconds, which is a long time to lock up an
editor.

Disable network access via GOPROXY=off when running most go commands.
There are two notable exceptions. First, the initial workspace load is
allowed, though subsequent loads are not. My reasoning is that if the
user is opening a project they've just downloaded, they probably expect
to fetch its dependencies. (Also, it's convenient to keep the regtests
going.) The second is the go mod tidy diagnostics, which I hope to
address in a later change. All the other commands that access the
network are at the user's request.

When the workspace load fails due to a dependency that hasn't been
downloaded, we present a quick fix on the go.mod line to do so. The only
way that happens is if there's a manual modification to the go.mod file,
since all of the other quick fixes will do the download. So I don't
think there's a need to present the fix anywhere else.

Updates golang/go#38462.

Change-Id: I470bc1ba790db7c1afee54d0b28fa0c6fd203fb9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274120
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-03 19:33:52 +00:00
Heschi Kreinick 9bc6a9788d internal/lsp: set -mod=readonly in most contexts
Go 1.16 will set -mod=readonly to be the default behavior of the go
command. This CL changes gopls' behavior to be more in line with that.

The model we end up with is more explicit about managing the go.mod.
Previously, adding an import for a package in the module cache but not
in scope would succeed, but add a warning with a quick fix. Now, the
import will fail, again with a quick fix, and the project will not
compile until the require is added. It also means that the go.sum needs
to be in sync. Previously, the go command would update the temporary
go.sum if the user's was out of date, and then we would discard those
changes. Now, loads will fail until the go.sum is brought into sync,
either by `go mod tidy` or the new "update go.sum" command.

The go.sum requirements affect many regtests. I added a DumpGoSum
function to the environment, which prints the txtar format go.sum file
that needs to be added to the workspace. We'll need to keep them in
sync, unfortunately. We could update them on the fly, but that would
slow down the regression tests somewhat and potentially mess up the test
setup. So I'm not sure what to do exactly. Perhaps maintain them
out-of-line in a separate file that could be auto-updated? Dunno.

I also had to add go directives to go.mod files to keep old Go versions
happy.

Multi-module workspace mode currently doesn't create a go.sum file at
all and is held back to the old behavior until it does.

Change-Id: Ib31afc17614afac2f5fbdf31c7fc03a90bd13e3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/268597
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-03 19:32:01 +00:00
Jean de Klerk bdde1628ed internal/lsp: add READMEs that describe tests, how to run tests
I've recently started working on gopls. It's been a fantastic
experience, but the testing strategies here have required non-trivial
mental work to understand. (thanks Rebecca for all your help!)

Now that I understand the testing a bit better, I wanted to codify it
into a readme for the next person that comes along.

I've taken a stab at that: please feel free to suggest heavy edits,
it's just a best-effort attempt.

Change-Id: Ib739d40ef71018521cd904844443e8c9634a10a6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273066
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Jean de Klerk <deklerk@google.com>
2020-12-03 17:03:53 +00:00
Simon Frei 8b44681d7f gopls/doc: fix link to lsp-go.el
Change-Id: I3fecfa77e0e49ad3dc26683e3aaa4f58b4b8ec27
GitHub-Last-Rev: cfbc49022a
GitHub-Pull-Request: golang/tools#260
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275152
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-12-03 17:00:53 +00:00
Rebecca Stambler 2ecf2a5d1b internal/lsp: don't reload invalid build configurations unconditionally
Previously, we would always reload views with invalid build
configurations on every call to reloadWorkspace, even if the metadata
had no reason to be treated as invalid.

Fixes golang/go#42813

Change-Id: I9e0e493228916262908b81bc1b1ab1eb4e4eca9e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274443
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-03 16:35:28 +00:00
Pontus Leitzler bef1c47641 gopls/doc: add fieldalignment to analyzers.md
Add missing documentation for the fieldalignment analyzer.

Change-Id: Ibc36bd27541a565e04eb732bd809eba9138fae94
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274476
Trust: Pontus Leitzler <leitzler@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-02 20:03:35 +00:00
Cuong Manh Le 7534955ac8 cmd/toolstash: drop 387, use softfloat instead
golang.org/cl/258957 dropped 387 support, and golang.org/cl/260017
implements GO386=softfloat, so use it instead.

While at it, also cleanup things related to nacl.

Change-Id: I7bd58c5653dd61635b373f1b219f52bfc53e55e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274752
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-02 10:05:33 +00:00
Peter Weinbergr 92771a23d8 gopls/internal/regtest: TestRenamePackage passes with go 1.16
Instead of skipping the test, insist on 1.16 or later.

See golang/go#41061

Change-Id: Ie13f114039693993d65333ab9194629187a9b6b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274533
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-01 21:08:46 +00:00
Rebecca Stambler 7beb506c84 internal/lsp: improve errors in multi-module workspaces (GO111MODULE=on)
Currently, when a user opens a workspace with no top-level module but
multiple modules in subdirectories, gopls treats that as an invalid
build configuration and reports an error message that may be difficult
for the user to understand (a go list error message about creating a
main module in the top-level directory). Instead, show a more useful
error message about the gopls workspace layout in both the progress bar
and as a diagnostic on every open file.

This fix only works for GO111MODULE=on (for now) because it's a lot
easier to interpret user intent, and the go command will return no
packages. The next step will be to improve error messaging for
GO111MODULE=auto and for users with nested modules.

Updates golang/go#42109

Change-Id: I702ca6745f7e080ff6704ade7843972ab469ccf3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272346
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-01 20:46:55 +00:00
Rebecca Stambler a1b87a1c0d internal/lsp: track all go.mod changes no matter the workspace mode
In some cases (such as presenting more helpful error messages), we need
to know the number of go.mod files in the workspace--not just the
active go.mod files. Track both known and active mod files separately.

Change-Id: I068f76c2930c90cd0fdf5ce637e5934210880f65
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273047
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-01 19:22:19 +00:00
Heschi Kreinick 5fbf2908eb internal/lsp/cache: include missing dependencies in mod tidy key
(source.Package).Imports only returns successful imports, but go mod
tidy looks at all of them, so we need to include MissingDependencies in
the key too.

Change-Id: I790fd8d3cfd8e85be18a435698954e55611cfd8c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274240
Trust: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-01 19:14:55 +00:00
Heschi Kreinick 182cd11f49 internal/lsp/cache: fix race on snapshot.workspaceDirHandle
Detected in
https://storage.googleapis.com/go-build-log/f5978a09/linux-amd64-race_c9dc2583.log.

Change-Id: I0bfae80b5eb8d15388c352980740206137410dc3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274374
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-01 18:02:36 +00:00
Rebecca Stambler ae829c3383 internal/lsp: limit all findModules calls to search 1 million files
Previously, we had an optional file search limit in the findModules
function. We should stay consistent, so change that to a non-optional
default of 1 million files. We should adjust this if it's necessary to
reduce the limit.

Change-Id: I2664a8760362d03d40867c8208ae0b83111cd4f4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273307
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-01 17:15:14 +00:00
Rebecca Stambler ac6f37ff4c internal/lsp: run analyses on changed files before full diagnostics
Without this, analysis diagnostics have to wait until the entire
workspace is analyzed, which has a noticeable latency.

Refactored diagnosePkg out of diagnose to reuse code, and cleaned up
the showMsg and seen file logic a little bit.

Fixes golang/go#42499

Change-Id: I51314dab156dce87dc19eba997c53d2aea428b6c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/269197
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-01 16:13:51 +00:00
Rebecca Stambler fd09bd90d8 internal/lsp: use mode (GOPATH/modules) oriented error messages
We can offer better error messages to users in GOPATH mode. The Go
command has clear error messages indicating where it's looking for
its dependencies, so we can borrow these messages too.

The error message will look like this:
https://user-images.githubusercontent.com/5856771/100292862-bde8bb00-2f4f-11eb-9920-d945ee2c7e87.png

Change-Id: I39d367d0731ea5b7b7bb963699be3003b4fefe86
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274119
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-12-01 06:44:07 +00:00
Rebecca Stambler f0400ba216 internal/lsp: check the value of GO111MODULE before collecting modules
We don't check the value of GO111MODULE before finding all of the
modules in the workspace, meaning we treat the workspace as if it has
modules even if modules are disabled. Before creating a workspace,
we now do check this.

Change-Id: I36b9d13f3b8382e65de36b4b4deed68f5b59e21d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273309
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-01 06:27:05 +00:00
Himanshu 02d27ecf39 Change require 'nvim_lsp' to 'lspconfig' in vim.md
Change-Id: I3cab635216b6e104e79801cc26e0935d75d5c53a
GitHub-Last-Rev: 009b01191f
GitHub-Pull-Request: golang/tools#258
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273386
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2020-12-01 06:06:10 +00:00
Rebecca Stambler 1937afe449 internal/lsp: disable support for symlinks pending decision
We currently have partial, untested support for symlinks. Remove all
support for now until we come up with a decision.

I thought we could re-enable the OpenBSD trybot since we think it was
failing because of the latency of evaluating symlinks, but it seems like
it's still failing.

Updates golang/go#42833

Change-Id: Iece1741def4eaaeffe5fecd10f884c1cce87f449
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273190
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-01 05:30:39 +00:00
Rob Findley dcde6b0efb internal/lsp: only show gc_details diagnostics on saved buffers
gc_details runs against on-disk files, so showing the resulting
diagnostic on unsaved buffers can result in incorrect positions.

Change-Id: I997d01776b9a31dfb2aa731d6d9b1ac34f22f771
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272747
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Robert Findley <rfindley@google.com>
2020-12-01 03:50:11 +00:00
Rob Findley 7470481624 internal/lsp/lsprpc: prefer XDG_RUNTIME_DIR for the daemon socket
If XDG_RUNTIME_DIR is set, it makes more sense as a location for the
gopls daemon socket than TMPDIR.

This avoids auto discovery issues when TMPDIR is overridden for certain
editors.

For golang/go#41266

Change-Id: I5a0a20c6185ca60d8ff03b8d948b17a636aa8404
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274272
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-01 03:00:18 +00:00
Rebecca Stambler 7e522c867c internal/lsp: update modifications to directories at the LSP level
Expanding the set of modifications in the cache package leads to a
mismatch when the didModifyFiles code in text_synchronization.go
processes the list of modifications.

Change-Id: Id0b7fea445103b34838fb9b03aee95a01e454306
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274192
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-12-01 01:59:40 +00:00
Rob Findley bd313628b4 internal/lsp: restore snapshot ID guard for published diagnostics
A guard against publishing stale diagnostics was removed in CL 269677,
because the signficance of diagnoseDetached was overlooked. Restore it.

For golang/go#42837

Change-Id: I911c4707a9c18a632ce32e0c25c43ae2e92135b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274241
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-01 01:50:23 +00:00
Robert Findley bf23c547d2 Revert "internal/lsp/source: simplify workspace symbol package collection"
This reverts commit 852eb6420a.

Reason for revert: accidentally submitted before CL 268539

Change-Id: I0f9bf230bef29cf44e931dbf4574186fdb404359
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274273
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Robert Findley <rfindley@google.com>
2020-12-01 01:28:06 +00:00
Rob Findley 852eb6420a internal/lsp/source: simplify workspace symbol package collection
While evaluating workspace symbols, we avoid duplicate packages per
package path in an effort to save computing time and eliminate duplicate
results. But for simplicity, we later guard to ensure that we don't ever
walk files twice.

We can just rely on this guard to prevent duplication, and walk all
known packages. This ensures we don't miss symbols, at minimal
additional cost, and simplies the code.

Fixes golang/go#42791

Change-Id: I97000dbe29e67bda6071d5119a6edb7c5fa4da80
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272686
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-01 01:24:05 +00:00
Peter Weinbergr fd5f293690 go/analysis: avoid panic in ifaceassert
Presently ifaceassert.go panics if given asserts whose
types reduce to
[]interface{}.(string)
which is illegal Go. Its tests won't even run on such code, but
gopls will happily invoke it. This CL adds a test for nil.

See golang/go#42857

Change-Id: I2791f4bd0b58559e65e6590822ac8f4123989273
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273766
Reviewed-by: Michael Matloob <matloob@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2020-11-30 22:00:05 +00:00
Jean de Klerk 0e8b1ee181 gopls, internal/lsp: support fillstruct for partially-filled structs
This updates fillstruct to work even when the struct is partially
filled. User supplied fields are preserved but comments are blown away.

Preserving comments appears to be very hard with the current ast
library. One possible option is to do manual string shenanigans, but
after exploring that path it seems like A Bad Idea.

Fixes golang/go#39804

Change-Id: Iec0bb93db05d4d726dfa6c77a8139f53b14bcc77
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262018
Run-TryBot: Jean de Klerk <deklerk@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Jean de Klerk <deklerk@google.com>
2020-11-30 20:22:45 +00:00
Muir Manders ca1c149215 internal/lsp: offer type converted completion candidates
For example:

    func wantsInt64(int64)            {}
    func wantsDuration(time.Duration) {}

    func _() {
      for i := range []string{} {
        // inserts "i" as "int64(i)"
        wantsInt64(i<>)

        // inserts "i" as "time.Duration(i)"
        wantsDuration(i<>)
      }
    }

Type converted candidates have a significant score penalty so they
should never outrank a directly assignable candidate, other factors
being equal.

To minimize false positive completions, we don't offer converted
candidates if either:
- The candidate is a deep completion into another package. This avoids
  random "float64(somepkg.SomeVar)" popping up when completing a
  float64.
- Don't offer to convert ints to strings since that's not normally
  what the user wants.

After going back and forth I decided not to include the type
conversion in the candidate label. This means you will just see the
candidate "i" in the completion popup instead of "float64(i)". Type
names add a lot of noise to the candidate list.

I also tweaked the untyped constant penalty to interplay better with
the new type conversion penalty. I wanted untyped constants to be
ranked above type conversion candidates since they are directly
assignable, so I reduced untyped constants' penalty. However, to
continue suppressing untyped constants from random other packages, I
applied a similar heuristic to above where we give a bigger penalty if
the untyped constant is a deep completion from another package.

Fixes golang/go#42764.

Updates golang/go#39207 (untyped constant penalty tweak may improve
this situation).

Change-Id: I565114b3a1c9628285d07200b9dfc45c61e5d898
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272286
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-11-30 20:04:59 +00:00
Rebecca Stambler c5a73c3035 Revert "internal/lsp: use mode (GOPATH/modules) oriented error messages"
This reverts commit ccae4fb384.

Reason for revert: Accidentally submitted too early

Change-Id: I5193554ee78560b1398f571afce56c66b00b7d63
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274118
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-11-30 18:45:08 +00:00
Rebecca Stambler ccae4fb384 internal/lsp: use mode (GOPATH/modules) oriented error messages
We can offer better error messages to users in GOPATH mode. The Go
command has clear error messages indicating where it's looking for
its dependencies, so we can borrow these messages too.

The error message will look like this:
https://user-images.githubusercontent.com/5856771/100292862-bde8bb00-2f4f-11eb-9920-d945ee2c7e87.png

Change-Id: I888b33804eec7f38c329ae2e4343b82fcc22f1df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272166
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-11-30 18:27:53 +00:00
Rebecca Stambler e7a5458643 internal/lsp: fix misspelling in Codelens option
Deprecate the old "codelens" and replace it with "codelenses".

Change-Id: I667ffc5702270d46ce85f8d25837f37569f7048e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273308
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-11-30 17:56:50 +00:00
Rebecca Stambler b5590deeca internal/lsp: move options to correct sections
Some of our options were listed as experimental, despite being fairly
stable and intended for general use. Others were listed as user options,
when they should really be "deprecated" and moved into the internal
options section (which has no public documentation). Moved these various
options into the correct sections.

Fixes golang/go#42674

Change-Id: I89724521f70707f1feb4ecb8b5ed671e988d09eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271420
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-11-25 23:11:58 +00:00
Rebecca Stambler 2e53cd6703 internal/lsp: explicitly watch all known directories
VS Code's file watching API doesn't send notifications about directory
deletions unless you register for them explicitly (see
https://github.com/microsoft/vscode/issues/109754). Rather than watch
every file in the workspace, keep track of every relevant directory and
register file watchers for it.

This CL moves the snapshot's WorkspaceDirectories function to the
session and changes it to a KnownDirectories function. It returns all of
the directories and subdirectories known the session at a given moment.
Top-level directories are marked as such so that their *.{go,mod,sum}
contents can be watched, while subdirectories are just watched by path
so we can be notified of deletions.

Fixes golang/go#42348

Change-Id: Ic6d02dba55b5de89370522ea5d3cf1d198927997
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271438
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
2020-11-25 22:00:14 +00:00
Pontus Leitzler 299f270db4 go/analysis/passes/fieldalignment: add fieldalignment analyser
This change adds Matthew Dempskys maligned analyser as fieldalignment,
modified to provide suggested fixes as well. The pass detect structs
that would take less memory if their fields were sorted.

It is also added to gopls as an opt-in analyser.

Change-Id: I549215807d2fb7244ea4f58739bab98b0dea9c0e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270217
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Pontus Leitzler <leitzler@gmail.com>
2020-11-24 20:20:34 +00:00
Rebecca Stambler d890b968b6 internal/lsp: extract filenames from go command errors
Update the logic that extracts positions from error messages to handle
optional column numbers, and then use that function when extracting
go command errors. This will be useful in parsing go list errors.

Change-Id: Ie68de1439f002c30f785c0c121c5cec4f2fea727
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272095
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-11-24 18:15:41 +00:00
Rebecca Stambler 208275ba88 internal/lsp: switch the default symbol style to dynamic
Fixes golang/go#41760

Change-Id: Ia9b9e5e1e0e549efc69c623abe9877cfcd008f47
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272748
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-11-24 17:38:11 +00:00
Rebecca Stambler 325b08a518 internal/lsp: rewrite the workspace symbol marker tests
The workspace symbol tests are not really resilient to changes and
did not generate/use golden files consistently. This made it really
tricky to switch the workspace symbols defaults.

To improve the workflow, consolidate the different kinds of tests into
one function, generate and use golden files, and require that all of the
workspace symbol queries appear in one file only. Also converted the
brittle workspace symbol regtest to a marker test.

Update golang/go#41760

Change-Id: I41ccd3ae58ae08fea717c7d8e9a2a10330e8c14f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271626
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-11-24 17:38:01 +00:00
Rebecca Stambler ed677e9dcd internal/lsp/tests: factor normalization logic out of cmd tests
Some features (notably, workspace symbols) produce results with file
paths outside of the command-line package. This logic can be useful for
all tests, so factor it out into the shared testing package.

Change-Id: I2e00ebc0174079660c2f07562c50fd9377088475
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272210
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-11-24 16:59:54 +00:00
Rob Findley a30985897b internal/lsp: track diagnostics by reporting source
Our handling of diagnostics has gotten complicated and has recently been
a source of bugs. Heschi and I took a step back and refactored the
diagnostic pass, starting with a new data structure for tracking
diagnostics.

The LSP server now holds a map of URI to collection of diagnostic
reports, which is used to track diagnostics as they are computed by
multiple sources. Additionally, this collection holds a hash of the
last published diagnostic set.

This new information allows us to implement an algorithm for
incrementally updating diagnostics on the server: diagnostics reports
are stored as they are computed for a snapshot, and then published in
(possibly multiple) passes, with the last pass for a snapshot being
marked as 'final'.  In non-final passes, 'publishReports' publishes any
diagnostics that have already been computed for the snapshot, but does
nothing with URIs for which no diagnostics have been computed. In final
passes all diagnostics are reported, with empty diagnostics being
published for any URIs with no diagnostic reports. Any URIs for which no
diagnostic reports were computed are pruned from the diagnostic set. In
all cases, tracking the hash of published diagnostics prevents us from
duplicate publication.

This enables some simplifications of the existing diagnostic logic.
Computing new diagnostics and tracking send diagnostics is now handled
by the same algorithm, avoiding some bookkeeping. It is also no longer
necessary to explicitly clear diagnostics for deletions. This fixes some
previously broken edge cases, for example when packages go out of scope
due to go.mod or gopls.mod changes.

Fixes golang/go#42198

Change-Id: Id0d8d0f7a60f6ffa8c33f0ae41763461f61dab7b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/269677
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-11-24 15:22:09 +00:00