1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:18:35 -06:00
Commit Graph

1723 Commits

Author SHA1 Message Date
Rebecca Stambler
ddb87c8c46 internal/lsp: add an importShortcut configuration
This configuration deals with the fact that VS Code has the same
shortcut for go-to-definition and clicking a link. Many users don't like
the behavior of this shortcut triggering both requests, so we allow
users to choose between each behavior.

Fixes golang/go#39065

Change-Id: I760c99c1fade4d157515d3b0fd647daf0c8314eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/242457
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-15 23:00:36 +00:00
Rebecca Stambler
4cea89713c internal/lsp: handle nil pointer in PackageStats
Fixes golang/go#40224

Change-Id: I9f3f194b1c115ff0242cbce89a36e20d9e21a41f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/242797
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-15 19:57:38 +00:00
Rebecca Stambler
b42590c1b1 internal/lsp/source: handle nil pointer in newBuiltinSignature
Fixes golang/go#40230

Change-Id: I457dd3ef009c9df9293f66871acdd90dcc6e1dcc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/242798
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-07-15 19:52:07 +00:00
Peter Weinbergr
9048b464a0 internal/lsp: avoid panic caused by assuming file ends with newline
importPrefix in format.go computes the end of the package statement
including a trailing newline. This causes a panic if the user has
not typed the newline. The code now checks for that case.

Fixes golang/go#40208

Change-Id: I4c5118a5de78027e6c5e6ed91dfddca81e38f7e9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/242638
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-14 19:07:37 +00:00
Hyoyoung CHANG
6acd2ab80e internal/lsp: always show signature as the top line in hover
The current behavior is inconsistent across different configurations.
The signature is the top line for FullDocumentation, but the last line
for synopsis documentation.

Change-Id: I2fe1e1c7bfa38ae46fda06b0ecd4c7712b0e74af
GitHub-Last-Rev: d3b768558f21f518d1296b6fc776cf3974f441d9
GitHub-Pull-Request: golang/tools#241
Reviewed-on: https://go-review.googlesource.com/c/tools/+/242104
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-07-13 23:52:42 +00:00
Rebecca Stambler
62a0bb781d gopls, internal/lsp: support an extra formatting hook for gofumpt
This change reworks CL 240118 to apply gofumpt directly as a formatter,
not an analyzer. Depending on how gofumpt changes, we may be able to use
it as an analyzer in the future, but for now it's just easier to add it
as a formatting hook.

Fixes golang/go#39805

Change-Id: I227fde4b1916d8a82557f30dfca88e155136dff5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241985
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-13 21:42:47 +00:00
Rebecca Stambler
f8240f79c3 internal/lsp: add changeMethods logic to rename check
This logic is directly copied from the refactor/rename package. See
https://github.com/golang/tools/blob/master/refactor/rename/rename.go#L321.

Fixes golang/go#39269

Change-Id: Ibe335aab37c495d2a960cb9da254b24b6fbac8e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/242158
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-07-13 19:50:33 +00:00
Rebecca Stambler
01425d7016 internal/lsp/source: add Vendor to list of supported commands
I wanted to add a regtest for this, but then immediately got stumped on
how to do it well. The best I've got is to add a helper that wraps
the client's call to executeCommand, but it's used in so many places that
an easier fix was to put it in executeCommand itself.

Fixes golang/go#40101

Change-Id: Iafb804fb77e57e6ac01e3de1d115058b21ac1954
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241984
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-13 19:07:48 +00:00
Rebecca Stambler
f739c553ea internal/analysisinternal: do not initialize {Get,Set}TypeErrors
Follow up from CL 241619.

Change-Id: Iab0c0e42f28bd79024e36cbfdab59eac0f2af23c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241897
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-13 16:05:48 +00:00
Rebecca Stambler
fd294ab11a internal/lsp: watch go.{mod,sum} files, as well as Go files
Not sure how this hasn't come up earlier. We aren't noticing file
changes on-disk for go.mod/go.sum files.

