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

5574 Коммитов

Автор SHA1 Сообщение Дата
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
Peter Weinbergr 13b3b30742 internal/lsp/semantic.go: remove global variable
instead copy the client's token types and modifiers into the options,
and reconstruct the inverse map once per LSP request.

Change-Id: I4ae5b56a31060882a06b1b6bbc65d26e4085e058
Reviewed-on: https://go-review.googlesource.com/c/tools/+/264320
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-22 21:19:33 +00:00
Rebecca Stambler 9cf592e881 all: update all dependencies to latest pseudoversions
Change-Id: If1b583e7d776eae605ba361baa8f1879dba03465
Reviewed-on: https://go-review.googlesource.com/c/tools/+/264207
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-22 03:59:29 +00:00
Rebecca Stambler 23787c0079 internal/lsp: fix race condition in diagnostics show message
Detected on CL 263984. Logs:
https://storage.googleapis.com/go-build-log/62f18d07/linux-amd64-race_c6e9f2a0.log.

Change-Id: I07deb768eea43a277d67fbe72cabed885af41b93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/264202
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>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-21 21:49:18 +00:00
Rebecca Stambler 6652d1fb14 internal/gocommand: add a GoVersion function to avoid duplicating logic
It seems easier to have this as a shared internal function.

Updates golang/go#41598

Change-Id: If35bdbdf5499624dd55ae9daede1ff1ae9495026
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263985
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>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-10-21 20:36:10 +00:00
Rebecca Stambler d105bfabbd internal/lsp: dynamically register semantic tokens
This CL switches from automatically registering the semantic tokens
capability to dynamic registration. This allows us to turn it on and
off as the option is switched--otherwise it defaults on always.

To achieve this, we also have to set session options on
didChangeConfiguration. It turns out that the passed-in "changed"
parameter can be null, which is why we always refetch the workspace
configuration.

Fixes golang/go#41963

Change-Id: I58d742577ce7f3da67db32011ba21bd9813eb203
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263525
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-21 17:10:30 +00:00
Rebecca Stambler 2cbe144a5b internal/lsp: return code lenses in a deterministic order
Fixes golang/go#41961

Change-Id: I65f333caaa8568d90a59594019ac4296b8f56b98
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263527
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-21 17:08:55 +00:00
Rebecca Stambler eb9088fa2e internal/lsp/source: remove workspace module from all experiments
This will enable us to turn on all experiments by default in the
nightly.

Change-Id: I20dff811f8234fd0588e54e1ea90475d171cd9e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263779
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-21 16:55:45 +00:00
Than McIntosh 2be66b663c cmd/toolstash: pass -S=2 when comparing toolchains
For "toolstash -cmp", run builds with "-S=2" as opposed to just "-S".
The additional output from "-S=2" includes aux data (including DWARF
symbols) and ABIs for function symbols, both of which are potentially
important for comparison purposes.

Change-Id: Iba273d82b46e0b08ab4c83ca16fd22c0c0f7e68b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263979
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-10-21 12:24:55 +00:00
Peter Weinbergr c12dc663cb gopls: regtest to demonstrate gopls confused by //line directives
2 examples of //line directives confusing gopls, for hovers and
for diagnostics.

Change-Id: I88838f66ccf23ff191acb68ef81b6019cdfa6135
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262700
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-10-21 12:08:33 +00:00
Rebecca Stambler d49c4edd7d internal/lsp: do not allow non-Go files to be loaded in packages.load
Fixes golang/go#41962

Change-Id: I47ec376213541095386add09e63a5127473a6d27
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263983
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-21 00:02:07 +00:00
Rob Findley 226fd2f889 internal/lsp/fake: factor out working in a temp directory
In subsequent CLs, tests are added that don't need the full machinery of
fake.Workdir (file tracking, etc.). Factor out some of the facility for
writing a txtar-encoded temp directory, and working with relative paths.

Change-Id: Iae25c37a8fd8de2dfe6c91e507d9be01440d3492
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263523
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-10-20 16:11:33 +00:00
Hana 90550980fc internal/lsp/source: use 'gopls.' instead of 'gopls_'
And, export CommandPrefix const so api_json generator can use it.

