Commit Graph

5955 Commits

Author SHA1 Message Date
Cuong Manh Le 412ee174ef all: add SliceToArrayPointer instruction
CL 332049 added support for slice to array pointer, which introduced in
go1.17, by using Convert instruction. However, the conversion can fail
dynamically, while all current conversion instructions can not. That
leads to inconsistent with other parts of SSA IR.

@timothy-king suggested to add new instruction for this conversion, this
CL implements that.

Fixes golang/go#46987

Change-Id: I1a00d51e257d2b3eabc2c37e3a09b78754193a78
Reviewed-on: https://go-review.googlesource.com/c/tools/+/333749
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
2021-07-21 23:55:41 +00:00
Rob Findley 7f68387a4a internal/lsp/source: workspace symbol improvements for selectors
This CL adds various improvements for matching nested fields and
methods:
- Limit the symbols we produce to not show unqualified fields/methods,
  and not show partial package paths.
- Handle embedded selectors, by trimming the package path.
- Improve the internal API used by symbolizers to operate on named
  chunks.

Fixes golang/go#46997

Change-Id: I86cbe998adbb8e52549c937e330896134c375ed7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/334531
Trust: Robert Findley <rfindley@google.com>
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>
2021-07-21 20:52:30 +00:00
Rebecca Stambler 7aa8294462 internal/lsp: handle panic in fix AST
I'm not sure how this can happen, but it seems possible that a bad
expression might somehow have an invalid position.

Fixes golang/go#47231

Change-Id: I0794bdfb66f668fc375e9fe561c9f239c8b92492
Reviewed-on: https://go-review.googlesource.com/c/tools/+/334892
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>
2021-07-21 16:31:48 +00:00
Francesco Renzi 6e9046bfcd gopls/doc: fix imports function for Neovim LSP
The documented Lua function for supporting imports with Neovim native
LSP support does work for imports, but also runs any other code action
available in the current range. For example, if the function was to run
with the user's cursor on an empty struct being initialized, the code
action for filling that struct would also run.
This change restricts the desired actions to only be organizeImports.

Fixes golang/go#47181

Change-Id: Ie4eb5961cb4405091477b79175acc7052ff16d4c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/334749
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Robert Findley <rfindley@google.com>
2021-07-15 13:35:41 +00:00
pjw 0cf4e2708a internal/lsp/semantic: improve semantic token processing
There is insufficient type information to compute semantic tokens in
packages that don't compile. Particularly affected are test files
and files being actively edited in new packages.
Further, existing code could
panic on poorly formed imports; this has been fixed.
Computing semantic tokens for identifiers
having neither use or definition information has been improved.
(Each of the many cases in the new function unkIdent() occurs
in existing code or test files.)

Change-Id: Id1b5db0622b17076de1ed23a950a20cd03c3750a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/333869
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: 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>
2021-07-14 22:42:09 +00:00
Rob Findley 5061c412c3 internal/lsp: signal diagnostic completion if modification failed
If didModifyFiles fails we were never closing the diagnoseDone channel.
This was potentially leaking goroutines in the regtests.

Noticed in
https://storage.googleapis.com/go-build-log/ab4085ce/freebsd-amd64-12_2_149b05c3.log

Change-Id: I906b643d415c915d7be1951e5d8d21bf9016acee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/334250
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>
2021-07-13 20:49:08 +00:00
David Chase ef97713d99 gopls/doc: add vetted examples for Sublime Text
Instructions for Sublime Text + LSP + golsp,
including examples for:
  minimal configuration
  adjusting path
  per-project settings

The per-project settings include breadcrumbs helpful
to someone working on Go itself.

Change-Id: I2fe41cd60d7327578bd5bd9999f2459e79e9be4c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/325189
Trust: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-07-13 20:15:39 +00:00
Rob Findley 8e85a283cd internal/lsp: adopt bcmills' suggestion for an improved debouncer API
The debounce API becomes both more testable and more elegant when using
channels rather than callbacks to signal events, as suggested by bcmills
in CL 333349. Adopt these suggestions.

Fixes golang/go#45085

Change-Id: Ic1843f582d514af8aa109c24f5e3311536e54a60
Reviewed-on: https://go-review.googlesource.com/c/tools/+/334252
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: Bryan C. Mills <bcmills@google.com>
2021-07-13 16:40:23 +00:00
Suzy Mueller ae0deb7a4c internal/lsp: fix variable reuse bug in code actions
Taking the address of the variables defined by range in a for loop is not
safe since they are reused. Get the address from the original slice.