Fixes golang/vscode-go#297

Change-Id: I4532a252f330404515efec244a9c266a765e6bcb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/242160
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-07-13 01:13:07 +00:00
Rebecca Stambler
7342f9734a internal/lsp/cmd: add a -vv flag for higher verbosity
Add a higher log level for the command-line. This uses the verboseOutput
setting.

Updates golang/go#40139

Change-Id: I9b7edcda12b0431058c9cfe1413b7c5fc016c026
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241857
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-07-11 15:58:55 +00:00
Rebecca Stambler
f1c4188a97 internal/lsp, go/packages: reproduce and fix golang/go#39646
This test exposes a lot of fundamental issues with `go list` overlays.
Now that we have the regression test framework, we can copy it over and
make any flakes completely reproducible by waiting for each change to
complete.

The issue here ended up being that initial workspace load returns
workspace packages with no associated files due to golang/go#39986.
Working around this allows invalidation to proceed as usual.

In the process of debugging this, I also noticed that packages can get
loaded as command-line-arguments even when we can get the correct
package path for them. It's pretty complicated to fix this, so
restructured the code a tiny bit and left a TODO. I'd like to come back
to this at some point, but it's not pressing since I was able to fix
this bug.

Fixes golang/go#39646.
Updates golang/go#39986.

Change-Id: Id6b08a5e92d28eddc731feb0ef3fd3b3fc69e64b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240098
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-07-10 04:28:08 +00:00
Rebecca Stambler
125cc70a40 internal/lsp: add new go.mod requires to files with unused require
This change addresses an underlying issue with the go.mod code, which is
that it was modifying go.mod files without cloning them. This could've
resulted in some ugly race conditions.

We also handle the fact that new dependencies weren't being added
cleanly to files that already had unused dependencies.

Fixes golang/go#39041

Change-Id: I96ee0052d8d29a25e24f0bda9688e780a0fa7442
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241443
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-10 04:15:23 +00:00
Rebecca Stambler
55a0fde516 internal/lsp: fix rename with Windows line endings
Replacing the text in the comment line-by-line prevents issues to do
with CRLF/LF line endings.

No test, because txtar expects LF line endings, and I didn't think it
was worth more invasive changes to handle this.

Fixes golang/go#39364.

Change-Id: Ia26b311a851396e4dde1954ebfc1b40c0a3c04fb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240757
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-07-10 04:00:52 +00:00
Rob Findley
e327e1019d internal/lsp/regtest: standardize on 20s timeout
The default regtest timeout was increased to 60s a while ago to try to
avoid flakes.

We think we've figured out the flakes, so drop it back down.  Start with
20s, since TestGOMODCACHE (which had overridden its timeout to 5s)
occasionally fails on freebsd:
https://build.golang.org/log/6c607c7fd3e886cf23127c958ae17637440fbc63