Update golang/go#41187

Change-Id: Ie976b774d64ba707152b6f659a15aef19ef12dcd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263057
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2020-10-20 14:19:29 +00:00
Peter Weinbergr f5c826d190 internal/lsp: hold notifications until gopls is initialized
Errors in options generate showMessage notifications, but these
were lost if they were sent before the initialization handshake completes.

Change-Id: I011da2387467bb6bf188201a7294e1bb30805cbc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263518
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-20 12:34:48 +00:00
Heschi Kreinick b894a3290f all: use explicit -mod, -modfile fields for gocommand.Invocation
Build flags, -mod, and -modfile are all accepted by disjoint go command
verbs. Mixing them together had the effect of forcing gocommand users to
figure out which went where themselves, which was annoying and
error-prone. Add ModFlag and ModFile fields to Invocation and update all
uses to use them.

go/packages has a BuildFlags field that's bad for the same reason. Add
private modFlag and modFile fields that forward to the corresponding
Invocation fields.

imports.ProcessEnv gets the same treatment.

Fixes golang/go#41826.

Change-Id: If74d19146e9e62930d7c34f40859c27c25566c4e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263213
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-19 17:57:15 +00:00
Rob Findley 0a3dcccdcf internal/lsp/source: add a FileSource interface
Rename Snapshot.GetFile to GetVersionedFile, and make the signature of
GetFile consistent with the corresponding method on session and cache.
This allows algorithms that depend only on file state to be expressed
using this API. In a subsequent CL, this is used for building and
testing the workspace module.

Preeemptively add the FileSource interface for use in these algorithms.

Change-Id: I550906e554fd290dcdf4cac442d5f223e0f644c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263522
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: Rebecca Stambler <rstambler@golang.org>
2020-10-19 16:07:06 +00:00
Rebecca Stambler b2746f1d7a internal/lsp: fix nil pointer exception in initialization
Fixes golang/vscode-go#802

Change-Id: Ide3e834d413efcb394370a0c2e5ffa412a45e1a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263520
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-19 15:59:33 +00:00
Rob Findley 6003fad69a internal/lsp/source: delete unused Snapshot.IsSaved
Change-Id: I0f71798d81618a0a9bb992056a3c2d5f71aed150
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263207
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-17 00:14:24 +00:00
Rebecca Stambler a03874c3f7 internal/lsp: clean up unused parameters
Noticed these when I enabled the "unusedparams" analyzer. Not really
necessary to fix most of them, but seemed harmless.

Change-Id: I77c6e5f7c79f1abb701cd3332642486c34049736
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263203
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-16 23:51:31 +00:00
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
Rob Findley 593bd9b1d2 internal/lsp/cache: delay transitive invalidation in snapshot.clone
Currently, walking the transitive closure of invalidated packages
happens eagerly while we invalidate each file. Delay this until after
looping through invalidated files, so that we may more easily consider
invalidations not directly associated with an individual file change.

Change-Id: Id6a95098ce6d5d3ec70143c029ac7d2c9b8c7d28
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263205
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-10-16 23:30:29 +00:00
Rebecca Stambler e52f5410cf internal/lsp: fix analysis in all experiments, disable unusedparams
The reason unusedparams wasn't showing up was because we didn't handle
the analyses settings correctly. Fix it and remove unusedparams.

Change-Id: Ia8636c306d136a718d1d12a80326117b34f5da28
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263201
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-16 23:27:24 +00:00
Rob Findley eae18abd75 internal/lsp/cache: factor out guessPackagesForURI from snapshot.clone
To simplify snapshot.clone a bit, factor out the logic to figure out
which packages to invalidate when a new file arrives. This also made it
easier to improve the algorithm by caching os.Stat results when walking
known packages.

Change-Id: I012b60e8ad73eb4df80950aac48791204877e9e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263204
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-10-16 21:48:57 +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
Matthew Dempsky a78bdc4e06 x/tools/go/analysis/passes/unsafeptr: report Header misuse
This CL updates unsafeptr to report about *x and &x expressions where
the pointed-to variable has type reflect.SliceHeader or
reflect.StringHeader.

