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

5445 Коммитов

Автор SHA1 Сообщение Дата
Rebecca Stambler a7380940e0 internal/lsp: pass a parsed module to go mod tidy
This allows us to show parsing errors as part of module diagnostics.

Change-Id: I558b95c145135482fdfceef8a5c68c62a6d32721
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271630
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-20 02:54:08 +00:00
Rebecca Stambler c0d5e89189 internal/lsp/fake: hold the mutex for all of SaveBufferWithoutActions
This addresses the race seen in
https://storage.googleapis.com/go-build-log/5ba1c3f2/windows-386-2008_2bf3acc7.log.

Paraphrased from Rob in chat:

The race is triggered because of the additional asynchronous handling of
file changes added to sync non-dirty files on disk changes. The buffer
is marked as non-dirty, THEN the on-disk change is processed, sending a
didChange, THEN the didSave is sent (https://golang.org/cl/267577).

Also, don't send didChange for formatting if nothing has changed.

Change-Id: Ibc6a55d35dee99c04dadf5470c2d68ca937f849b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271578
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-19 19:12:46 +00:00
Rebecca Stambler be796f87a6 gopls/internal/regtest: handle flake in TestCRLF
Make the test a little more stable by making sure diagnostics complete
before organizing imports in these tests.

Change-Id: Id23341569207878554902887498632d6f1ce56cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271628
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-11-19 19:02:02 +00:00
Rebecca Stambler 0557df368a internal/lsp/source: set experimentalPackageCacheKey to true by default
Fixes golang/go#42692

Change-Id: I10ccec29a707391442c23c88d3f26955e103130d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271478
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-19 17:46:15 +00:00
Michaël Lévesque-Dion 4783bc9beb Handle BareInits option in ssa.BuilderMode
Fixes golang/go#42614

Change-Id: I9546804af627cc97e7aebafc66ba3e8928d1c049
GitHub-Last-Rev: 05f5aa85b5
GitHub-Pull-Request: golang/tools#257
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270177
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2020-11-19 13:27:11 +00:00
Rebecca Stambler 25dc3e1ccc internal/lsp: handle deletion of a directory on disk
The current DidModifyFiles logic does not handle the possibility of a
directory URI in a didChangeWatchedFiles request. For creation and
changes, this is fine because only file URIs matter in those cases, but
for deletion, the deletion of a directory signifies the deletion of all
of the files in it.

Add handling for directories by looking up all of the known files in a
given directory. We then create file modifications for all of those
files, instead of the directory.

Fixes golang/go#38422

Change-Id: I26d7b93285367fe116fd1cb3e8ec13a276f9e517
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266138
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-11-19 05:40:27 +00:00
Heschi Kreinick 4d9c4f8a78 internal/lsp/mod: speed up and simplify go.mod code lenses
The tidy and upgrade code lenses first run the go command they
represent, then show the lens if there are changes to be made. While
this makes for a cleaner user experience, it also means that we're
running a go command that hits the network in a synchronous code lens
call. That's risky if the user is on a slow network connection.

Removing the call does represent a change, possibly a regression, in UX.
However, we already felt that the presentation of the upgrade option on
each dependency line was too noisy. Therefore the only remaining benefit
is that the lenses only appear when they have something to do. We've
decided that's not sufficient justification. Remove the calls.

We may recreate them as diagnostics in the future, so I've left
ModUpgrade around. (ModTidy is still used by diagnostics.)

Change-Id: I16c5eaebd1a50e5358c2addde9c1bb3f1182aac2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271297
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-18 21:56:54 +00:00
Rebecca Stambler 1727ee11c4 internal/lsp/cache: fix a staticcheck warning by handling error
Change-Id: Ic8d1e7a046d60eb98007e355f3bef2537072a473
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271298
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-18 21:47:00 +00:00
Heschi Kreinick 6ed8ff9ad9 internal/lsp: support unimported completions in multi-module mode
Refactor to use goCommandInvocation to get the evironment for
goimports. That takes care of most of the work; all that's left is to
track the go.mod hash so we know when to clear the cache.

Fixes golang/go#41836.

Change-Id: I614dacad04adfb879ead55e3b8640e57816534cb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270877
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-11-18 17:45:08 +00:00
Rebecca Stambler 598b068a91 internal/lsp: fix end positions for multi-line comments with CRLF lines
The previous work-around assumed that the end of the comment would be
off by one line, when in reality, it is off by the offset of the number
of \r in the comment, which may result in the comment end position being
off by multiple lines. Work around this by scanning for the end of the
comment position using text/scanner.

Fixes golang/go#42646

Change-Id: Icc33e889546f324c6b65b55a98dea587f84c8f01
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270879
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-18 03:03:13 +00:00
Rebecca Stambler bd56c0adb3 internal/lsp: use a marker test for struct field ranking test
Change-Id: I70faef2c789a3cc7b4dee8c7dd5dcac0e06d7568
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270880
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-18 00:33:11 +00:00
Chiawen Chen 74a3905de1 internal/lsp: order struct fields completions by definition
Previously struct fields completions are ordered alphabetically.
Now it is ordered by its order in definition.

Fixes golang/go#42626

Change-Id: I8c404205b97fa9f1a5a66a95a84033b6f0f48eae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270777
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-11-17 23:31:01 +00:00
Rob Findley f544f6cb68 gopls/internal/regtest: eliminate log duplication
The regtest runner currently logs every framed connection, which results
in duplicate RPC tracing (one from the client perspective, one from the
server perspective).

This is unnecessarily noisy. Just log the first connection (currently
from the client perspective).

Change-Id: I4164cde8263e4267e4e45369bd54176c782c4707
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270357
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>
Reviewed-by: Peter Weinberger <pjw@google.com>
2020-11-17 22:57:35 +00:00
Rebecca Stambler 9036a0f9af Revert "internal/lsp: explicitly watch all known directories"
This reverts commit 3c3a81204b.

Reason for revert: OpenBSD trybots are failing

Change-Id: I39f52ef07a667ed1457d2ae53863af15134eb78e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270798
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>
Trust: Rebecca Stambler <rstambler@golang.org>
2020-11-17 15:25:13 +00:00
Rebecca Stambler 3c3a81204b internal/lsp: explicitly watch all known directories
VS Code's file watching API doesn't send notifications about directory
deletions unless you register for them explicitly (see
https://github.com/microsoft/vscode/issues/109754). Rather than watch
every file in the workspace, keep track of every relevant directory and
register file watchers for it.

This CL moves the snapshot's WorkspaceDirectories function to the
session and changes it to a KnownDirectories function. It returns all of
the directories and subdirectories known the session at a given moment.
Top-level directories are marked as such so that their *.{go,mod,sum}
contents can be watched, while subdirectories are just watched by path
so we can be notified of deletions.

Fixes golang/go#42348

Change-Id: If80a26cf6af5a2c2f7d87bb57b9ef5cb3dcf04ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267120
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-17 02:10:29 +00:00
Rebecca Stambler 74f2986df7 internal/lsp: show critical error pop-ups as progress reports
We've been looking for a way to show unintrusive error status reports to
users--try using progress reports as a way of populating a status bar.
This avoids the problem of annoying the user with constant pop-ups.

Whenever an error is returns from (*snapshot).WorkspacePackages, we
start a progress report with the error message. If the error goes away
on the next call to diagnostics, or the error message changes, we will
either remove or update the progress report.

Screencast: https://drive.google.com/file/d/1tG9pc_tPsLoqkQHiJqdY8b06TzTkPVae/view?usp=sharing&resourcekey=0-CEG_LhGHYiFp9S37ut_kgw

Updates golang/go#42250

Change-Id: I8a529a911883092bc08af32246719d883dc5f5a2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/268677
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-17 01:39:53 +00:00
Michael Matloob 1d699438d2 go/packages: handle variation an an error message
go/packages has a special case for cmd/go errors that result from
errors running the 'pkg-config' tool. When modules are missing from
the module cache cmd/go can download modules, and log a message for
each downloaded module, so add a special case to the special case
to check for that message.

Also remove a usage of the x/xerrors package now that it's been folded
into the stdlib for a while.

Fixes golang/go#36770

Change-Id: If1cf8c5d83ac84a51b8bafc4930a0869674d216a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/261502
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-11-16 18:20:00 +00:00
Rebecca Stambler 6f6c72aec4 internal/lsp: fix capability registration for semantic tokens
Fixes golang/go#42148

Change-Id: Icd063d70cc9b822a4bfb69f2d47ac06f19c18131
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270359
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>
Trust: Rebecca Stambler <rstambler@golang.org>
2020-11-16 18:11:12 +00:00
Heschi Kreinick d68bbb5467 internal/gocommand: improve debug string
The current debug string looks like `go [go list foo]` because I forgot
that argv[0] is a thing. Remove the duplication, and quote things only
when necessary.

Change-Id: Ib751a39435e5a3453833539307d12c9715cc1cad
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270037
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-11-16 17:23:50 +00:00
Heschi Kreinick 247bdb27d1 go/packages: start with empty environment
go/packages is documented as starting with an empty environment if
Config.Env is populated. Fixing all uses of gocommand.Invocation was a
daunting task, so add a mode flag to it instead and set it just in
go/packages.

Clean up packagesdriver.GetSizes, which seems to be completely unused?

Fixes golang/go#42590.

Change-Id: Idac2e1a4798b4a2f5e7c8aa0a1a089a6bd3630ba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270038
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-16 17:23:36 +00:00
Peter Weinbergr 1a2739ce1b internal/lsp: get debug pages limping along again
Changes to the cache data structure broke the templates displaying
information in the debug server. This CL makes small changes to
get the pages working again. it adds  a link to the command line
on the Info page.

More work is needed. For instance, only the memory page refreshes
automatically; options could be displayed; information
about diagnostics could be displayed, as could be information
about modules, and no doubt there's more.

I'm working on a test to typecheck the templates.

Fixes golang/go#41343

Change-Id: I98538a8673de1a9589d09660eab47ad04eb2cc14
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270099
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Peter Weinberger <pjw@google.com>
2020-11-16 16:55:47 +00:00
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