Commit Graph

5554 Commits

Author SHA1 Message Date
Rob Findley bc3cf281b1 go/loader: loosen a test assertion on go/types error messages
In CL 267717, the error message for invalid assignment of untyped values
is being corrected from 'cannot convert ...' to 'cannot use ... as ...
int ...'. This breaks the go/loader tests due to an assertion on the
former message.

Since the Go repo TryBots run x/tools tests, this assertion must be
loosened to allow merging the CL above.

Change-Id: I8a371397c9df58109090b7fd2eaa5b4a600776ef
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267686
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-11-05 00:16:34 +00:00
Heschi Kreinick 22bd85271a internal/lsp: remove organize imports action for go.mod
Per our discussion, it's too slow for a save hook.

Fixes golang/go#38209. (for real this time?)

Change-Id: I264c6d1590a374eff09b09cb1a9162e8e5ff2dc7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267682
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-11-04 19:38:57 +00:00
Heschi Kreinick aefe0b7421 internal/lsp: set correct directness when adding new requires
When adding a require, we should add an `// indirect` comment if that's
what go mod tidy would do.

It's possible I should split Add out from Update and Remove, but this
was quick and easy and I'm not too worried about it for now.

Also minimize the test that covered this case, which was way more
complicated than it needed to be AFAICT.

Fixes golang/go#38914.

Change-Id: I89c44f8573873227c4c9e637d1d31d8c1a6530aa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267578
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-11-04 18:37:02 +00:00
Rob Findley 330dc7d2a4 internal/lsp/cache: assign a static temp workspace dir to the first view
Editors need a way to run commands in the same workspace that gopls
sees. Longer term, we need a good solution for this that supports
multiple workspace folders, but for now just write the first folder's
workspace to a deterministic location:
  $TMPDIR/gopls-<client PID>.workspace.

Using the client-provided PID allows this mechanism to work even for
multi-session daemons.

Along the way, simplify the snapshot reinitialization logic a bit.

Fixes golang/go#42126

Change-Id: I5b9f454fcf1a1a8fa49a4b0a122e55e762d398b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/264618
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-11-04 18:18:50 +00:00
Rebecca Stambler b653051172 internal/lsp/cmd: delete TestDefinitionHelpExample test
Fixes golang/go#32794

Change-Id: I52339d1c49d4737d9f562471777eae9db689f075
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267122
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-11-03 23:54:15 +00:00
Rebecca Stambler ac612affd5 internal/lsp: fix the logic to avoid duplicate file watching
The logic that checked if a file was already being watched by the
default glob pattern was incorrect. Fix it, and use the newly added
InDir function.

Change-Id: Ia7e3851ab5b9fa1fa7590cae3b370676201a9141
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267119
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-03 19:00:53 +00:00
Rebecca Stambler 6d1a7fa378 internal/imports: handle out of range panic in modInfo
Fixes golang/vscode-go#882

Change-Id: If238f61be5653c159293a811bf9728029701de48
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267125
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-03 18:34:43 +00:00
Rebecca Stambler 7ad286ab5e internal/lsp: check for nil snapshot in didModifyFiles
Updates golang/vscode-go#879

Change-Id: I27c54cbfcf312d9c570b910401a4c504fd5cce7d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267124
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-03 17:06:40 +00:00
Rebecca Stambler c64668f4c9 internal/lsp: do not rename in compiler directive comments
Fixes golang/go#42331

Change-Id: I63599c961ac963b22dacd706b312807678c0a9d6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267121
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-11-03 16:52:30 +00:00
Rebecca Stambler f46e424521 internal/lsp/cache: handle nil pointer exception in missing module error
Fixes golang/go#42349

