Commit Graph

73 Commits

Author SHA1 Message Date
Rob Findley 2d76fa4fd5 gopls/internal/regtest: delete OpenFileWithContent
OpenFileWithContent is identical to CreateBuffer. Delete it in favor of
the latter, which (in my opinion) has the clearer name.

Change-Id: Icf0f017a9a71a273ace6d697c7d669a2df2e3ba8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263206
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-10-16 23:30:35 +00:00
Rebecca Stambler de28cda03d internal/lsp: remove staticcheck and gofumpt from all experiments
Change-Id: I7b60a06ca5442ce2736d3c1a2d55a0f91b4d44fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263197
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-10-16 20:25:18 +00:00
Jean de Klerk 7c89c52d2f x/tools/gopls: add a skipped test for renaming of package
This adds a test that asserts that gopls gracefully recovers from a bad package
name. It does not include the fix for the test, and so this test is skipped: I
took a stab at it but it was a deep spelunk that I wasn't able to make enough
progress on.

Updates golang/go#41061

Change-Id: I86d817396dae5b0211e633721867e811c7d6cf40
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262019
Run-TryBot: Jean de Klerk <deklerk@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Jean de Klerk <deklerk@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-10-16 15:57:21 +00:00
Rob Findley a5d9e455e9 internal/lsp/source: be consistent about command identifiers
The primary identifier for gopls commands was changed from Command.Name
to Command.ID(), but this change was not made in the commands passed
back to the client via ExecuteCommandOptions.

Fix this, and ensure that our regtests actually check commands against
the list of supported commands that has been sent.

For golang/go#41985

Change-Id: If566584f157e8a86d26eac6353dbfd772b298cfc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262597
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: Heschi Kreinick <heschi@google.com>
2020-10-15 18:20:29 +00:00
Rebecca Stambler 0112737ef1 gopls/internal/regtest: add a test for switching from modules to GOPATH
Fixes golang/go#40487

Change-Id: I79457a8de559da2a9a3ffabdb315f4d35345c8a0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/261738
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-10-13 18:32:36 +00:00
Rebecca Stambler ec925d8b1d gopls/internal/regtest: add a failing test for swig
Fixes golang/go#37660

Change-Id: I4607142af03224820e8350a85eca722586b150b5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/261140
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-10-13 01:55:53 +00:00
Rebecca Stambler 5bd0538631 internal/lsp: move the workspaceMode into the snapshot
Workspace mode makes more sense as a property of the snapshot, since
it is determined based on the modules in the workspace. Move it to the
snapshot and enable the GOPATH to modules test. The mode switch means
that we may run `go mod` commands before a `go.mod` is on-disk, so add
handling for that case.

Also, remove the code added in CL 258121 to treat packages starting with
a "_/" the same way as command-line arguments--that's not actually
correct because perfectly valid packages can also have a "_/" package
path prefix.

Fixes golang/go#40340

Change-Id: I35044f5d108983ba00df1359698bf14217caa982
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260078
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-10-12 19:26:20 +00:00
Rebecca Stambler 96877f285f internal/lsp, gopls: require a "gopls_" prefix on all commands
Updated the generator to check for this. Necessary to fix command name
collision in VS Code Go. Not the nicest solution, but seemed like the
least invasive one.

The codelens configuration is a little strange now, with the "gopls_"
prefixes, but the alternative is adding the prefix when processing the
config and that would make the default look different from the example.

Fixes golang/go#41187

Change-Id: I5cf42f4a96f6252016dcd5c40a4ac401e1b30a8f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259204
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-10-09 03:22:23 +00:00
Rebecca Stambler ffec97847f internal/lsp: handle major versions above v0/v1 in workspace module mode
Workspace mode did not yet support major versions other than v0/v1. To
do so, we have to check the major version before creating the fake gopls
workspace pseudoversion that goes in the workspace module.

Fixes golang/go#41807

Change-Id: I108fe504fdf9e9a0ce23f7102991c9ae78f12a9f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260004
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-10-08 17:44:24 +00:00
Rebecca Stambler 9df69603ba internal/lsp: don't pass build flags to `go mod` commands
This is a temporary fix--golang/go#41826 is a better approach.

Fixes golang/go#41803

Change-Id: Ia055c5e171fe5d4f6d67e9e2e9e7c85fe254605e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260000
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-10-08 02:52:39 +00:00
Rebecca Stambler d5f20aad3b gopls: add regtest mode for experiments, like workspace module tests
This CL adds another regtest mode for trying out experiments, like the
workspace module mode. Before this CL, we lost coverage for default
mode when we turned experimental module mode on by default.