- Disallowing *x means that reflect.{Slice,String}Header.Data can only
  be accessed using field selection via a *reflect.{Slice,String}Header
  value.

- Disallowing &x means that a *reflect.{Slice,String}Header value can
  only be created by converting from an unsafe.Pointer.

Well, almost only. There are still tricks that can be played to
workaround both of these. For example, a pointer can be dereferenced
via reflection, or a user could write a conversion like:

    type T reflect.SliceHeader
    _ = (*reflect.SliceHeader)(&T{})

But presumably this at least raises the bar enough that someone is
likely to pause to figure out the correct way to use
reflect.{Slice,String}Header.

Notably, disallowing *x and &x does *not* emit warnings for code that
uses reflect.{Slice,String}Header purely as values. For example, the
tests in internal/unsafeheader. Such code is arguably still a
violation of the unsafe.Pointer safety rules ("reflect.SliceHeader and
reflect.StringHeader should be used [...] never as plain structs"),
but is benign.

Updates golang/go#40701.

Change-Id: Id21996bfee07acc0d927a525797dca344bc804d8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248192
Reviewed-by: Michael Matloob <matloob@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
2020-10-16 18:50:37 +00:00
Matthew Dempsky 255fb2adf6 x/tools/go/analysis/passes/unsafeptr: stricter reporting
The unsafe.Pointer safety rules have three separate rules allowing
conversion of uintptr to unsafe.Pointer:

(3) allows converting unsafe.Pointer to uintptr, performing
arithmetic, and converting back;

(5) allows converting the results from calling
reflect.Value.{Pointer,UnsafeAddr} to unsafe.Pointer; and

(6) allows converting the Data field of reflect.{Slice,String}Header
to unsafe.Pointer.

Notably, these are three separate rules, and they're not allowed to be
arbitrarily mixed. For example, this is not allowed:

    unsafe.Pointer(v.UnsafeAddr() + x) // BAD

It needs to instead be written as:

    unsafe.Pointer(uintptr(unsafe.Pointer(v.UnsafeAddr())) + x)

(For further explanation on why this is necessary, see
https://github.com/google/go-cmp/issues/167#issuecomment-546093202.)

This CL brings cmd/vet's unsafeptr check inline with the
unsafe.Pointer rules and cmd/compile's implementation thereof.

Change-Id: I1844e0f71dcc8fb7aafacc144b86cc80a2b83b42
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248191
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
2020-10-16 18:50:07 +00:00
Peter Weinbergr a2250d31f3 internal/lsp: add gopls semtok command and semantic token tests
The command 'gopls semtok <file>.go' produces a version of <file>.go
decorated with comments describing tokens as semantic tokens. The
format is described towards the top of cmd/semantictokens.go.

There are also tests in testdata/semantic/. a.go is used by lsp_test.go
(with -cover) to show that essentially all of semantic.go is executed.
b.go illustrates the handling of strange, but legal, constructs
like 'const false = nil and non-ascii'. The .golden files show
the expected results.

The implementation will panic, rather than log, on unexpected state.

gopls semtok has been run on all the .go files in x/tools and in
the source distribution. There were no unexpected messages nor panics.

Change-Id: I11715bcc8d6830d1951eb58239978c4a363bbc30
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262198
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>
2020-10-16 18:10:36 +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
Hana c90119023d internal/lsp/source/genapijson: add 'gopls_' prefix to commands
This CL adjusts the genapijson program as the follow up of the command
name change cls. The program loads the command list by parsing the
source code and uses the result to compute the codelens list.
Involved data types are also used for JSON marshalling, so I just
update the command name after codelens list loading is done using
the command data.

Updates golang/go#41187
Fixes golang/go#41985

Change-Id: Ic5e818e11b09c649f462fe87dabee0be64c96c2a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262354
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-10-16 15:26:35 +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
Heschi Kreinick b29caf79d4 internal/lsp/source: include setting name in all settings errors
Every setting parse error should include the name of the error for user
sanity. Add it in the errorf method, clean up redundancy, and make
existing errors more consistent/correct.

Updates golang/go#41964.

Change-Id: I8f980ceb5d82d4238edcd4095ea0e9572ac9c271
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262353
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-15 17:44:10 +00:00