Change-Id: I171495005298b8f55ae75ded5c2f40e457748082
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267118
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-11-02 21:20:25 +00:00
Peter Weinbergr 3f6de07740 internal/lsp: make Diagnostics.CodeDescription a pointer
This avoid an embedded URI defaulting to ""
(https://github.com/golang/go/issues/42314)

Fixes:Fixes golang/go#42314

Change-Id: I614171d4ec80d139f5511b953d30f8385c2c7d5e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267106
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Peter Weinberger <pjw@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-11-02 20:58:24 +00:00
Keith Randall 3288bc1ea1 go/analysis: add frame pointer check for vet
Our calling convention requires BP to be preserved (it is
callee-save).  But that only happened with the introduction of
framepointers in 1.5. Furthermore, nothing checks it, so there is
assembly from before and since which violates the calling
convention. The frame pointer is not used by Go, but only by kernel
traceback code (for sampled profiling), so no one noticed.  Also, the
frame pointer tends to "fix itself", since after it is clobbered by an
assembly function f, the calling function fixes the frame pointer up
when that function returns.

I've fixed the stdlib, CLs 248260, 248261, 248262.

This CL is a simple check, intended to be used in vet, to catch
assembly that violates the calling convention by overwriting the
frame pointer without saving/restoring it. It is not intended to
catch all violations, just ones that are easy to find.

We look for a write to the frame pointer before any use of the frame
pointer or any control flow instruction. In such a situation, there's
no way the code could restore the value of BP before returning. This
analysis is very conservative; it gives up in lots of cases. False
positive should be very rare, though.

Possible false positives:

 // looks like a write to BP, but isn't.
CMPQ  BP, BP

// BP actually isn't clobbered, just swapped with AX.
XORQ  AX, BP
XORQ  BP, AX
XORQ  AX, BP

The first is unlikely, as it is using the contents of an incoming
register, which is junk. The second is a general problem of op=
assembly operations that are indistiguishable in syntax from =
operations.  But anything other than the swap above also depends on
the incoming junk value in BP. The swap itself is pointless (XCHQ
works better).

Change-Id: Ie9d91ab3396409486f7022380ad46ac76c3fbed4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248686
Trust: Keith Randall <khr@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Keith Randall <khr@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-11-02 19:21:40 +00:00
Rebecca Stambler b53d4cbd60 internal/lsp/cache: check for symlinks when checking "isSubdirectory"
This change copies the logic from the go command's inDir function
(https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/search/search.go;drc=3931cc113f3f3e7d484842d6e4f53b7a78311e8e;l=570)
to replace gopls's "isSubdirectory" function. This function resolves
symlinks, which isSubdirectory did not previously do.

The only adjustments are to flip the arguments to match the previous
signature of isSubdirectory and to return a boolean instead of a string.

Fixes golang/go#38558

Change-Id: I9c64604222ac277eae81a4111eef432ead887e9f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266200
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-02 04:30:06 +00:00
Rebecca Stambler 8860a70d10 internal/lsp/cache: set a 15 minute deadline on calls to packages.Load
We've recently noticed multiple instances of `go list` hanging
indefinitely during an initial workspace load. Heschi suggested setting
a 5 minute deadline on the IWL, but it seems reasonable to set this
deadline on all calls to packages.Load since that calls `go list`.

I also started with a 15 minute deadline to be a little more careful.
Do you think this is risky enough to merit an experimental setting?

Fixes golang/go#42132

Change-Id: I0a38741f3d99b6a38c46c3e663daf61f2cb45581
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266478
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-02 02:19:07 +00:00
Rebecca Stambler 51cde5226e internal/lsp: move initialization entirely into the snapshot
The majority of the initialization logic is already based on the
snapshot, not the view, so it makes sense to move it there. The
initialization status of the snapshot is copied and invalidated in
clone.

Fixes golang/go#41764

Change-Id: I93234b394318964e7af4696e5ebd465088a05728
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266700
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-02 01:26:20 +00:00
Rebecca Stambler 1f28ee6820 internal/lsp: change `go mod vendor` warning into a diagnostic
This CL uses the approach of a source.ErrorList for the `go mod vendor`
error--rather than a ShowMessageRequest. The suggested fix is a command
that runs `go mod vendor`, so I added a CommandFix to the source.Error
type.

I'm not sure if a diagnostic is better than a ShowMessageRequest--
perhaps it should be both?

Fixes golang/go#41819
Fixes golang/go#42152

Change-Id: I4ba2d7af0233f13583395e871166caed83454d6e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/261737
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-02 00:57:53 +00:00
Dmitri Shuralyov 582c62ec74 go/analysis/singlechecker: fix whitespace in package documentation
Consistent whitespace makes godoc render the snippet without
extraneous leading indentation.

Change-Id: If7b6910cd431ada0db0f59b7aecc9e5bd011af23
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266877
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dominik Honnef <dominik@honnef.co>
2020-10-31 02:16:30 +00:00
Rob Findley 4fc0492b8e internal/lsp/cache: keep a cached workspace module dir
Keep a workspace module dir around for running the go command against a
snapshot, bound to the contents of the workspace modfile.

This uses the cache's resource model to share the workspace module dir
across snapshots if it is not invalidated, and to delete it when it is
no longer in-use by a snapshot. Of course, the go command will still
only see files on the filesystem, but using this immutable model was
most consistent with the immutable workspace.

For golang/go#41836

Change-Id: Iaec544283b2f545071e5cab1d0ff2a66e6d24dff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263938
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>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-10-30 20:42:49 +00:00
Rob Findley 3734b81991 internal/lsp: delay longer in TestDebouncer
Amazingly the builders are occasionally so slow that they can't send the
next event within 100ms. Debounce longer to give them a bit more time.

Change-Id: Ib06bef77099c569060dd32c5b964bf394103485a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266698
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>
Trust: Robert Findley <rfindley@google.com>
2020-10-30 20:03:00 +00:00
Rob Findley d36b6f6806 internal/memoize: add a final argument to Bind for cleaning up
With its memoization and refcounting, the cache is well suited to the
sharing of other expensive resources, specifically those that interact
with the file system. However, it provides no means to clean up those
resources when they are no longer needed.

Add an additional argument to Bind to clean up any values produced by
the bound function when they are no longer referenced.

For golang/go#41836

Change-Id: Icb2b12949de06f2ec7daf868f12a9c699540fa5b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263937
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-10-30 19:59:21 +00:00
Rob Findley f239dba448 internal/lsp/cache: consider gopls.mod when finding workspace root
gopls.mod files should take precedence over go.mod files when finding a
workspace root. To allow this, implement our own algorithm for expanding
the workspace, rather than using the go command.

For golang/go#41837

Change-Id: I943c08bdbdbdd164f108e44bae95d2c659a6e21e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263897
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-30 19:58:41 +00:00
Rob Findley d463eb0e41 internal/lsp/cache: introduce a workspace abstraction
When incorporating the gopls.mod file, the invalidation logic for
workspace module information becomes quite complicated. For example:
 + if a modfile changes we should only invalidate if it is in the set of
   active modules
 + the set of active modules can be provided by either the filesystem or
   gopls.mod
 + if gopls.mod changes, we may gain or lose active modules in the
   workspace
 + if gopls.mod is *deleted*, we may need to walk the filesystem to
   actually find all active modules

Doing this with only concrete changes to the snapshot proved
prohibitively complex (at least for me), so a new workspace type is
introduced to manage the module state. This new abstraction is
responsible for tracking the set of active modules, the workspace
modfile, and the set of workspace directories. Its invalidation logic is
factored out of snapshot.clone, so that it can be tested and to
alleviate some of the growing complexity of snapshot.clone.

The workspace type is idempotent, allowing it to be shared across
snapshots without needing to use the cache. There is little benefit to
the cache in this case, since workspace module computation should be
infrequent, and the type itself consumes little memory.

This is made possible because the workspace type itself depends only on
file state, and therefore may be invalidated independently of the
snapshot. The new source.FileState interface is used in testing, and so
that the workspace module may be computed based on both the session file
state as well as the snapshot file state.

As a result of this change, the following improvements in functionality
are possible:
 + in the presence of a gopls.mod file, we avoid walking the filesystem
   to detect modules. This could be helpful for working in large
   monorepos or in GOPATH, when discovering all modules would be
   expensive.
 + The set of active modules should always be consistent with the
   gopls.mod file, likely fixing some bugs (for example, computing
   diagnostics for modfiles that shouldn't be loaded)

For golang/go#41837

Change-Id: I2da888c097748b659ee892ca2d6b3fbe29c1942e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/261237
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-10-30 19:58:30 +00:00
Rebecca Stambler 443cd81abb Revert "internal/lsp: move initialization entirely into the snapshot"
This reverts commit deb1282f04.

Reason for revert: Merge conflicts for Rob's CL stack

Change-Id: I166b3bd60ec2b727a79a090049f0764864656d47
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266699
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-10-30 19:36:23 +00:00
Rebecca Stambler deb1282f04 internal/lsp: move initialization entirely into the snapshot
The majority of the initialization logic is already based on the
snapshot, not the view, so it makes sense to move it there. The
initialization status of the snapshot is copied and invalidated in
clone.

Fixes golang/go#41764

Change-Id: Icebcf8f4dc750ae4d31e19aa93f9a4c0a57beb4b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266343
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-10-30 19:34:16 +00:00
Rebecca Stambler 8da1a626af internal/lsp/source/completion: remove "completion_" prefix from files
It felt a little redundant to have completion duplicated in the file
names. Happy to revert if you prefer it the original way.

Change-Id: Ibf14a739688d48ecce0b86154b3cbe4807b2f8b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266477
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-30 17:45:15 +00:00
Rob Findley 589136c8af cmd/fiximports,cmd/present,cmd/stringer: update links to pkg.go.dev
These commands link to self-documentation hosted on godoc.org. Given
that this traffic will eventually be redirected to pkg.go.dev
(https://blog.golang.org/pkg.go.dev-2020), we should proactively update
them to pkg.go.dev.

For golang/go#42251

Change-Id: Iff1e4c6958d4e1ddff98150fae6b811e7764816a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/264999
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-10-30 16:06:39 +00:00
Paul Jolly cf7a54d066 internal/lsp/source: use bestMatch for fully qualified symbol style
Currently, fully qualified symbol style does a simple match against a
fully qualified symbol. However, this doesn't really match the user's
intent. Much like the dynamic style, the match should be done "from the
right" (per the logic of bestMatch) with the results being fully
qualified for presentational reasons.

We therefore reuse the logic from the dynamic symbol style, but instead
return a matched symbol as the fully qualified value.

Change-Id: I5c8c6b647c0710c5054bc8e27dbb29cb0fac14d8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266557
Run-TryBot: Paul Jolly <paul@myitcv.org.uk>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Paul Jolly <paul@myitcv.org.uk>
2020-10-30 14:32:52 +00:00
Rebecca Stambler 63f8a171a6 internal/lsp: use the correct method name to register semantic tokens
Leave the legacy names to handle old versions of the VS Code language
client.

Updates golang/go#42148

Change-Id: Ia3eeef9e792e502c5c8018698b9c0ea3a9b0dfe5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266479
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-30 14:18:16 +00:00
Peter Weinbergr 2feb2bb1ff internal/lsp: elide details for non-package files
When gc_details is invoked on a file, it can add diagnostics for files
not in that file's package. Some of these will not go away when
gc_details is toggled off. The fix is not emitting compiler details
diagnostics about files not in the package.

Fixes: https://github.com/golang/go/issues/42198
Fixes golang/go#42198
Change-Id: Ib69cdd8b7be96d73ee417711f7241f56fb529836
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266342
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-10-30 01:04:31 +00:00
Rebecca Stambler 186a7436c9 internal/lsp/source: respect user's hover kind in signature help
I had originally wanted to create a shared code path for hover in all
cases, but hover has a lot more differences from the documentation in
signature help and completion than I expected. You can't use markdown,
and you probably don't want links--it would take a bigger refactor to
extract something that worked for each feature.

Handling the Structured and SingleLine hover setting also doesn't seem
necessary--those settings are really specific to the way the client
presents the hover, which isn't related to signature help or completion.

For completion, all we need is an extra check on the hover kind for the
NoDocumentation option.

Fixes golang/go#38577

Change-Id: Ib2037906c13f5be26813fcd2c20989e4d1b6c9bd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266139
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
2020-10-29 22:52:41 +00:00
Heschi Kreinick 061905c3e8 internal/lsp/cache: stop unnecessarily waiting for IWL
These were added in https://golang.org/cl/237419 and I don't think they
actually fixed anything. I'd like to remove them and see if anything
goes south.

Change-Id: I2f3a48d0e8e40b7a79b963a9319d426cbc6f5d9a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266341
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-29 19:59:06 +00:00
Rebecca Stambler c86e6230b4 internal/lsp/source: add missing vet analyzers
Fixes golang/go#42263

Change-Id: I1493f39c3347d912d4d88a90cfe12bb30929360a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266058
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-29 19:53:23 +00:00
Heschi Kreinick e7a17c4c13 internal/lsp/cache: preserve OS environment
In https://golang.org/cl/265237 I accidentally lost the os.Environ()
call, so we weren't using the OS environment as the defaults any more.

Change-Id: Id36e3c04f3c13d512b0b71b8d73ed086d9ee9f1d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266337
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-29 18:29:19 +00:00
Cherry Zhang 690a3c245f go/analysis/passes/asmdecl: permit return jump without writing to results
RET f(SB) is a tail call. It is okay to not write the results,
as it has not returned to the caller at this point.

Change-Id: I670486d02285c3a346cbc93e91be3b9e61ab77bd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/264319
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Austin Clements <austin@google.com>
2020-10-29 13:53:53 +00:00
Heschi Kreinick 2c115999a7 internal/lsp: use the go command to fix go.mod files
Modifying go.mod files directly leaves go.sum unchanged, and therefore
in need of updates later. Leaving work for the users to clean up isn't
ideal, so it'd be better to use the go command to make modifications.

Unfortunately, the go command has something of a mind of its own. The
most obvious problem is that using go get to add a new require adds a
// indirect comment to that new require, and there's no way to prevent
it. The only thing we can do is add the require first, then use go get
to do nothing but update the go.sum file.

The other inherent problem is that the go command operates on files as
they exist on disk, not the in-memory versions. As discussed, we issue
an error for this case. The alternative would be to work on temporary
files based on the in-memory contents, but that would be much larger
change, so I'd rather not at least right now.

To support Commands for quick fixes, add a new Command field to
source.SuggestedFix, and use it when forming the CodeAction response.

Fixes golang/go#38209.

Change-Id: I0c13ea39199368623e7494e222ba38587323d417
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265981
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-28 22:47:54 +00:00
Heschi Kreinick 49729134c3 internal/lsp: unify go command invocation logic
We have two parallel code paths for Load and other go command
invocations. Unify them by introducing a mode argument to the various
functions that run the go command, indicating the purpose of the
invocation. That purpose can be used to infer what features should be
enabled.

In the future, I hope we can use the mode to decide whether mod
file updates and network access should be allowed.

Change-Id: I49c67fcefc9141287b78c56e9812ee6a8ac8378a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265238
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-28 22:19:10 +00:00
Rob Findley 832c4b4433 internal/lsp/source: tweak the WorkspaceSymbols docstring
The workspace symbols docstring was indenting quoted text using '>', but
this is incompatible with convention of simply using indentation to
cause pre-formatted text.

Change-Id: Ifbaf88e19ac09a29b83f1812c576de6ea96a0793
Reviewed-on: https://go-review.googlesource.com/c/tools/+/264636
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-10-28 22:16:44 +00:00
Heschi Kreinick 2b84a066b2 internal/lsp: use gocommand.Invocation more
We pass around verb/args/wd in many places. Bundle them up as an
Invocation instead. goCommandInvocation now updates and returns an input
Invocation.

packages.Config is conceptually an extra layer of parsing and
type-checking on top of a go list invocation. It doesn't make sense for
us to construct the latter using the former. A later CL will construct
the Config in terms of the Invocation; for now duplicate a bit of logic.

Use the environment in the cache key for various module operations
rather than the Config hash. I'm not sure either is fully correct but I
think the environment captures everything that's likely to matter. This
way we don't need Configs in those functions at all.

Change-Id: Iebee2705e63638ab365b3ee18b23f8c3e8ca30ce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265237
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-28 21:55:01 +00:00
Rob Findley 5bbba6644e internal/lsp/source: synchronous commands the default
This makes all commands with the exception of running tests synchronous.

Remove the special handling for applying suggested fixes. Instead, make
workDone reporting a no-op if the workDone handle is nil.

Change-Id: I6801c91f8564d68b8bdaaf9456cd6752b164d0b9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265583
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-28 18:20:00 +00:00
Peter Weinbergr dc70f74c71 internal/lsp: correct typo
Misspelled 'gcOptimizationDetails'. (auto-completion helped.)

Change-Id: I496de8f1749768e5bc0037821fe1672ba605d605
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265779
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2020-10-28 17:12:10 +00:00
Rob Findley 0dcbe3655a gopls/doc: update links from godoc.org to pkg.go.dev
Change-Id: If81e8d9b3a08f6d9cceff9bf3d9cac6aa9247a94
Reviewed-on: https://go-review.googlesource.com/c/tools/+/264998
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-10-28 14:18:08 +00:00
Peter Weinbergr eafbe7b904 internal/lsp/protocol/typescript: code for latest 3.16 LSP
Typescript code to generate internal/lsp/protocol/ts*.go for
the latest 3.16 version of the language server protocol.

Change-Id: Ie5bb0f44ffb83c69e30578a36d057820e55fee76
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265579
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-10-28 11:10:35 +00:00
Rebecca Stambler 8cd080b735 internal/lsp: handle nil pointer exceptions in check for Go files
Fixes golang/go#42240

Change-Id: I48382613c9eb9d021a9e1dc9ca6ab6b4b1dfcf8f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265763
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-28 02:59:01 +00:00
Rob Findley 0b86805daf internal/lsp: finish work when synchronous commands complete
Synchronous commands were bypassing the logic to handle the command
error an publish a final workDoneProgressEnd message. Push this logic
down into Server.runCommand.

Also, switch 'generate' to be synchronous, since this makes sense and
causes the synchronous path to be exercised in tests.

Finally, stop defaulting the command title to Command.Name. All Commands
should have Titles.

Change-Id: Id0b1e5283e54d82c307e933782317372bd8971af
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265737
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>
Trust: Robert Findley <rfindley@google.com>
2020-10-27 23:31:11 +00:00
Ian Lance Taylor 6312208388 go/internal/gccgoimporter: support notinheap annotation
Port https://golang.org/cl/265702 from the main Go repo.

Original CL description:
    The gofrontend has started emitting a notinheap annotation for types
    marked go:notinheap.

For golang/go#41761

Change-Id: Ic14ffda4b0c3eef850ad85dbf9af755283a5196b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265718
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-27 21:30:30 +00:00
Peter Weinbergr 8dabb74018 internal/lsp: update lsp protocol stubs to match LSP 3.16 revisions
Upgrades to bring gopls up to date with the latest LSP protocol
specifications. There are two new RPCs, Moniker, and ResolveCodeAction,
and a new field CodeDescription in Diagnostic.

This CL also includes the tiny change to helper.go to cope with
_s in function declarations.

Change-Id: I1a0dcb57adc48510f2a0ed97cf18aa4719648822
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265117
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Peter Weinberger <pjw@google.com>
2020-10-27 18:00:23 +00:00
Heschi Kreinick e84cfc6dd5 all: clear GOMODCACHE in tests
Various test setups set GOPATH expecting that it will affect GOMODCACHE.
If GOMODCACHE is explicitly set in the test's environment, that doesn't
happen. Clear the value out as needed.

Change-Id: I3520d672ace5c1e13783fd078828212bef7d1c01
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265177
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: Bryan C. Mills <bcmills@google.com>
2020-10-26 22:31:36 +00:00
Rebecca Stambler c8cfbd0f21 internal/lsp/source: handle nil pointer in rename_check.go
Fixes golang/go#42170

Change-Id: Id5b9f5767e952b63482372e5275aa162bc9ab14a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/264619
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-23 17:41:41 +00:00
Rebecca Stambler 2f4fa188d9 go/packages: use native overlay support for 1.16
This change modifies go/packages to use the go command's -overlay flag
if used with Go 1.16. It does so by adding a new Overlay field to the
gocommand.Invocation struct. go/packages writes out the overlay files
as expected by go list before invoking a `go list` command.

Fixes golang/go#41598

Change-Id: Iec5edf19ce2936d5a633d076905622c2cf779bcc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263984
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-23 15:00:57 +00:00
Josh Bleecher Snyder ffe8bce740 cmd/stress: print elapsed time, percentage failure
Add more information to the output of stress.


Prior to this change, stress printed lines like:

8288 runs so far, 2 failures


After this change, stress prints lines like:

1m5s: 8288 runs so far, 2 failures (0.02%)


I've found the timing information to be helpful in that it helps
me anticipate how long a new stress run might take to reach some
number of iterations I've deemed necessary to convince myself
that a bug has been fixed.

I've found the % failure to be helpful when there are multiple failures;
I can use them to gauge whether I've made the test more reliable.

I've been using this patch for a while and found it helpful
on numerous occasions, so I figured I should upstream it.

Change-Id: If0c9b74c30353898bacb38a81f27796f74eb4064
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258299
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-10-22 21:58:48 +00:00