Change-Id: If7fbf3fdbfeeaf329f36e416642582002895bbce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/330649
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-07-13 14:00:16 +00:00
Rob Findley d36a54b56b internal/lsp: improve package search in a couple places
When we open a file in a package, independent of whether it is in the
workspace, we type check in ParseFull mode. However, several other
code paths don't find this better parse mode.

We need a better abstraction, but for now improve a couple code paths
specifically for the purpose of fixing Hover content.

Updates golang/go#46158
Updates golang/go#46902

Change-Id: I34c0432fdba406d569ea963ab4366336068767a2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/333689
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>
2021-07-13 13:36:40 +00:00
Rob Findley 384460091c gopls/internal/regtest: add a flag to profile didChange handling
Using the -cpuprofile testing flag for profiling didChange handling
causes the profile to capture the IWL. Add a new -didchange_cpuprof
flag that instruments just the change handling.

Also fix a check for empty workspace files that was preventing
This inaccurate check was preventing the didChange benchmark from
working.

Change-Id: Ie9f5402960ddccda5d6b9b36ae3c111aa5b51bb8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/333939
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>
2021-07-13 12:52:46 +00:00
GGCristo de44776175 gopls/doc: Neovim v0.5 is now stable
Change-Id: Ia3078f9d321d17681b92fd9b00f6dd1cb3eff6d0
GitHub-Last-Rev: 5c2023007a2e6a6471ec75871f74dc3edfe91af9
GitHub-Pull-Request: golang/tools#329
Reviewed-on: https://go-review.googlesource.com/c/tools/+/332849
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2021-07-12 22:00:43 +00:00
Shoshin Nikita ccff7327b9 internal/lsp/source: fix comment update during rename for short variable declarations
*ast.AssignStmt doesn't have an associated comment group. So, we should
try to find and return a comment just before the identifier.

Fixes golang/go#42134

Change-Id: Ie40717a4973ccfdbd99c3df891c2cfffbb21742d
GitHub-Last-Rev: da75fde2dbf3613f3325dbc5930dfc84ea813b90
GitHub-Pull-Request: golang/tools#323
Reviewed-on: https://go-review.googlesource.com/c/tools/+/327229
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
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>
2021-07-12 21:21:15 +00:00
Rob Findley a7dfe3d2b7 internal/lsp: attempt to make TestDebouncer more robust
CL 309276 added logic to retry TestDebouncer if its execution was
determined to be invalid.

Unfortunately it also reduced the delay period, which increases the
likelihood of a flake on any individual execution. This appears to have
more than offset any robustness resulting from the retries.

This CL does a few things to try to improve the test:
 - Remove t.Parallel: we want goroutines to be scheduled quickly.
 - Increase the debouncing delay.
 - Improve the logic for determining if a test was invalid.
 - Guard the valid variable with a mutex, since this was actually racy.

For golang/go#45085

Change-Id: Ib96c9a215d58606d3341f90774706945fcf9b06c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/333349
Trust: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-07-12 16:18:15 +00:00
Rob Findley 980829d8a1 internal/lsp/lsprpc: add an AutoDialer abstraction
Refactor the lsprpc package to move the logic for 'automatic' server
discovery into an AutoDialer abstraction, which both implements the v2
jsonrpc2 Dialer interface, and provides a dialNet method that can be
used for the existing v1 APIs.

Along the way, simplify the evaluation of remote arguments to eliminate
the overly abstract RemoteOption.

Change-Id: Ic3def17ccc237007a7eb2cc41a12cf058fca9be3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/332490
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: Ian Cottrell <iancottrell@google.com>
2021-07-12 16:16:36 +00:00
Peter Weinberger cb1acef8be Revert "internal/lsp/semantic.go: repress useless messages and tighten logic"
This reverts commit 5b540d349b.

Reason for revert: left in logging statements

Change-Id: I9ef5cd79e9ae8c94098fceca3a356fa3377c16e7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/333711
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
2021-07-10 00:41:40 +00:00
pjw 5b540d349b internal/lsp/semantic.go: repress useless messages and tighten logic
Error messages associated with bad parses and when working at the end
of the file are not useful to users, so they are no longer generated.
The logic around recognizing function calls has been improved, and
a panic sometimes caused by bad imports has been fixed.