Removed TestNoWorkspaceModule, as it was just a placeholder until this
mode was available.

Change-Id: Ie3e4c2daec3e635c188bafa25b33dd178da875a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258518
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-10-07 01:32:53 +00:00
Rebecca Stambler 45061abf50 internal/lsp: add support for an "enable all experiments" settings
This setting automatically turns on all of the off-by-default gopls
features so that users can opt in to all experiments.

Fixes golang/go#41763

Change-Id: Ia6998128649a081c2a1e8eb08c2db6d795a73143
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260002
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-07 01:14:59 +00:00
Rebecca Stambler a00137c514 internal/lsp: default to workspace module mode even with vendor dirs
We were previously opting out of workspace module mode when any module
had vendor directories. While we still haven't decided how to handle
vendoring, it simplifies things to opt experimentalWorkspaceModule users
in to the workspace module mode when they have modules with vendoring.

Temporarily require default mode for the inconsistent vendoring test
(golang/go#41819).

Fixes golang/go#41725

Change-Id: Ifa494daea51a2a3bb2e6bc3026bfb9e8118d31a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259623
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-10-07 00:01:20 +00:00
Heschi Kreinick 23a3aa10a2 internal/lsp: improve handling of files not in views
didModifyFiles and DidModifyFiles were tightly coupled but also repeated
each other's work a bit, and inconsistencies in the implementation led
to golang/go#41777.

Push all the work of assigning a "best view" down to the Session, and
always assign it somewhere, matching the logic in ViewOf. This would
in principle allow us to diagnose random files, but we only diagnose
workspace packages.

Fixes golang/go#41777.

Change-Id: I6dab32b98bdff6edd07032d84a8fec1b82ecd283
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259877
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>
2020-10-06 18:39:45 +00:00
Rebecca Stambler 576e169c3d internal/lsp: fix hover for builtin error method (Error)
Looks like this may never have worked. "Error" does not appear in the
builtin package's scope, so we have to look up "error" and then find
the method. A little convoluted, but it works.

Change-Id: I5fe4e96d5c51a1fdc683e44b9a80e0cbdab85422
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259143
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: Peter Weinberger <pjw@google.com>
2020-10-05 18:50:03 +00:00
Rebecca Stambler 39ee293a30 gopls: add test for `go mod tidy` diagnostics in multiple modules
Just a simple test that confirms that diagnostics work in multi module
mode. There are still a lot of edge cases with interdependent modules
that should be covered.

Change-Id: I3a489071346d3fce12b21c48a727ca1db4cfc57e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259140
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-10-02 18:24:19 +00:00
Rob Findley 08f19738fa gopls/internal/regtest: only run in singleton mode
singleton mode is naturally less flaky and faster than forwarded mode,
and provides 98% of the coverage.

Regtests have started to time-out in some particularly slow
environments.  Rather than not be able to write more regtests, let's
first run only in singleton mode by default.

I'll set up Kokoro CI to run in all modes.

Change-Id: I6b1c11b75f6c8fe002c123ab75b02f674e67e442
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259137
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: 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-10-02 16:18:17 +00:00
Rebecca Stambler 22683886a9 internal/lsp: fix go.mod creation without experimental workspace module
We were previously adding modules to the snapshot, even if they weren't
relevant without the workspace module mode. Now, check that the modules
are relevant before adding them.

Change-Id: Ib7600482992d538db2f7451863fee5709a35ffb3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258719
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-10-02 14:15:43 +00:00
Rebecca Stambler 0d28ed0cbe gopls: add a test that mirrors govim's -mod=readonly test
This isn't strictly necessary, but we've broken it a number of times,
and it's easier to have a regtest for it. When golang/go#41437 is resolved, we
might consider making this a -mod=mod test or something.

Also, added a wrapper for RunGoCommand.

Change-Id: I75db585549d84dacde9d3efbc6e02a7ba4e005aa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258803
Reviewed-by: Heschi Kreinick <heschi@google.com>
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>
2020-10-02 05:59:58 +00:00
Rebecca Stambler 4e032a7e1e internal/lsp: fix and add a test for non-workspace module mode
This issue was reported on Slack. We need to run more tests in the
default mode, but this is a quick fix.

Change-Id: Ic29d0332aa0410b6e80f77d894c8c007c7f251fa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258657
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-10-01 21:53:43 +00:00
Rebecca Stambler 1e3611d215 internal/lsp: remove logic for re-creating a view when a go.mod changes
This is no longer necessary now that we modify the modules field based
on newly created/deleted modules.

There was a race condition setting the metadata--we were reusing old
metadata that may have already been cached in some instances. Now, we
always override metadata.

Also, disabled the TestUseGoplsMod test -- there seems to be an issue
with it. Will discuss this offline in the AM.

Change-Id: Ie8c97557d4f0a319051256e5f130b9cdae479928
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258121
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-10-01 18:12:13 +00:00
Rebecca Stambler 2e5f0cfadf internal/lsp: remove all but one use of the view's modURI field
The view reinitialization logic appears to be broken, and so needs one
remaining use of the modURI, which be fixed in a follow-up. Every other
use of view.modURI is removed.

Updates golang/go#32394

Change-Id: Ic051ed848c30e6981d42a576fb35f40efbeb17a6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/257417
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-30 20:43:29 +00:00
Rob Findley a6f32d173b gopls/internal/regtest: allow cleanup to fail on windows
Due to Windows' default file locking and the fact that regtests shell
out to the go command, cleanup sometimes fails.

This is causing trybot flakes, increasingly as of late. Since the
tempdir will eventually be cleaned up on the trybots anyway, don't fail
on windows.

For golang/go#38490

Change-Id: I136d97143baba1d98777db51daa062cf0e42e33e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258315
Trust: Robert Findley <rfindley@google.com>
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>
2020-09-30 20:10:28 +00:00
Rebecca Stambler f1e51e6b94 internal/lsp: stop using modURI as much as possible
This change switches over load and RunProcessEnvFunc to use the
snapshot's modules instead of the view's modURI. These do not seem to
have been the racy parts of CL 257417.

Change-Id: I317a350fc4b0c62d77858455a0e2e61148804ecd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/257969
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-09-29 19:10:02 +00:00
Rob Findley 5272f303b6 gopls: fix various staticcheck errors
Do a pass of unused code cleanup and other staticcheck errors.

Change-Id: Iaf5d27c4f5405d4cce3e48fa06a5d46ec757de40
Reviewed-on: https://go-review.googlesource.com/c/tools/+/257965
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-09-29 17:30:36 +00:00
Rob Findley d7fc70abf5 gopls/internal/regtest: always await InitialWorkspaceLoad
There's very little reason not to always await IWL, and none of our
tests actually need to be able to execute before it completes.

Await IWL before running the test func.

Change-Id: Ia0626aa4e4c6cfa89dc5d03075b6bd797574a8dc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258078
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-29 16:13:45 +00:00
Rob Findley 19e0367891 internal/lsp/cache: use gopls.mod for the workspace module if it exists
When building the workspace module, prefer a gopls.mod file located at
the root of the view if it exists.

Also do some minor documenting/cleanup along the way.

For golang/go#32394

Change-Id: If87729a766d37e6c834fefe40cfb47b67a36a60c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/256582
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-09-28 18:20:47 +00:00
Rob Findley 42b62fc938 gopls/internal/regtest: fix data race when printing logs
Lock around log access in regtests. This flake was relatively rare in
regtests because of the serial nature of our jsonrpc2 implementation,
but was nonetheless racy.

Fixes golang/go#41653

Change-Id: I08674f42b05624a69d33885c2232c9e31866375b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/257957
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
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>
2020-09-28 11:28:10 +00:00
Rebecca Stambler 5d1fdd8fa3 internal/lsp: allow multiple go.mod files in a view
This change allows a view to have multiple go.mod files associated
with it. This doesn't actually make any changes in internal/lsp/cache
with regards to the view's modURI, but it does do the necessary plumbing
in the client packages.

The next CL will delete modURI.

Updates golang/go#32394

Change-Id: I2312efd69c364aed4244ee3769679885a1ebc7e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/256941
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-09-25 19:12:24 +00:00
Rebecca Stambler 0eae6ac92e internal/lsp: add a test for gc annotation details code lens
This change adds a test to check the functionality of the GC details
code lens, including the behavior of toggling it on and off. This
exposed a Windows bug that was mentioned on Slack, which can be fixed by
adjusting the URI.

I also refactored a bit of the code to use a JSON decoder, which
simplifies things a little bit.

Change-Id: I7737107cf020fa35bca245485a3b1a1416920fd2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/256940
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: Peter Weinberger <pjw@google.com>
2020-09-25 14:57:16 +00:00
Rebecca Stambler 0f1c53950d internal/lsp: show orphaned file warnings as diagnostics
Show message warnings are annoying to users. Instead, show a diagnostic
for orphaned files. Right now, it will always be there (instead of on
first open). Not sure if users will find this annoying or helpful.

Fixes golang/go#31668

Change-Id: I5051072b00fee9018d447585fdd9cdfe9df7107a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/256977
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2020-09-24 18:28:24 +00:00
Rebecca Stambler 24570c0594 internal/lsp: handle initial workspace load failure per module
This CL adds diagnostics to the go.mod file if one of the modules in
the workspace is invalid and causes the initial workspace load to fail.
When the module is fixed, the initial workspace load will be retried.

This CL also introduces the *source.ErrorList error type, which will be
useful in the future as a way of producing diagnostics out of errors.

Updates golang/go#32394

Change-Id: Ib8860a4f16c1983b8512f75e26354512d5a9a86d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254753
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-09-24 18:05:18 +00:00
Rob Findley 7bb30d1408 internal/lsp: fix go generate command for subdirs
The go generate command was not honoring its dir argument, instead just
running in the workspace root.

Fixes golang/go#41566

Change-Id: I5fb96a765cf4fb2572e2a8a2e560e02f0760023f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/256818
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-09-24 17:36:56 +00:00
Danish Dua 06f3a46a9d gopls/internal/regtest: add benchmarks for completions
This change adds benchmarks for completions running against x/tools
codebase. We still maintain support for manually configured completion
benchmarks through the CLI; run instructions are added as comments in
code.

Change-Id: I3bcf7edac183397ad01755b767798925c4bd30ba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/256877
Run-TryBot: Danish Dua <danishdua@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Danish Dua <danishdua@google.com>
2020-09-24 16:27:44 +00:00
Heschi Kreinick 4aa5c68dc7 internal/lsp: remove multi-module test cases
As we begin testing multi-module workspace, clean up existing
multi-module marker tests. Most of their coverage was redundant with reg
tests already. Add a couple to cover the remainder.

This is probably not strictly necessary but it was easier to remove the
tests than worry about how to support them in multi-module mode.

Change-Id: I54cca5eea60e0679759f7d39131c5cd015fb0154
Reviewed-on: https://go-review.googlesource.com/c/tools/+/256361
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-09-21 20:20:10 +00:00
Rebecca Stambler 78fed78f7d internal/lsp: handle modifications to the workspace module
We should be able to smoothly add and remove modules from the workspace.
This change moves the module-related fields from the view into the
snapshot so that they can be easily modified and recomputed. The
workspace module is now a workspaceModuleHandle.

Updates golang/go#32394

Change-Id: I6ade7f223cc6070a29b6021b825586b753a0daf1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254940
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-09-18 22:49:48 +00:00
Danish Dua 75ebdcb73b gopls/internal/regtest: add expected ranges in completion tests
This change adds tests for package completion in multiline comments and package completion on a newline. It also adds expected ranges in completion tests since simply testing for returned item labels won't catch regression. For more info, see the discussion at https://go-review.googlesource.com/c/tools/+/253177.

Change-Id: Ia42e2645e26647617b32f676952767d2da90e427
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255278
Run-TryBot: Danish Dua <danishdua@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Danish Dua <danishdua@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-17 19:21:54 +00:00
Rebecca Stambler c537a342dd internal/lsp: pass options by reference instead of by value
We were previously behaving as though the slice/map values in the
options struct could be modified directly. The options should be cloned
before modification. Also, convert any usage of source.Options to
*source.Options.

Fixes golang/go#39592

Change-Id: Ib39f668bca0fa1038162206bd7793fd2049af576
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254558
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-09-16 22:53:23 +00:00
Rob Findley c8d9e05b1c gopls/internal/regtest: simplify expectation return values
Returning 'metBy' from expectations was not an ideal API, as extracting
the result value was cumbersome and error prone. It also forced quite a
bit of plumbing.

Using OnceMet, we can improve this by instead using a 'ReadDiagnostics'
expectation that reads diagnostics into a variable.

For golang/go#39384

Change-Id: Ia73e5b496089240df3200626e5696305cb507c9a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255126
Trust: Robert Findley <rfindley@google.com>
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>
2020-09-16 12:40:19 +00:00
Rob Findley 6ec2cde963 internal/lsp/source: add some additional symbol downranking
Downrank symbols if they are:
 1. Unexported and outside of the workspace. Since one wouldn't jump to
    these symbols to e.g. view documentation, they are less relevant.
 2. Fields and interface methods. Usually one would jump to the type
    name, so having fields highly ranked can be noisy.

To facilitate this change and more generally clean up, symbolCollector
is refactored to pass around slices of *ast.Idents rather than build up
'.' separated names as it traverses nested nodes.

For golang/go#40548

Change-Id: Ice4b91cee07b74a13a9b0007fda5fa9a8e447976
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254037
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>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
2020-09-16 12:25:06 +00:00
Rob Findley e20053b796 gopls/internal/regtest: remove ExpectNow
ExpectNow was surpassed by OnceMet, which serves the same purpose but is
atomic. Since it's no longer used, remove it.

Change-Id: I8ae6c54c2e558e57ba17d2ff7917994c9a80b234
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255125
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-09-16 12:03:49 +00:00
Rob Findley 797bd0f00c gopls/internal/regtest: simplify regtest EditorConfig
WithEditorConfig(fake.EditorConfig{...}) seemed like unnecessary
boilerplate. Simplify the option to just 'EditorConfig'.

Change-Id: I11a3045388f8e642caff78a3f0caa13374b4713a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255124
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-09-16 12:02:33 +00:00
Rob Findley cbbbe6237a gopls/internal/regtest: add an InitialWorkspaceLoad expectation
The pattern of awaiting initial workspace load has become very common in
regtests. Factor out an expectation variable for this, to clean up.

Change-Id: I2fe0ad94e2584e447baa57b23d4fdf9f8550772e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255123
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-09-16 12:01:37 +00:00
Rob Findley bf5c620a10 gopls/internal/regtest: move expectations to their own file
We've accumulated a lot of expectations, that could benefit from some
cleanup. Move them to a new file, and reorganize a bit as some of the
logical sections had gotten mixed up.

This change is purely moving code, no other changes.

Change-Id: Ib0a86a5cd686b167e555d5fae77d20d02cfd67a1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255122
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-09-16 12:01:01 +00:00
Rebecca Stambler f4cefd1cb5 internal/lsp: enable multi-module workspace mode by default in tests
This change enables the multi-module workspace mode by default, so that
we can catch all of the test failures and edge cases. It is still
disabled in GOPATH mode and for any workspaces that contain a module
with a vendor directory.

A few minor changes had to be made to handle changes caused by the
workspace module pseudoversions.

Updates golang/go#32394

Change-Id: Ib433b269dfc435d73365677945057c1c2cbb1869
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254317
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: Heschi Kreinick <heschi@google.com>
2020-09-15 20:16:39 +00:00
Rebecca Stambler 97363e29fc internal/lsp: handle staticcheck in didChangeConfiguration
As we have modified the ways that we control which analyzers get
executed for a given case, we have lost the behavior of enabling and
disabling staticcheck smoothly. This CL splits out the staticcheck
analyzers from the main group so that the "staticcheck" setting can
override whether or not a given staticcheck analysis is enabled.

Fixes golang/go#41311

Change-Id: I9c1695afe4a8f89cd0ee50a79e83b2f42a2c20cb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254038
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-13 03:21:22 +00:00
Rebecca Stambler 7ad463ce66 gopls/internal/regtest: add a test for new symbols in test variants
I believe this has been fixed by previous file watching improvements.

Fixes golang/go#38358

Change-Id: I8feba96af8c87795533bf31769e2fcdbbb96d309
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253797
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2020-09-11 15:33:31 +00:00
Rebecca Stambler d179df38ff internal/lsp/cache: automatically construct the workspace module
This change adds an experimental configuration, which when enabled,
shifts gopls to operate in multi-module mode. It implements the
super-module as described in
https://github.com/golang/proposal/blob/master/design/37720-gopls-workspaces.md.
Replace directives are also added when a workspace module requires
another workspace module (which has not yet been mentioned in the design
doc).

A user-provided workspace gopls.mod file is not yet supported, as it is
not yet testable. Clients will need to add support for change
notifications for the gopls.mod once it is added.

Updates golang/go#32394

Change-Id: I5089358603bca34c5c8db9e5a00f93e1cca0b93f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/247819
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-11 04:00:25 +00:00
Rebecca Stambler 53e29e9d12 internal/lsp: show a warning message when opening an "orphaned" file
Build tags are a common stumbling block for users of gopls, as build
tagged files may be excluded from the initial workspace load without a
clear warning. This change adds a check for every opened file to confirm
if it maps to a package. If not, we show a message with suggestions.

A follow-up improvement might be to check if the opened file actually
has build tags to make the error message more precise (and give a better
example config).

Updates golang/go#31668

Change-Id: I829d8546edea65aa08274021bfde8ea2fb6eeaa1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253798
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-10 16:52:16 +00:00
Rob Findley d6107fe4b8 gopls/internal/regtest: skip failing test for go1.13 and below
I missed that this test was failing when fixing the 1.12 build, because
I forgot that I moved the regtests to the gopls module. Hoisted by my
own petard.

Change-Id: I1cf601e730fa7bb92885f55b68845b539e57e1a0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253937
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-10 15:53:27 +00:00