Change-Id: I10e6927985b8fb1d149070e204bd8ca120309c7b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240060
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-07-09 18:17:11 +00:00
Rob Findley
e404ca24fb internal/lsp/regtest: use a common directory for regtest sandboxes
For easier debugging (and less cruft if regtests are ctrl-c'ed), root
all regtest sandboxes in a common directory.

This also tries one last time to clean up the directory, and fails on an
error. This might be flaky on windows, but hasn't been so far...

Also give regtest sandboxes names derived from their test name.

Updates golang/go#39384
Updates golang/go#38490

Change-Id: Iae53c29e75f5eb2b8d938d205fbeb463ffc82eb2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240059
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-07-09 18:15:24 +00:00
Heschi Kreinick
df98bc6d45 internal/lsp/regtest: remove stray short timeout
Apparently 5 seconds is too short for the freebsd-race builder and we
care about that.

Fixes golang/go#40090.

Change-Id: I6dad57402ed18e7c9e01f695ada7cc8b0cf35fb4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241521
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-07-08 18:38:56 +00:00
Rebecca Stambler
3544e8c95d internal/lsp/regtest: add a regtest for golang/go#39296
Looks like the issue described in
https://github.com/golang/go/issues/39296#issuecomment-652058883 is
resolved with Go 1.15.

Fixes golang/go#39296

Change-Id: Ibe694281d4d4d40df3dc7bacc5837f593bb1dc5a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241398
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-08 18:30:29 +00:00
Heschi Kreinick
31b9a74881 internal/lsp/cache: handle missing mod file
If the config changes in non-module mode, don't look at the nonexistant mod file.

I actually caught this case after review but didn't finish the job.

Fixes golang/go#40121.

Change-Id: Ic888f7eab5f882e6ca79b046b5a3fb37b3b19e5c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241520
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-07-08 18:08:30 +00:00
Rebecca Stambler
7370b03448 internal/lsp: check if analysis enabled in convenience fixes
Change-Id: I49c7808ee07340cea0381f324b1fb113ec405213
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241519
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-08 18:02:25 +00:00
Rebecca Stambler
134513de88 internal/lsp/regtest: await IWL before running tests
This change makes these tests a little more resilient by making sure
that the initial workspace load is completed before we run them.

Change-Id: I24735da31cc045cb78dfb280e88136b5835351a6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241276
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-08 00:37:08 +00:00
Rebecca Stambler
d5a745333d internal/lsp/source: disable fillstruct by default
The discussion on golang/vscode-go#299 has uncovered the fact that
go/printer is very expensive, and we're calling it frequently on file
changes. Analyzers whose suggested fixes require the original file
content are generally posing issues; this is being discussed on
golang/go#40110.

Updates golang/vscode-go#299

Change-Id: I5cb370c9cb508203e463e7243fc781e75876fe30
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241321
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-08 00:01:38 +00:00
Heschi Kreinick
065b96d36c internal/lsp/cache: fix race in RunProcessEnvFunc
Changing build flags (-modfile) while work is happening in the
background causes races. Explicitly detect relevant configuration
changes and only modify the ProcessEnv then, when the resolver is
inactive after the call to ClearForNewMod.

This still leaves a very small window for a race: if refreshProcessEnv
has already captured env but not yet started priming the cache, it may
race with the modification. But I don't expect it to be a problem in
practice.

Fixes golang/go#39865.

Change-Id: I31c79f39be55975fee14aa0e548b060c46cdd882
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241317
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-07-07 22:21:32 +00:00
Josh Baum
9c9572d6f9 internal/lsp: extract highlighted selection to variable
I add a code action that triggers upon request of the user. A variable
name is generated manually for the extracted code because the LSP does
not support a user's ability to provide a name.

Change-Id: Id1ec19b49562b7cfbc2cd416378bec9bd021d82f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240182
Run-TryBot: Josh Baum <joshbaum@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-07-07 21:12:28 +00:00
Heschi Kreinick
416e8f4faf internal/imports: require valid options, move LocalPrefix up
CL 239754 eagerly initialized the environment. This turns out to be a
problem for gopls, which calls ApplyFixes with no ProcessEnv.
Reinitializing it every time seriously harmed the performance of
unimported completions. Move back to lazy initialization.

Working with invalid options has caused a lot of confusion; this is only
the most recent. We have to maintain backwards compatibility in the
externally visible API, but everywhere else we can require fully
populated options. That includes the source byte slice and the options.

LocalPrefix is really more of an Option than an attribute of the
ProcessEnv, and it is needed in ApplyFixes where we really don't want to
have to pass a ProcessEnv. Move it up to Options.

Change-Id: Ib9466c375a640a521721da4587091bf93bbdaa3c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241159
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-07-07 20:02:13 +00:00
Josh Baum
9e0a013e85 internal/lsp/analysis/fillstruct: support anonymous structs
The previous implementation did not support filling anonymous structs.
This is distinct from filling a struct that has an anonymous
struct as a field. That field will still not be filled.
golang/go#39929 has been opened to address this limitation.

Fixes: golang/go#39803
Change-Id: Ia7ba9fda2bdee092d182e0a23829b9a6d9a4b986
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240463
Run-TryBot: Josh Baum <joshbaum@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-07-07 13:47:15 +00:00
Rebecca Stambler
682c4542fd all: update dependencies in go.mod file
CL 226639 changed the positions of the go.mod diagnostics (in a
negligible way), but the tests are quite brittle and can't handle the
different position. Rewrite this test as a regression test to handle it.

The special // indirect marker can be removed from the go/expect package
as a result, since it was only used in this one place.

Change-Id: I7d9a62e32e53d477838e65673635ed231c07b659
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240691
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-06 23:19:48 +00:00
Søren L. Hansen
95bc2bdf7e internal/lsp/source: handle nil pointer in comment completions
c.pkg.GetTypeInfo().ObjectOf(node.Name) will sometimes return nil.
Check for that and a few other things that c.found also checks for.

Fixes golang/go#40043

Change-Id: I4a2b40adbbd740323e10b3460f025b29cff74130
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241019
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-07-06 18:08:31 +00:00
zikaeroh
0cc1aa72b3 gopls/internal/hooks, internal/lsp/source: only match full words in link regexes
The current URL regexes (including xurls) match links in any part of a
string. However, this leads to odd underlining within words which just
so happen to have valid domain names as substrings. For example, a
comment which contains "reflect.DeepEqual" will match the URL regex as
"reflect.de" is a domain name.

Ensure that the URLs only match full regex words by adding \b around the
expressions. For xurls, this is done by pulling the expression out of
Relaxed() and recreating the Regexp.

While I'm here, make the non-gopls module expression prefer the longest
match, as xurls does.

Change-Id: I403db970fa1661c443b0693c03f8dee114f8eaff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240738
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-07-02 04:49:44 +00:00
Rebecca Stambler
f01a4bec33 internal/lsp: support opening single files
This change permits starting gopls without a root URI or any workspace
folders. If no view is found for an opened file, we try to create a new
view based on the module root of that file. In GOPATH mode, we just
use the directory containing the file.

I wrote a regtest for this by adding a new configuration that gets
propagated to the sandbox. I'm not sure if this is the best way to do
that, so I'll let Rob advise.

Fixes golang/go#34160

Change-Id: I3deca3ac1b86b69eba416891a1c28fd35658a2ed
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240099
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-01 22:10:12 +00:00
Rebecca Stambler
ea7be8d74e internal/lsp/regtest: add regression tests for on-disk file changes
There are still many more cases to check, but this is a good starting
point. A few tests have skips in them because I encountered bugs, which
I plan to go back and fix.

Change-Id: I0b7bbeb632d38c09d6bdb1f4866d81a1690d6ca7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238917
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-01 22:06:37 +00:00
Muir Manders
1837592efa internal/lsp/source: speed up completion candidate formatting
Completion could be slow due to calls to astutil.PathEnclosingInterval
for every candidate during formatting. There were two reasons we
called PEI:

1. To properly render type alias names, we must refer to the AST
   because the alias name is not available in the typed world.
   Previously we would call PEI to find the *type.Var's
   corresponding *ast.Field, but now we have a PosToField cache that
   lets us jump straight from the types.Object's token.Pos to the
   corresponding *ast.Field.

2. To display an object's documentation we must refer to the AST. We
   need the object's declaring node and any containing ast.Decl. We
   now maintain a special PosToDecl cache so we can avoid the PEI call
   in this case as well.

We can't use a single cache for both because the *ast.Field's position
is present in both caches (but points to different nodes). The caches
are memoized to defer generation until they are needed and to save
work creating them if the *ast.Files haven't changed.

These changes speed up completing the fields of
github.com/aws/aws-sdk-go/service/ec2 from 18.5s to 45ms on my laptop.

Fixes golang/go#37450.

Change-Id: I25cc5ea39551db728a2348f346342ebebeddd049
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221021
Run-TryBot: Muir Manders <muir@mnd.rs>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-07-01 04:11:22 +00:00
Rebecca Stambler
9a0e069805 internal/lsp/cmd: change pre-filled issue header for gopls bug
Change-Id: I221f2e6a0dc41cfd8325df64607b5c625d69ca17
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240503
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-07-01 03:39:15 +00:00
Rebecca Stambler
a32c0cb1d5 internal/lsp: decorate error message from workspace/configuration
Fixes golang/go#39896

Change-Id: Ib63e3b4b716f6005b3cbbc92ede40fdbfc8ca22f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240619
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-07-01 00:03:37 +00:00
TheSecEng
b2d8b03366 internal/lsp: remove VS Code-specific completion hack
This hack was previously being used to correct the rankings for VS Code
Go users. This logic has since been moved into the VS Code Go plugin.

Change-Id: Ia6bff53eb2c6dbe479faa1fd0667d763837eea78
GitHub-Last-Rev: e7fed76b3f85b0db3b705cbb6945cecd855d2c7b
GitHub-Pull-Request: golang/tools#225
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231098
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-30 15:48:51 +00:00
Rebecca Stambler
4bdfe1a3b7 internal/lsp/cache: handle a few possible panics in PackageStats
Change-Id: I50dbe8bf7d801e7325bdbe413368e85779511d85
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240183
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-30 15:45:28 +00:00
Josh Baum
aa3d50130b internal/analysisinternal: prevent fillstruct panic on nil package
The previous implementation missed a nil check which caused a panic
when the package of a type was nil.

Fixes: golang/go#39899
Change-Id: I2dfb50d6b79f52df367e093e5d857cd70b7cef27
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240537
Run-TryBot: Josh Baum <joshbaum@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-30 14:51:37 +00:00
Rob Findley
aa94e735be internal/lsp/source: add a new symbolStyle configuration option
Add a symbolStyle configuration option, and use it to parameterize the
following behavior when computing workspace symbols:

 + package (default): include package name in the workspace symbol.
 + full: fully qualify the symbol by import path
 + dynamic: use as the symbol the shortest suffix of the full path that
   contains the match.

To implement this, expose package name in the source.Package interface.
To be consistent with other handling in the cache package, define a new
cache.packageName named string type, to avoid confusion with packageID
or packagePath (if confusing those two identifiers was a problem, surely
it is a potential problem for package name as well).

Change-Id: Ic8ed6ba5473b0523b97e677878e5e6bddfff10a7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236842
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
2020-06-26 17:13:37 +00:00
Paul Jolly
84cfedeb1e internal/lsp: fully qualify workspace Symbol matches
Fully qualify (using a package's import path) symbols when matching
them. This is a minimal change in preparation for later changes to add
more advanced query functionality to the workspace Symbol method.

Add more comprehensive regtest tests (covering case sensitive, case
insensitive and fuzzy matchers) in addition to updating lsp tests.

Change-Id: I675cde2f7b492158988cf9c3206a0a55fe29622a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228123
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-26 16:54:09 +00:00
Rebecca Stambler
bcbc01e07a internal/lsp: add a new regtest to reproduce golang/go#39646
Change-Id: I51d8c66a83ecae1c8fc1f39c0e90a03a732c263b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240063
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-26 03:28:29 +00:00
Rob Findley
6506e20df3 internal/lsp/fake: explicitly set GOPACKAGESDRIVER=off in regtests
In the past, changes to GOPACKAGESDRIVER have led to some confusing
regtest failures. Explicitly set it off.

Updates golang/go#39384

Change-Id: I303a58380a5e46e6621c19b2edc40d43199bb343
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240058
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-25 21:18:23 +00:00
Rebecca Stambler
fadf93ffb2 internal/lsp: watch all files in the module and replace target
Previously, our file watching only considered the root directory of the
view, which may not include the entire module or its replaced
dependencies. Now we expand our watching to include the whole module.

As part of testing this, I noticed that VS Code's file watcher actually
only sends updates for files in the workspace, even if we request
notifications for all files in the module. I filed an issue to ask about
this: https://github.com/microsoft/vscode-languageserver-node/issues/641.

Change-Id: I9499d31aff273f69e9c117511e7985ff58b7fdc4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239198
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-25 21:08:52 +00:00
Heschi Kreinick
e31c80b82c all: rework goimports environment, support GOMODCACHE
This CL got away from me a little.

For a number of reasons, the existing goimports API of passing in values
for various GO* values was not working. For one, the number of necessary
variables kept growing. For another, we tried to avoid calling `go env`
in GOPATH mode by using `build.Default`, but that turns out to be buggy;
see golang/go#39838. And finally, it created massive confusion about
whether the values were intended to be read from the OS environment, or
fully evaluated by the `go` command.

There are only two users of the internal imports API, so there really
shouldn't need to be more than two modes. For the command line tool, we
have to call `go env` to deal with the `go/build` bug. So we just do it.
Tests use that same path, but can augment the enviroment to set
themselves up. In contrast, `gopls` needs to fully specify the
environment. It can simply pass in the fully evaluated GO* values.

Finally, make the change I was actually here to make: propagate
GOMODCACHE and use it where appropriate.

Fixes golang/go#39761.

Change-Id: I720c69839d91d66d98e94dfc5f065ba0279c5542
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239754
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-25 17:33:20 +00:00
Josh Baum
727c06e3f1 internal/lsp/analysis/fillstruct: correct pointer to builtin values
The current implementation correctly calls 'new' when filling a
pointer to a builtin type.

Fixes: golang/go#39854
Change-Id: I0c2b27bb57fd865c4376279059ad060608d48ba3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239978
Run-TryBot: Josh Baum <joshbaum@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-25 16:34:51 +00:00
Rebecca Stambler
aa12c9ebf5 internal/lsp: handle panics due to line numbers in fillstruct
Change-Id: I90f3fd2daf180705048d494476acac5a213f5fb3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239751
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Baum <joshbaum@google.com>
2020-06-25 15:39:20 +00:00
Heschi Kreinick
88f3c62a19 internal/span: handle file URLs with two slashes
Correct file URLs should have three slashes: two for the protocol
(file://) and one for the beginning of the path. Perhaps unsurprisingly,
VS Code is sending us URLs with only two. Add the third.

Fixes golang/go#39789

Change-Id: I922b3adf1d5980991a43229d952d77fecaf1366b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239743
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-24 22:54:43 +00:00
Rebecca Stambler
7a9acb0a45 internal/lsp/source: fix panic in test code lens
Change-Id: I727b2772c63752cb5d3bb4b9165f984b64adc842
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239752
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-24 22:30:20 +00:00
Rebecca Stambler
25775e59ac internal/memoize: add an error return to (*handle).Get
Fixes golang/go#36004

Change-Id: I8da7c21eaa9cf6ffac12aabdd6803d06781cef32
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239564
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-24 16:33:19 +00:00
Thomas
dcbf2a9ed1 internal/jsonrpc2: omit empty error data
The spec states error data may be omitted. It is currently always encoded
as null, despite having no usage.

Omit the field if empty, and add a test to prove the behaviour.

Fixes golang/go#39736

Change-Id: Icdb39409010f3a42f84d2372c2061e4bc7cc198e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239059
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-06-24 06:08:01 +00:00
Rebecca Stambler
f8e0ea3a3a internal/lsp/analysis/fillstruct: add indentation for struct fields
Getting the right indentation for the text in the AST proves to be a
little complicated. The most reasonable approach seems to be writing
out the AST, getting the lines with the struct definition on it,
and trimming whitespace to get the current indent. Then, we add this
indent to the struct fields in the new text.

Change-Id: I1cc3421d95edae61cfb662254ff3fb759b5c487f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239199
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-23 20:47:33 +00:00