The logic is imprecise/incorrect in some cases; there will be
another CL.

Change-Id: I72be3a0a003569fe06d458989e3dbbb46b7a22c0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/332909
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: Robert Findley <rfindley@google.com>
2021-07-10 00:32:22 +00:00
Bryan C. Mills e33c0f2934 go/packages: skip tests that link binaries in short mode
These tests together account for about 1s of running time on my
workstation. I expect that they are even slower on platforms that
require external linking, and likely more memory-intensive than most
of the other tests.

For golang/go#46764

Change-Id: Ic9607ac71bcfd617581c58cfffe3775e23cd3422
Reviewed-on: https://go-review.googlesource.com/c/tools/+/332351
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-07-09 19:50:55 +00:00
Rob Findley 8e32e9f144 internal/lsp/regtest: fix a panic TestResolveImportCycle
CL 333289 introduced a panic, which was subsequently suppressed in test
error output due to the deferred t.Fatal (an interesting gotcha that I
honestly wasn't aware of).

Fix both the panic, and the suppression of regtest panics.

Also fix the regtest editor shutdown to run on a detached context, so
that shutdown doesn't fail for tests that have timed out.

For golang/go#46773

Change-Id: I080a713ae4cd4651476d8b4aab1d2291754a4f5a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/333510
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>
2021-07-09 17:21:04 +00:00
Rob Findley 2583041a9d go/packages: fix data race in TestCgoNoSyntax
CL 332350 introduced a race to exported.Config.Mode when it parallelized
this test. Revert the call to t.Parallel.

Change-Id: Ifd4b6c4037ee30e8b3f55dc69d4f9f3f09a89185
Reviewed-on: https://go-review.googlesource.com/c/tools/+/333509
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-07-09 15:03:35 +00:00
Satoru Kitaguchi 69948257bd go/ssa: incorrect document in type Builtin struct
There is no Func field in CallCommon. s/CallCommon.Func/CallCommon.Value/ in the documentation for Builtin.

Fixes #46972

Change-Id: I501e9439bc0b1cb4f1dac0582f27e74de67e61b9
GitHub-Last-Rev: 6f07a2c80253c628b31970a2b1774644d93b3920
GitHub-Pull-Request: golang/tools#327
Reviewed-on: https://go-review.googlesource.com/c/tools/+/331310
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tim King <taking@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Tim King <taking@google.com>
2021-07-08 23:16:08 +00:00
Bryan C. Mills e688b94517 go/packages: parallelize most tests
This reduces the overall running time on my workstation from ~44s to ~17s.

For golang/go#46764

Change-Id: I94e3c5bf160599687f7aa16513bb7b7e977f14b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/332350
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-07-08 21:10:20 +00:00
Rob Findley 64bd808b73 internal/lsp/cache: don't report a context error if load succeeded
If a context was canceled during load, only report it as a critical
error if the load actually failed.

Along the way, simplify evaulation of the critical error to use a switch
statement.

Also await IWL in the second Env used in shared regtests. Presumably it
is this Env that is being shutdown prior to IWL, triggering the
panicking code-path from golang/go#47030. I wasn't able to reproduce,
but all panics are occurring in regtest/misc, and this seems highly
plausible.

Fixes golang/go#47030

Change-Id: I4df65697f644cff275ab1babb783868fd9e10c2d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/332589
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>
2021-07-08 21:02:30 +00:00
Bryan C. Mills cae92d5d68 go/packages: skip GOPATH tests in short mode
This cuts the running time for 'go test -short ./go/packages' by about
50% by skipping the tests that run in GOPATH mode.

All of the tests are still run when the -short flag is not set, so the
longtest builders should still report any GOPATH-mode regressions, and
the faster short tests should improve turnaround times (and resource
usage and associated test flakiness) on the non-longtest builders.

	~/x/tools/go/packages$ go test -short
	PASS
	ok      golang.org/x/tools/go/packages  25.379s

	~/x/tools/go/packages$ go test
	PASS
	ok      golang.org/x/tools/go/packages  42.812s

For golang/go#46764

Change-Id: Iff9a94b6a2657174cd5c60aeb732ca4f132a7897
Reviewed-on: https://go-review.googlesource.com/c/tools/+/331052
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-07-08 21:00:45 +00:00
Rob Findley 2f04284e71 internal/lsp/regtest: allow for unsent diagnostics in TestResolveImportCycle
Gopls doesn't send empty diagnostics for open files in some cases
(likely a race to context cancellation). This is probably a bug itself,
but for now don't let this cause TestResolveImportCycle to fail.

Added a TODO to investigate further.

Fixes golang/go#46773

Change-Id: I197d9b09885951b47b3f90a0480ae75679d2a1a0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/333289
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>
2021-07-08 19:58:58 +00:00
Rob Findley 41a65bdc11 internal/lsp: avoid flake in TestDebouncer
TestDebouncer inherently depends on the timing of events. Specifically,
it can fail if the pause between two subsequent events is more than the
debouncing delay.

When this has proved flaky in the past I just increased the debouncing
delay. However, tests are still occasionally flaking. Rather than just
increase the delay arbitrarily, attempt to make the test more robust by
retrying up to three times if the base assumption (that goroutines are
scheduled within a reasonable amount of time) is not met.

Fixes golang/go#45085

Change-Id: Ifa32e695d64ae4bcfe9600a0413bf6358dff9b7a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/309276
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>
2021-07-08 19:58:23 +00:00
Rob Findley 1c9019e64a internal/lsp/cache: fix raciness of updating the view workspace
The view workspace was written concurrently, meaning that changes to a
go.mod or go.sum could race to updating the view workspace, leaving it
in an incorrect state.

Move control over writing this workspace onto the view, and hold the
snapshotMu while writing.

Change-Id: I47f58769cc77860e9c9674c8f6bf5fd0793e7937
Reviewed-on: https://go-review.googlesource.com/c/tools/+/309289
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: Heschi Kreinick <heschi@google.com>
2021-07-08 19:57:21 +00:00
Rob Findley febfa9d67f internal/lsp/source: move diagnosticsDelay out of experimental
This option has been enabled by default for a while now: remove it from
'experimental' to 'advanced'.

Change-Id: Id8116bf7b8976204a61fe1bbf9dc0b8bd69c68d1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/309271
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>
2021-07-08 19:56:33 +00:00
Rob Findley 71eae3a1b4 internal/lsp/cache: be consistent about using snapshot.FileSet
Ideally we could at some point break the snapshot->view->session->cache
reverse traversal, but for now at least don't copy this pattern around
everywhere.

Change-Id: Ib144e6d322016f5b9563f21c56a0691c1a8ec97d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/309270
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>
2021-07-08 19:56:07 +00:00
Rob Findley 251f283686 internal/lsp: add a setting to batch didChangeWatchedFile notifications
Gopls's serial processing of didChangeWatchedFile notifications has
historically been a pain point for clients that don't batch file events,
when branch switching or running go generate.

It's "not that tricky" for us to debounce and batch up watched file
notifications on our end, so this CL introduces this functionality as a
new experimental setting. Truth be told it ended up being harder than
expected, due to (1) our requirement for regtests to be able to
determine when diagnostics have completed, and (2) our reliance on
jsonrpc2 for sequencing changes to the server.

To address (1), I factored out the actual processing of change
notifications into a separate method (thus increasing our surprisingly
long chain of method calls). To address (2), I guarded the processing of
file changes with a mutex.

I also guarded some places where views and snapshots were accessed in
potentially racy ways. Our interaction with session.views was rather
complicated, so I had to switch session.viewsMu to a RWMutex.

Add this to the experimental regtest mode, and more generally enable all
experimental features in this mode, rather than just the experimental
workspace module.

Fixes golang/go#41691

Change-Id: Ifccdbdf86263dbe2e37ffe9f7bbf2a2cd74218b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/309269
Trust: Robert Findley <rfindley@google.com>
Trust: 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: Heschi Kreinick <heschi@google.com>
2021-07-08 19:55:54 +00:00
Rob Findley c979f9254a internal/lsp/cache: invalidate packages in setMetadata
When setting metadata, we must invalidate any packages that have been
computed with old metadata.

Also make setMetadata atomic, by locking around it in Load. This is just
writing memory after a Load, so should be fast and infrequent. It is
critical that our various maps related to metadata are coherent, so it
makes sense to err on the side of coarser locking, IMO.

Fix a race in TestUpgradeCodeLens.

Change-Id: Iee8003b7e52b9f21681bdba08a009824f4ac6268
Reviewed-on: https://go-review.googlesource.com/c/tools/+/331809
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>
2021-07-08 19:53:41 +00:00
pjw 55cd4804df gopls/doc: Document how gopls generates semantic tokens.
The new file gopls/doc/semantictokens.md describes how gopls presently
decides which semantic tokens and modifiers to send to clients.

Change-Id: Ifc76e13954dde2ea58b6da446517f94be038a285
Reviewed-on: https://go-review.googlesource.com/c/tools/+/333010
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>
2021-07-08 16:22:39 +00:00
Jean de Klerk 77c1b7a4f7 internal/lsp/cmd: print flags when running gopls help
Currently, flags are not being printed when users run `gopls help` because they
never get parsed in Main. This CL fixes that issue.

Updates golang/go#35855

Change-Id: Ic9882d0d2410a0f045aa0ecaa87b36c23eb569fd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/330854
Trust: Jean de Klerk <deklerk@google.com>
Run-TryBot: Jean de Klerk <deklerk@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-08 16:04:41 +00:00
Cuong Manh Le 640c1dea83 go/ssa: support unsafe.Add and unsafe.Slice
Fixes golang/go#47091

Change-Id: Id59375a3083520275025f58879c8950b0560e25a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/333110
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-07-08 02:47:23 +00:00
pjw fd00574339 internal/lsp/protocol: upgrade generated lsp code to beginning of July
There are no changes, other than the date and git checksum.

Change-Id: Ic7e93829f5e4cd95b7c2b5023c9c0905a07655ed
Reviewed-on: https://go-review.googlesource.com/c/tools/+/332690
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: Robert Findley <rfindley@google.com>
2021-07-07 20:06:16 +00:00
Rob Findley 7edcfe5231 internal/lsp/lsprpc: add a goenv middleware
Add a middleware to enrich LSP messages with Go environment on the
forwarder.

Change-Id: Ia294b0c2fa1276b09b75542436e5f4179f81f302
Reviewed-on: https://go-review.googlesource.com/c/tools/+/331771
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: Ian Cottrell <iancottrell@google.com>
2021-07-02 16:14:50 +00:00
Rob Findley e3040f2721 internal/lsp/lsprpc: add a CommandInterceptor middleware
This will be used for starting the debug server along the serving path.

Change-Id: I19d13753ad70c179a53f348ed574aaea19c0d301
Reviewed-on: https://go-review.googlesource.com/c/tools/+/331770
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: Ian Cottrell <iancottrell@google.com>
2021-07-02 16:14:40 +00:00
Rob Findley ea370293d7 internal/lsp/lsprpc: use middleware for the V2 handshaking
The number of concerns satisfied by the lsprpc package is proving to be
a barrier to both factoring out the debug and event package, and use of
service discovery.

The new Binder API admits a nice abstraction that can help make the
lsprpc package more modular, or perhaps even unnecessary: a binder
middleware that can instrument all aspects of the connection lifecycle.
In this CL, this pattern is used to decouple the server handshake from
the actual forwarding setup. Later CLs will implement additional
functionality using this pattern.

The TestEnv helper is refactored to be more scriptable.

Change-Id: I6060bc4bba57e4ee7e161a5d6edbc40c6fccbaa8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/331369
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: Ian Cottrell <iancottrell@google.com>
2021-07-02 16:14:25 +00:00
Cuong Manh Le 20dafe5d60 go/ssa: allow conversion from slice to array pointer
Fixes golang/go#46987

Change-Id: Ic3b4410c3ea9f62d3cdce579a1152884167be16b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/332049
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-07-01 08:39:23 +00:00
tkawakita f0847e0ce9 go/callgraph: change reflect.Call to reflect.Value.Call in comment
Change-Id: I672a2dcd5a50c6d6cb5bbe2c0d0c53ff56d24efd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/331709
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
2021-06-30 16:45:04 +00:00
Matthew Dempsky 72e4d1bb8d go/internal/cgo: handle symlinks with $PWD, not -srcdir
In CL 293250, I changed x/tools/go/loader to invoke cgo using the
-srcdir option, rather than chdir'ing into the source directory. But
evidently cgo's -srcdir option does not affect #include processing of
relative file paths, so this ended up breaking packages that relied on
the latter.

This CL reverts back to chdir'ing into the source directory, but also
sets the PWD environment variable. This appears to be how cmd/go
invokes tools and handles symlinks.

Fixes golang/go#46877.

Change-Id: Ia538c5d8722b151a4547f73188f6537e0551136f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/331409
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-06-29 19:12:30 +00:00
Rebecca Stambler 100b229261 internal/lsp/cache: treat load timeouts as critical errors
Lower the timeout for the go command to 10 minutes.
Also, if the first workspace load attempt fails because it times out,
treat the timeout as a critical error, since we explicitly don't cancel
the first workspace load.

Fixes golang/go#46859

Change-Id: Iccd26509177e4c47ca4b2c8ab4111df9be0f934e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/330969
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>
2021-06-29 14:11:33 +00:00
Rob Findley 12f8456a01 internal/testenv: actually Exit if small machine for netbsd-arm*-bsiegert
Change-Id: Ie5c06bf2a0788a7dc278f5de8f56e3865d9bdbe7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/331053
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-25 23:53:21 +00:00
Rob Findley 00129ffdb6 internal/lsp/lsprpc: update binder tests to handle forwarding
Update the new binder tests to run both with a standalone server, and
with a forwarding chain.

Make a few superficial improvements along the way as well.

Change-Id: Icd197698093a3f6149ab58171806b2388ed75b7f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/321134
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: Ian Cottrell <iancottrell@google.com>
2021-06-25 19:21:47 +00:00
Rob Findley fe2294a1b8 internal/jsonrpc2_v2: initialize async before binding
The lsprpc package needs to wait on the newly bound connection to
perform some tear-down, so it must be safe to call conn.Wait from Bind.

Achieve this by switching async from an init pattern to a constructor.
This means moving async fields to pointers, but since they weren't safe
to use prior to initialization anyway this feels correct.

Change-Id: I4f93980915e0b568fbf2db3cd7d062adf06e4b99
Reviewed-on: https://go-review.googlesource.com/c/tools/+/330929
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: Ian Cottrell <iancottrell@google.com>
2021-06-25 19:21:17 +00:00
Rob Findley 636017e131 internal/lsp/cache: fix missing pkg error on Windows
Use filepath.SplitList rather than always splitting GOPATH on ':'.

Fixes golang/go#46805

Change-Id: I27324afba96b550f75cc272b6c7f701b28825d39
Reviewed-on: https://go-review.googlesource.com/c/tools/+/328969
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>
2021-06-25 15:37:24 +00:00
Jean de Klerk 48cad5ecb1 tools/gopls: small fixes to contributing.md
Change-Id: I261e1936b96e70ad8347655a7a8d0eb792348d44
Reviewed-on: https://go-review.googlesource.com/c/tools/+/330853
Trust: Jean de Klerk <deklerk@google.com>
Run-TryBot: Jean de Klerk <deklerk@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-06-25 15:05:05 +00:00
Rebecca Stambler da404b52bc internal/lsp: start parsing go.work file like gopls.mod file
Allow users to experiment with golang/go#45713 by adding experimental
support for the go.work file. We handle it like a special case, very
similar to the current gopls.mod file mechanism. The behavior is
undefined if both a gopls.mod and go.work file exist. Ultimately, we
will deprecate support for the gopls.mod file if the go.work file
proposal is accepted, so I don't think it's important to be careful
about handling both simultaneously.

Change-Id: Id822aeec953fc1d4acca343b742afea899dc70ff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/328334
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>
2021-06-24 04:20:31 +00:00
Rebecca Stambler 4833ac519e internal/mod: add workfile parser
This is a minimal copy of golang.org/x/mod/modfile that adds the parser
in CL 324764. It will be used to add experimental support for go.work
in gopls.

Change-Id: I75a8171eda763506ea8b5ffa0c6d163d59010333
Reviewed-on: https://go-review.googlesource.com/c/tools/+/329069
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>
2021-06-24 04:20:08 +00:00
Rob Findley bfc1674319 internal/lsp/cache: fix loading of std and cmd
The go/packages queries std/... and cmd/... don't work. I believe
they're supposed to be just "std" and "cmd" based on experimentation
(and stdlib_test.go), but I didn't see this explicitly documented.

Fixes golang/go#46901

Change-Id: I3d0ed48fa64a50eefe4b5cc6074a93455cd37dc8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/330529
Trust: Robert Findley <rfindley@google.com>
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>
2021-06-24 03:06:00 +00:00