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

5574 Коммитов

Автор SHA1 Сообщение Дата
Rob Findley ac45abd4c8 gopls/internal/regtest: update TestEditFile to use a modified buffer
In CL 267577, the fake editor was updated to automatically refresh
unmodified buffers with on-disk changes. This created a race in
TestEditFile, which asserts that on-disk changes are NOT reflected in
open buffers.

Fix this by inserting a trivial modification to the open buffer.  Also
make the test deterministic, so that it fails consistently without this
modification.

Change-Id: If20af2a3e8f33a64a7514ae3fb5469bd9c59a9c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270244
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-11-16 00:27:33 +00:00
Rebecca Stambler 9712d02be3 internal/lsp: add ?utm_source=gopls to links to pkg.go.dev
This extra query needs to be added before any link anchors (#), so it's
a little more complicated to add than expected. Separating out the
anchor from the link path simplifies the code a little bit and allows
us to create the correct links.

Fixes golang/go#42602

Change-Id: Ia72d50e20b1446149f1ddd36b12f6d968a9b06cb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270097
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-16 00:15:58 +00:00
Rebecca Stambler 61ea331ec0 internal/lsp/source: handle nil pointer exception in completion
Fixes golang/vscode-go#923

Change-Id: I168228876e0bfc4de12b88697494898287f8762b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270098
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-14 22:40:30 +00:00
Heschi Kreinick 1643af1435 internal/regtest: refactor diagnostic expectation implementation
The various diagnostic expectation functions had a huge amount of
duplicate code between them. Make the DiagnosticExpectation type more
concrete make the functions thin wrappers around it.

I think there's probably an argument to be made for a fluent interface
here, rather than half a dozen functions, but not now.

This rewrites NoDiagnosticWithMessage, which as far as I can tell made
no sense. Please correct me if I'm wrong.

Change-Id: I16d713ed3dccb7c3cf456d9c293c184fb8e83950
Reviewed-on: https://go-review.googlesource.com/c/tools/+/269319
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-11-13 20:20:37 +00:00
Peter Weinbergr 559c4acc06 internal/lsp: make log message for debug server clickable
When the debug server by -debug=localhost:0, a log message says on
which port to find the server. The new message gives a full URL
for the debug server.

Change-Id: I08fcaacbaf8de3591fce7854e373ba7d58931470
Reviewed-on: https://go-review.googlesource.com/c/tools/+/269921
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Peter Weinberger <pjw@google.com>
2020-11-13 16:40:40 +00:00
Rebecca Stambler eeaa07dd76 internal/lsp: remove gopls-<name> configuration
This was an undocumented and unused option to allow users some extra
per-workspace folder configuration. Editor clients need to offer that
support for it to be useful, and right now, none do. Remove the
configuration now so that we don't have to support it in the future.

For more context, see the discussion on golang/go#41966.

Fixes golang/go#41966.

Change-Id: I820b810d7a1ba02b0ec10cc47c79e670f7e67bb8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/269597
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-11-12 18:51:08 +00:00
yangwenmai b38955972a internal/lsp/cache: fix InDir error comment
Change-Id: I06b5cfe3053a5ebfc45e34c4b8aeeb10393ce581
Reviewed-on: https://go-review.googlesource.com/c/tools/+/269397
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>
2020-11-12 17:17:26 +00:00
Heschi Kreinick 41a3a58938 internal/lsp: fix recursive go generate pattern
In CL 256941 I suggested using `go generate ...` to run all the
generates in the current directory and its subdirectories. That was
wrong: ... means all in-scope packages. The correct pattern is ./... .
Change-Id: I1cb4e6b7cfbcd9b8f943d7193e4aee216614cdff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/269318
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-11-11 22:45:57 +00:00
Pontus Leitzler 5794f8bd7a internal/lsp: trim progress report messages
Progress reporting has three different kinds, "begin", "report" and
"end". Each of them comes with a text message attached.

The "report" kind is sometimes raw output, for example from go test, so
the output could end with a newline.

This change trims "report" messages to ensure consistency with "begin"
and "end" that doesn't end with a newline.

Change-Id: I779dc41fdf3f6281d9d44f64e9cee9bbcde0b4cd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266078
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Daniel Martí <mvdan@mvdan.cc>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-11-11 21:33:28 +00:00
Pontus Leitzler 69daaf961d internal/lsp: do not treat failed go test commands as errors
The "go test" command invoked via code action/code lens performs a
ShowMessage callback to the client when the test is done.

Previously it did set severity to "Error" when the test failed, but a
failing test isn't a error condition per se. This changes the result to
be of severity Info for both successful and failed test invocations.

Change-Id: Ib76558d98a434c706823617b9901a88e53864319
Reviewed-on: https://go-review.googlesource.com/c/tools/+/269257
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Daniel Martí <mvdan@mvdan.cc>
2020-11-11 13:33:15 +00:00
Rob Findley 7099162a90 internal/lsp: remove dead code
Running `staticcheck ./internal/lsp/...` turned up a few instances of
dead code. Remove them.

Change-Id: Ic53db59cd0959fad960b086158eb550a624a4d91
Reviewed-on: https://go-review.googlesource.com/c/tools/+/268580
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: Heschi Kreinick <heschi@google.com>
2020-11-10 20:14:00 +00:00
Heschi Kreinick 092357f697 internal/lsp/cache: disable GOPACKAGESDRIVER
In practice, we only support the go command, and now that we rely on the
private packagesinternal APIs to set -mod and -modfile, GOPACKAGESDRIVER
is actively broken. Forcibly disable it.

Change-Id: I91f8c0d29fada2fe87ad9fdfec6ba8c5504c80cd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/268977
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>
2020-11-10 19:54:50 +00:00
Heschi Kreinick f6c1dd6914 internal/lsp/cache: suppress Load log spam
moduleLoadScope triggers a load of many packages, just like
viewLoadScope, and should not log each loaded package.

Change-Id: Ifd59b41a496da8eb57421f948b9327519e82d2ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/268538
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-10 18:16:08 +00:00
Rob Findley 53e0aa8268 gopls/internal/regtest: add an option to nest the workdir
Add a regtest run option NestWorkdir, which causes the working directory
to be nested in the editor workspace, and use it in some modfile tests
to exercise the new workspace logic.

For now we only run the nested tests while using experimental workspace
modules. In a later CL, the 'legacy' mode will be updated to find a
solitary nested module, at which point we should be able to run nested
in all modes.

Fixes golang/go#42111

Change-Id: I0bd3b31969684bc1ba1935633cbb9a3f26de1587
Reviewed-on: https://go-review.googlesource.com/c/tools/+/257138
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-11-10 18:07:23 +00:00
Rob Findley 079ba7bd75 internal/typesinternal: add a copy of the Go 1.16 go/types error codes
This CL adds a copy of the internal error codes added to go/types in
https://golang.org/cl/264179. In a subsequent CL, we will use these to
extract the unexported error code from go/types errors via reflection.

A generated String method is added to provide a human-readable code for
the user.

For golang/go#42290

Change-Id: I280c9b111598426dce4eef38b9979919ed590068
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267939
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-11-10 12:42:07 +00:00
Rebecca Stambler 169ad6d6ec internal/lsp: avoid diagnosing unopened non-workspace packages
This fixes an issue where we were reloading packages in the vendor
directory when they changed on-disk. We should only do this if the
packages are part of the workspace or the files are opened.

Change-Id: Iefbd690ec0c096d9a40c62ce567c18335024ea15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/268038
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-10 03:05:25 +00:00
Rebecca Stambler 3db8fd2658 internal/lsp: use a structured format for the server's version
The server reports its version to the client--add some structure to this
report so that the client can parse and use it.

Fixes golang/go#42171

Change-Id: I00bff3615391cbeede89e4be6b0d028fed67989e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266198
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-09 18:20:53 +00:00
Heschi Kreinick 8694a4a169 internal/lsp/source: don't find possible interface references to types
In CL 259998 we added the ability to find calls to methods through
interfaces. That included very common interfaces like Stringer, which we
judged unfortunate but possibly acceptable. We didn't consider the
behavior when searching for references to a type. When searching for
references to a type that happens to be a Stringer, the user almost
certainly doesn't want to see all uses of the Stringer interface. Don't
consider interface references to types.

No tests; I don't think this is worth a regtest and the marker tests
can't check a negative AFAIK.

Fixes golang/go#42350.

Change-Id: I0b929d8743f7f0b4e7543e8d35921a7cf3784bf5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/268462
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-11-09 18:10:55 +00:00
Heschi Kreinick 78b1585853 internal/lsp/fake: reflect on-disk changes in clean buffers
If an open buffer is unmodified from the on-disk version, and that
on-disk content changes, VS Code will update the buffer with the change.
This is relevant for our quick fixes that use the go command to make
changes to go.mod/sum -- we want tests to pick up the changes without
needing to close/reopen the buffer.

For whatever reason, VS Code doesn't do this for deletions, and it made
the implementation easier, so I followed suit. I also mimicked its
behavior of sending both in-memory and on-disk change notifications.

Change-Id: I838a64b2f48f3cbe1a86035293923951b53aecf3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267577
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-11-05 22:03:10 +00:00
Rebecca Stambler bc9fc8d8c4 internal/lsp: fix flickering analysis diagnostics
Also, change withAnalysis to includesAnalysis to make the name a bit
more accurate.

Fixes golang/go#42363

Change-Id: If50f7d36b953e6627ed9ba049357a2b86dc3f676
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267817
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-05 17:38:54 +00:00
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