1
0
mirror of https://github.com/golang/go synced 2024-10-01 12:28:37 -06:00
Commit Graph

1099 Commits

Author SHA1 Message Date
Heschi Kreinick
50c778fb86 internal/imports: redesign scan API
We have multiple use cases for scanning: goimports, import completion,
and unimported completions. All three need slightly different features,
and the latter have very different performance considerations. Scanning
everything all at once and returning it was not good enough for them.

Instead, design the API as a series of callbacks for each
directory/package: first we discover its existence, then we load its
package name, then we load its exports. At each step the caller can
choose whether to proceed with the package. Import completion can stop
before loading exports, goimports can apply its directory name
heuristics, and in the future we'll be able to stop the scan short once
we've found all the results we want for completions.

I don't intend any significant changes here but there may be some little
ones around the edges.

Change-Id: I39c3aa08cc0e4793c280242c342770f62e101364
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212631
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-30 21:10:22 +00:00
Heschi Kreinick
ac3e9e73d1 internal/imports: remove go/packages support
We don't use the go/packages resolver in goimports, and as we develop
gopls it only becomes harder to use there. Give up.

Change-Id: Ic8b566c6dd730b23b0c81d7d34a41f16fe0be7e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212630
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-30 21:10:16 +00:00
Heschi Kreinick
fd66c7521c internal/lsp/source: don't get unnecessary unimported completions
Unimported completions are always low-priority. If the user already
has 100 completion options, the unimported ones are probably not useful.
There's no point in calculating any of them.

Also, only do unimported completions for package members when they're
enabled. Oops.

Change-Id: I7535a22ad56bed869dceb6cd0ffdfc6390cf8eb5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212629
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-30 21:10:09 +00:00
Rebecca Stambler
234df48a20 internal/lsp: load metadata for a single package ID, when needed
The metadata for the workspace packages may not be available when we
need it, so we should allow loading a single package ID. This can be
improved in follow-up CLs by consolidating the individual IDs into one
call to packages.Load. Some adjustments from CL 212102 were split out
into this CL.

Change-Id: I173a79a3cb136530bc99d093f1c2be189eac8ce2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212628
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-30 21:09:35 +00:00
Dan Kortschak
6c68fec0bc all: remove many cases of space-space
Change-Id: I49eb8410d4143c67dfccf027f8b2794e66963415
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212580
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-30 19:07:42 +00:00
Dan Kortschak
9fb4d21460 tools/internal/lsp/cmd: fix documentation
Change-Id: Ie21babc8879977fb1a3ef02737dbd24904722c26
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212579
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-30 18:10:14 +00:00
Rebecca Stambler
7b8e75db28 internal/lsp: create links for golang/go#1234-style strings
This change treats text of the format golang/go#1234 as a link to the Go
issue tracker. This will improve the readability of TODOs that include a
link to an issue, since it doesn't have to be an actual link.

Change-Id: I27606ceb9cbb15bc6bfb1d7aa660d3f4fdd08739
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212518
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-27 05:39:25 +00:00
Rebecca Stambler
99d11d0e63 internal/lsp: refactor and document options
This change cleans up the structure of the Options struct in order to
clearly delineate which options should be configurable for the user.
Follow-up work is needed to refactor the completion options to fit into
this structure, as well as to make sure that the name of the field is
the name of the setting. This will make it easier to generate markdown
documentation from the code.

Also, remove options that are no longer in-use and mark them as
deprecated.

Change-Id: Ib34ae25789e21b76077a564601e487fbebfc5f48
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212519
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-27 05:17:27 +00:00
Koichi Shiraishi
819aba5d6d internal/lsp/cmd: remove unnecessary message from help
remove "goplsgoplsserve" from before the main commands output.

Change-Id: Ib41376d4ad4b601650730f053682868408617c4d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212577
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-27 05:00:04 +00:00
Rebecca Stambler
6b505debf4 gopls: use mvdan.cc/xurls for textDocument/documentLink
Our current implementation isn't robust, and it doesn't seem worth it to
invest significant effort in improving it when this library exists.

Also, make the protocol part of the default URL regex non-optional, as
the alternative is that any string of the format "foo.bar" will appear
to be a link.

Updates golang/go#33505

Change-Id: Ia430a1c193eded394f8af12050bdd4dc2a9ccc94
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212517
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-26 21:20:25 +00:00
Muir Manders
dd894d0a8a internal/lsp: trim address operator from completion filterText
VSCode doesn't like (read: ignores) candidates whose filterText begins
with "&", so trim it off.

I also tweaked "addressed" candidates to include the "&" prefix in the
item label as well so the user can see what they will get.

Change-Id: I85840d036e379a202b72e28c5257807a069ae45d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212406
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-24 05:57:32 +00:00
Muir Manders
3721262b3e internal/lsp: support taking address for completion candidates
We now support taking the address of objects to make better completion
candidates. For example:

i := 123
var p *int = <> // now you get a candidate for "&i"

This required that we track addressability better, particularly when
searching for deep candidates. Now each candidate knows if it is
addressable, and the deep search propagates addressability to child
candidates appropriately.

The basic propagation logic is:

- In-scope *types.Var candidates are addressable. This handles your
  basic "foo" variable whose address if "&foo".

- Surrounding selector is addressable based on type checker info. This
  knows "foo.bar.<>" is addressable but "foo.bar().<>" isn't

- When evaluating deep completions, fields after a function call lose
  addressability, but fields after a pointer regain addressability. For
  example, "foo.bar()" isn't addressable, but "foo.bar().baz" is
  addressable if "bar()" returns a pointer.

Fixes golang/go#36132.

Change-Id: I6a8659eb8c203262aedf86844ac39a2d1e81ecc4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212399
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-23 23:54:10 +00:00
Muir Manders
918115ff85 internal/lsp: refactor find-implementation handling
This is the start of a significant refactoring to implementations,
references, and rename (i.e. everything that searches across
packages). The main goal of the refactoring is to push the package
variant logic from internal/lsp into internal/source so that all users
of source benefit, not just internal/lsp. It also makes it easier to
write tests for various cases because the source tests invoke the
source package directly (so previously did not include all the package
variants).

Currently source.Identifer() handles lots of disparate use cases.
Things like definition and hover don't care about package variants but
do care about other random bits of info that may not apply to
implementations or references. So, I'm splitting implementations out
from source.Identifier. As I work through references and rename
hopefully things will end up separated into smaller chunks.

I also improved implementation deduping to happen earlier. I thought I
could dedupe using obj.Pos(), but mirror objects in package variants
have different positions (suggesting they aren't reusing the
same *ast.File). Instead I used token.Position to dedupe.

Change-Id: I81c2b3ec33bf12640accb852be9ecdea4aa24d69
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211718
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-23 22:59:19 +00:00
Muir Manders
4d2fe2ba67 internal/lsp/source: move some data onto "candidate" struct
Make the score and import info be fields on "candidate" since they are
properties of the candidate. There shouldn't be a functional change
here; I'm just consolidating things in preparation for an additional
piece of candidate metadata.

Change-Id: I4c7c8ef40e8e5db7b52691cca21490ba13c17642
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212398
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-23 22:26:30 +00:00
Muir Manders
7bd96bd597 internal/lsp/source: improve completion in value spec
If the enclosing value spec specifies a type on the LHS, we now prefer
completions of that type on the RHS. For example:

i := 123
var foo int = // prefer "i" since we know we want an int

I also added a special case to lexical() to know that we can't offer
objects defined on the LHS as completions on the RHS. For example:

var foo int = // don't offer "foo" as completion

Change-Id: I8e24245a2bc86a29887360e7f642a4cbb87fa6ca
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212401
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-23 21:16:02 +00:00
Rohan Challa
c7341709c6 internal/lsp: cleanup temporary go.mod file on shutdown
This commit will delete the temporary go.mod file that is attached
to a view when the session is shutdown.

Updates golang/go#31999

Change-Id: I0f6b0663b0a814ce45d9b12468669f415f8c36aa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212479
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-23 19:58:47 +00:00
awh6al
8c5978f193 internal/lsp: make golint happy
This PR fixes internal/lsp/fuzzy/matcher.go:230:4: should replace skipPenalty += 1 with skipPenalty++ .

Change-Id: I7d5b6c20e25503ea266e26783e68ad92fd8b36e0
GitHub-Last-Rev: 36fd2c25232f593f905051692e84d8c634fb7a46
GitHub-Pull-Request: golang/tools#194
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212400
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-23 18:17:04 +00:00
Ian Cottrell
f13409bbeb internal/telemetry: clean up test data
the current implementation likes to sort maps, so we make sure
tag lists are in sorted order already so that a stable encoder
produces the same result

Change-Id: Ia7ce05f35edb636817c354d9df02de753a48fe1d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210216
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-12-20 23:47:30 +00:00
Ian Cottrell
c7346ecdc6 internal/telemetry: remove an extraneous comment
There was a fragment of a sentence that must have been from a previous version
(as it talks about a return value for a function that does not have one).

Change-Id: I9d154fe10711344f93e1d49b68a811dbc9772710
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212241
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-12-20 23:47:11 +00:00
Ian Cottrell
814139985e internal/telemetry: obey the onlyErrors flag in the log writer
has no impact because there are no use cases that don't set it to true right now

Change-Id: I2bc485226078c710bdc36397b96755cdce82d9cc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212242
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-12-20 23:46:55 +00:00
Ian Cottrell
2f6d8bf0ad internal/lsp: change tests to use the main exporter
Now the tests are at a high enough level, we can
switch them to using the full exporter by bulding
a fake http client to bind it to. This lets us
use the true public interface and also excercise
more of the functionality in the tests.
With this we are now ready to replace the entire
implementation safely.

Change-Id: Ifdbf6230de3ec7c7c5381c840b135cb7a0bc1e55
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209161
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-12-20 19:55:05 +00:00
Rohan Challa
75f8c4427c internal/lsp: change -modfile flag to tempModfile
Remove double negative issues and rename the disableTempModfile flag
to be tempModfile.

Updates golang/go#31999

Change-Id: Id62aa3707fef6758a1026c864a962f0bed36bc2b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212240
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-20 19:10:06 +00:00
Rebecca Stambler
5e752206af internal/lsp: don't clear file contents on save
CL 212037 introduced a bug with saving overlays. Since VS Code sends nil
contents for a file on save, we were deleting overlay contents on save.
This resulted in very strange behavior.

Also rename overlay.data to overlay.text to match variable names.

Fixes golang/go#36224

Change-Id: I7f2d12e369aa7f6daa2c9f36c33468ec6bf61930
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212199
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-12-19 23:08:27 +00:00
Rebecca Stambler
145a1e401f internal/lsp/cache: detach context before invalidation
In one of my previous refactoring changes, I lost the fact that the
context should be detached before invalidating a file's contents. If
this function is canceled, we will be in a bad state.

Also, small change to return ctx.Err() instead of a custom error message
from (*packageHandle).check.

Change-Id: I19e513e09e438feee105fdd89cb7364a0c3c5e7f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212104
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-19 21:23:07 +00:00
Rebecca Stambler
041a08a54a internal/lsp/cache: remove errors from dependencies
Now that `go list` errors are sufficient for us to determine a circular
dependency, we don't need to cache errors on dependency packages.

Change-Id: I0633aeb356f93d21afed3371d61d7eae7de255ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212197
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-19 21:17:59 +00:00
Rebecca Stambler
85a3356613 internal/lsp/cache: consolidate function to update overlays
This change merges the small helper functions that modified overlays
into a single function and removes the openFiles sync.Map in the view.

Change-Id: Id94c7d86228c9628b7373fab0030ad0c8018dda5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212037
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-19 21:06:08 +00:00
Heschi Kreinick
62b9674312 internal/imports: consider direct mod deps more relevant
As a followup to CL 204203, prefer direct dependencies over indirect.
This should improve results for common names like "log" and "errors".

Updates golang/go#36077.

Change-Id: I3f8cfa070832c2035aec60c4e583ee1c0abf5085
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212021
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-19 20:57:09 +00:00
Rebecca Stambler
2208e1677e internal/lsp: eliminate source.File type and move GetFile to snapshot
This change eliminates the extra step of calling GetFile on the view and
getting the FileHandle from the snapshot. It also eliminiates the
redundant source.File type. Follow up changes will clean up the file
kind handling, since it still exists on the fileBase type.

Change-Id: I635ab8632821b36e062be5151eaab425a5698f60
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211778
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-19 20:51:25 +00:00
Muir Manders
56b0b28a00 internal/lsp: put verbose go/packages output behind verboseOutput flag
On startup gopls runs go/packages over the entire workspace. The log
message in question outputs each package found along with all the
package's filenames. Obviously in a large project this produces an
incredible amount of output. Fix by putting the log message behind the
"verboseOutput" flag when invoking go/packages in the "dir/..." mode.
I also added the go/packages "query" string to the
once-per-go-packages-call log message so it is more useful.

Change-Id: I651419e34a855325056bca6720eda8671f7d5fa8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210739
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-19 19:20:50 +00:00
Rohan Challa
bdebc07e97 internal/lsp: fix highlighting of inexact matches when highlighting from the right
There is an issue when highlighting a single character identifier if the cursor is on the right of it. This problem
is a result of an assumption made in astutil.PathEnclosingInterval relating to the arguments passed in. Specifically,
if start==end, the 1-char interval following start is used instead. As a result, we might not get an exact match
so we should check the 1-char interval to the left of the passed in position to see if that is an exact match.

Updates golang/go#34496

Change-Id: If689fdf695df6ec1bc1935088e50d3de055bd5db
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212137
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-19 19:05:06 +00:00
Peter Weinberger
a98e7fcfeb internal/lps/protocol: bring code.ts up to date with latest changes.
This CL makes sure that code.ts will generate the latest version
of tsprotocol.go. It has a more succinct way of deciding which fields
need to be pointers.

Change-Id: I6854cb2f096d3707bc3b828a9601f9384638f475
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212140
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-19 18:45:41 +00:00
Emmanuel T Odeke
2ad5dca7a5 telemetry/log: sample reference for benchmarking harness
Serves as a reference harness to get benchmarking started.
Steps to run benchmark:

$ go test -run=^$ -bench=. -count=10

After you grab the output, put the various comparisons
into files before.txt and after.txt then edit those
result names to have a common name e.g.
    s/BenchmarkLoggingNoExporter/BenchmarkIt/g
    s/BenchmarkNoTracingNoMetricsNoLogging/BenchmarkIt/g
    s/BenchmarkLoggingStdlib/BenchmarkIt/g

Now run benchstat:

* All compared
$ benchstat no_log.txt tellog.txt stdlog.txt
name \ time/op    no_log.txt  tellog.txt   stdlog.txt
It-8              289ns ± 2%  2780ns ± 3%  5100ns ± 3%

name \ alloc/op   no_log.txt  tellog.txt   stdlog.txt
It-8              80.0B ± 0%  728.0B ± 0%  568.0B ± 0%

name \ allocs/op  no_log.txt  tellog.txt   stdlog.txt
It-8               5.00 ± 0%   32.00 ± 0%   28.00 ± 0%

* No logging vs telemetry log
$ benchstat no_log.txt tellog.txt
name  old time/op    new time/op    delta
It-8     289ns ± 2%    2780ns ± 3%  +862.31%  (p=0.000 n=10+9)

name  old alloc/op   new alloc/op   delta
It-8     80.0B ± 0%    728.0B ± 0%  +810.00%  (p=0.000 n=10+10)

name  old allocs/op  new allocs/op  delta
It-8      5.00 ± 0%     32.00 ± 0%  +540.00%  (p=0.000 n=10+10)

* No logging vs Standard library "log"
$ benchstat no_log.txt stdlog.txt
name  old time/op    new time/op    delta
It-8     289ns ± 2%    5100ns ± 3%  +1665.16%  (p=0.000 n=10+9)

name  old alloc/op   new alloc/op   delta
It-8     80.0B ± 0%    568.0B ± 0%   +610.00%  (p=0.000 n=10+10)

name  old allocs/op  new allocs/op  delta
It-8      5.00 ± 0%     28.00 ± 0%   +460.00%  (p=0.000 n=10+10)

* telemetry log vs Standard library "log"
$ benchstat tellog.txt stdlog.txt
name  old time/op    new time/op    delta
It-8    2.78µs ± 3%    5.10µs ± 3%  +83.43%  (p=0.000 n=9+9)

name  old alloc/op   new alloc/op   delta
It-8      728B ± 0%      568B ± 0%  -21.98%  (p=0.000 n=10+10)

name  old allocs/op  new allocs/op  delta
It-8      32.0 ± 0%      28.0 ± 0%  -12.50%  (p=0.000 n=10+10)

Change-Id: I53b15e9da315615278c576f3a60108435417a9f7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212078
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-12-19 18:19:13 +00:00
Rohan Challa
3aa5a36464 internal/lsp: add gopls setting to disable use of -modfile flag behavior
This CL adds a "disableTempModfile" boolean that can be turned on or off.
While we are adding support for go.mod files in gopls, this flag will allow
users to opt out of using the -modfile flag that is enabled in Go 1.14. This
flag might be removed at a future point, the decision still needs to be made.

Updates golang/go#31999

Change-Id: Ic90229333e988fcc6d461ab1ee47bce1114bd965
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212139
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-19 18:11:24 +00:00
Rohan Challa
4f29fbcc08 go/packages: change import cycle errorkind from UnknownError to ListError
The import cycle not allowed error should be returned as a ListError not
an UnknownError.

Fixes golang/go#35964

Change-Id: Ibc575f92d926ff715c0da67a4fceda05badcc652
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212138
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-19 18:10:03 +00:00
Muir Manders
979b82bfef internal/lsp/cache: fix excessive recursion in (*snapshot).clone()
It wasn't infinite, but gopls would sit at 100% cpu for ~25 seconds
whenever I made a change to a package imported by essentially
everything in my project.

Change-Id: Ifa253a4de06897260e0791888284527258e8de48
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212000
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-19 04:18:53 +00:00
Heschi Kreinick
84f0c7cf60 internal/lsp/cache: don't forget files just because they change
The situation in golang/go#35638 was as follows:

didOpen main.go creates a snapshot that knows main.go is in package
"mod.com".
didChange main.go creates a snapshot. When a file changes, we discard
its contents by leaving the file handle out of the "files" map.
didOpen const.go creates a snapshot, and attempts to invalidate the
metadata for packages in the same directory.

The way we detect packages in the same directory is by iterating through
the files in the snapshot. But we threw away the only file in "mod.com"
in step 2 when its contents changed. If a diagnostics run happened to
get in between the two steps, it would re-load main.go and the bug would
go away. If not, step 3 would find no files and fail to invalidate
"mod.com".

The best way to fix this is to insert the new file handle eagerly during
cloning. That way there's no confusion.

Fixes golang/go#35638.

Change-Id: I340bd28a96ad7b4cc912032065f3c2732c380bb2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211578
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-18 22:55:20 +00:00
Rebecca Stambler
ca0407e66b internal/lsp: return snapshots from text modifications
Eliminate the file watcher, since it led to a lot of confusion and
difficulty reasoning about the flow of a file action. This change splits
a file invalidation into the two logical steps - 1) things that affect
the overlay, and 2) things that affect the view. It is based on top of
CL 211757, so the diffs will look better once that CL is merged.

Change-Id: I277475569b61f3c80feaa6b6fe457b4bace82e35
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211777
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-18 22:53:40 +00:00
Rebecca Stambler
41c101f395 internal/lsp/source: fix completion budget type
Change-Id: I43d7b067e8bedc6371c32a2655afb9dc87f71f66
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211759
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
2019-12-18 21:55:16 +00:00
Rebecca Stambler
61483d104a internal/lsp: show comments for grouped variable declarations
Fixes golang/go#36139

Change-Id: I8aaf1a5d65b8d66ea7bb350439cc960c7505307d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211637
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-18 20:39:36 +00:00
Rebecca Stambler
d270ebf96e internal/lsp/cache: move overlay and debug handling into separate files
This change has no code modifications. Just move the handling for
overlays and debugging into separate files to make them easier to find.
Also, add some missing copyrights.

Change-Id: I7256f704c017457fa3418818d03f89f061af6fc9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211757
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-18 19:17:43 +00:00
Heschi Kreinick
bc4a8d3946 internal/lsp/cache: don't invalidate dependents' metadata
Rerun of CL 210458. Only invalidate metadata for packages directly
involving the changed file.

Change-Id: Id28647851254a9bdcb3dbe7a762194bb025da913
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211779
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-18 18:41:16 +00:00
Billie Cleek
6f9e13bbec internal/lsp/debug: print the debug port
Print the debug port to stderr when the debug server listens on a
dynamic port so that clients can determine which port to use when
launching a browser to the debug view.

Change-Id: I92f5e334df5cefdf54f7242ac2328b026852c70e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211798
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-12-18 04:04:34 +00:00
Rohan Challa
62a9628863 internal/lsp: use the -modfile flag to update a different go.mod file
In the upcoming Go 1.14 release, there is an introduction of the -modfile
flag which allows a user to run a go command but choose where to direct the
go.mod file updates. The information about this can be found here: golang/go#34506.

This change starts setting up the infrastructure to handle the seperate modfile
rather than keep changing a user's go.mod file. To support versions of Go that are
not 1.14, we run a modified "go list" command that checks the release tags to see
if 1.14 is contained.

Updates golang/go#31999

Change-Id: Icb71b6402ec4fa07e5f6f1a63954c25520e860b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211538
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-17 22:15:16 +00:00
Rebecca Stambler
38570b7665 internal/lsp: fix links for interface methods
This change handles fixes the link behavior for interface methods.
For example, before this change, hovering on "Name"  would point to an
incorrect link: https://pkg.go.dev/go/types?tab=doc#object.Name.
The correct link is
https://pkg.go.dev/go/types?tab=doc#TypeName.Name.

var typ *types.Named
typ.Obj().Name()

Change-Id: If28bff6069239d487e5d86cacafc20800493ebe8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211585
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-17 19:37:44 +00:00
Muir Manders
640059499b internal/lsp: kill some dead code
Clear out a few things I noticed aren't really used anymore.

Change-Id: I03f955015632197b56230ae0443cfb3871b54db2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211717
Run-TryBot: Muir Manders <muir@mnd.rs>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-17 19:30:50 +00:00
Rebecca Stambler
f2a421a9e5 internal/lsp: change completionBudget to milliseconds
Change-Id: Ic12f6325bc8307056481edff61da06cfc4f232b3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211677
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
2019-12-17 18:37:38 +00:00
Bryan C. Mills
01c78d57fd internal/imports: set the Dir field on the build.Context (instead of WorkingDir) if present
Updates golang/go#36168

Change-Id: Ibdb277176a28da72d85a4c7c8ed7c903c278125e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211599
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-12-17 14:41:53 +00:00
Rebecca Stambler
42268a1f04 internal/lsp: fix link anchors for struct fields
This change fixes the link anchors for fields within a struct or
composite literal by getting the enclosing types.Type.

Fixes golang/go#36138

Change-Id: I534a900fad6fa6fa1b1acaa5a63ca264c5d34c39
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211582
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-17 02:48:38 +00:00
Rebecca Stambler
c39ce2148d internal/lsp: expose option to disable timeouts for completion
This is useful for integration testing.

Fixes golang/go#36142

Change-Id: I175510df19f384a0a027267337925ebae15ef827
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211584
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-17 01:14:48 +00:00
Heschi Kreinick
621d4eef75 imports: pass more of the environment
goimports now wants various module flags, but I forgot to set them up in
the many places we create environments. Do so.

Change-Id: Ic3817caeb8fc4d564b49006ef6ca6842b2498eaf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211581
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-17 00:36:01 +00:00
Heschi Kreinick
846828e8ce internal/lsp/source: fix crash on conflict markers in imports
Generally speaking, if the imports package can operate on a file, we can
assume that it's in good enough shape for the rest of our work. That
means it's important we run imports first. On one code path, we weren't.

Fixes golang/go#36162.

Change-Id: I750aff31e0c3706aeb798ceb60c35ea17ba95943
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211580
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-16 23:08:29 +00:00
Rebecca Stambler
1d943b0903 internal/lsp: change CompletionItem.{Command,TextEdit} to pointers
This is a continuation of the discussion on
https://github.com/microsoft/vscode-go/issues/2920. Add corresponding
checks to internal/lsp/cmd/capabilities_test.go.

Change-Id: I51af05dee9e7ecea0e40733dd4c5ca3dfb8f4dd8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209859
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-16 22:14:42 +00:00
Heschi Kreinick
4981f6b3ad internal/lsp/cache: consolidate snapshot cloning
Cloning is complicated enough without worrying about concurrency, so
hold the snapshot's lock during the entire process.

Consolidate everything into one function. I don't think that the split
was making it easier to understand, and I was able to see and clean up
some extra complexity once it was all in one place. Let's discuss
options if you think the result is too long.

I don't intend any semantic changes in this CL.

Updates golang/go#35638.

Change-Id: I05c4b28875976293f5fcd56248d9c9e468f85cc6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211537
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-16 21:51:44 +00:00
Arda Güçlü
99b39703f4 internal/gopathwalk/walk: add missing function descriptions and renaming
Missing function descriptions are added. init is renamed setIgnoredDirs.

Change-Id: I56b5a7c3e4fcc27991b33aef16d506948ce4b36b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208358
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-12-16 21:45:07 +00:00
Muir Manders
a6aac22fcd internal/lsp: fix find-implementation for promoted methods
We weren't returning promoted methods as implementations when the
promoted method was defined in a different package than the type
implementing the interface.

Fix by properly mapping the implementer types.Object to its containing
source.Package.

I generalized the implementations() result to just contain the
implementer objects and their containing package. This allowed me to
get rid of some result prep code in Implementation().

Fixes golang/go#35972.

Change-Id: I867f2114c34e2ad39515ee3c8b6354c1cd35f7af
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210280
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-16 21:36:29 +00:00
Jędrzej Szczepaniak
a0e659d513 internal/lsp, internal/tool: clean up command line of gopls
Descriptions of certain commands were changed to not start with capital
letter.

All of the commands were splitted into so called main
commands and feature commands.

Package tool did have a limitation that revealed itself when command
was invoked only with `-h`, i.e. `gopls -h`. Limitation was that in
above mentioned case, FlagSet.Parse() was intercepting `-h` flag and
printing just default usage.

Updates golang/go#35855

Change-Id: I9bd27fc72e8fb8d18025d95ebcae974dd5583e91
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210359
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-12-16 17:36:52 +00:00
Muir Manders
49a3e744a4 internal/lsp: remove useless signature cast completion candidate
In a previous change I inadvertently added completion candidates like:

var f func(int)
f = <> // useless candidate "func(int)(<>)"

Ignoring the fact it is a syntax error without more parens around the
signature, it isn't a useful candidate because you don't need to cast
when assigning a named signature type to an unnamed type.

Change-Id: Ic261817af344ee47193240a11dca5d3a32cbd293
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211319
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-16 05:27:35 +00:00
Rohan Challa
04c2e8eff9 internal/lsp: skip return highlighting if cursor is in arglist of func
If the cursor is within an argument that is within a callExpr which is
in a return statement, we only want it to highlight the ident that the cursor
is in. We do not want it to highlight the entire function.

Updates golang/go#34496

Change-Id: If4025660a99fd5df90098e0560a5e9e7260e33c8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211338
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-13 22:12:58 +00:00
Rohan Challa
56463cc14b internal/lsp: create parseModHandle for storing go.mod data
Created an analogous data structure for go.mod files when we parse them
using the golang.org/x/mod package. Gopls can now access the data
within a go.mod file using a parseModHandle and the corresponding
parseModData object. This will help down the road when it is time
to implement the lsp functions for go.mod files.

Updates golang/go#31999

Change-Id: Ibd4d64569bbe3df61b203490b63399d479e7d794
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211303
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-13 22:03:54 +00:00
Rohan Challa
7ebc6af015 internal/lsp: add diagnostic on import causing import cycle
After the addition of golang/go#35964, the import cycle error now
has the import stack attached in the message. This CL parses that
stack and attached the import cycle diagnostic to the import versus
just adding it to the first character of the .go file.

Fixes golang/go#33085

Change-Id: I6f5f067c338879b898829951236f816aa63d9dfa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210942
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-13 19:54:01 +00:00
Rebecca Stambler
74e303f875 internal/lsp/source: fix error message for multiple GOPATHs
The current handling of error messages did not address the case that a
user may have multiple directories listed in their GOPATH.

Fixes golang/go#36120

Change-Id: I8e68a45d3dd902975a0ccf4177ec2698accdf69d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211304
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-13 19:21:09 +00:00
Iskander Sharipov
27b81bef4a internal/lsp/tests: add error handling for @item()
If there are less than 3 args for @item, it does an early
return without recording it for a given pos.
This leads to a panic when tests runner can't lookup
a non-nil item for a pos.

Since other collect* methods seem to use t.Fatal for error
handling, do the same in collectCompletionItems().

Change-Id: I21960731f532b93029e6e06800e0484dc7d599df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211257
Run-TryBot: Iskander Sharipov <quasilyte@gmail.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-13 18:39:29 +00:00
Muir Manders
0f69de236b internal/lsp: offer basic type conversion candidates
When the expected type is a basic type, we will now offer a
corresponding type conversion candidate. For example:

var foo int64
foo = // offer "int64(<>)" as a candidate

The type conversion candidate will be ranked below matching concrete
candidates but above the sea of non-matching candidates.

This change broke almost every completion test. I added a new
completion option for literal candidates so tests can selectively ask
for literal completions.

Updates golang/go#36015.

Change-Id: I63fbdb33436d662a666c1ffd3b2d918d840dccc7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210288
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-12 22:41:01 +00:00
Rebecca Stambler
cfcbc7796e internal/lsp: improve link in documentation on hover
This change refactors some of the logic that builds a link anchor for
a given symbol, pushing the actual Link into the HoverInformation struct.
This is necessary because type information is needed to build up that
link in certain cases, like methods.

The last step will be to correctly display struct fields.

Updates golang/go#34240
Fixes golang/go#36031

Change-Id: I7f989faddbaa07f91838a870b4477bf78ce8ddf7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210201
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-12 22:39:21 +00:00
Muir Manders
825cb06263 internal/lsp: downrank "nil" completion candidate
Having nil ranked normally causes it to show up as the top candidate
in cases like:

context.WithCancel(<>) // "nil" shows up before "context.Background()"

"context.Background()" gets a slight score penalty since it is a deep
completion, so "nil" is ranked highest.

Sometimes you do want "nil", but it's such a short identifier you
probably aren't leaning too heavily on autocompletion. I think it
makes sense to optimize for the case when you want something non-nil.

Change-Id: I537927db2b573535e751380c4cba5c9873dfe524
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210539
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-12 05:12:00 +00:00
Rebecca Stambler
56eb7d2c19 internal/lsp: don't resend diagnostics if they are unchanged
Cache delivered diagnostics on the server so that we can determine if
they should be resent. To be careful about this, we only reuse cached
diagnostics if they are for a greater version, or if we don't know
the file's version and it is unchanged.

Fixes golang/go#32443

Change-Id: I4ba22d85e5b21a8ad6cc62f74cd83c07d3c220cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208261
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-12 04:27:51 +00:00
Rebecca Stambler
4403f79810 internal/lsp: move DidModifyFile into internal/lsp/cache
This change is the next step in unification of text synchronization
methods. The logic really belongs in the internal/lsp/cache package
rather than the internal/lsp package.

Pulled out a function to run diagnostics on a file (diagnostics are still
run async).

Change-Id: I5e237411a02af210ad386b37a6c2aa62ef723567
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210784
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-12 03:49:59 +00:00
Muir Manders
dfebd2802a internal/lsp: fix find-references to search from all package variants
We previously searched the reverse dependencies of the "widest"
package that contained out starting identifier, but if our package has
tests then the widest package is the ".test" variant, and it has no
reverse dependencies. Fix by searching through all of the packages
that contain our starting identifier.

For example:

-- foo/foo.go --
package foo
func Foo() {}

-- foo/foo_test.go --
package foo
func TestFoo(t *testing.T) {}

-- bar/bar.go --
import "foo"
func _() {
  foo.Foo()
}

We would start searching from the foo.test variant, but we wouldn't
search package bar at all because bar does not import foo.test, it
imports plain foo. Now we search from both foo and foo.test (you still
need search foo.test to find references within foo_test.go).

Fixes golang/go#35936.

Change-Id: I5fd2f7bb130a421ed6fad92da11179995c99a2cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210537
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 23:36:49 +00:00
Rohan Challa
ad473c03aa internal/lsp: add handling for go.mod files in internal/lsp functions
When we are processing a go.mod file, we are calling go/packages.load
when we should not be. It will always return 0 packages since it is
not a .go file. This CL adds branching inside each internal/lsp protocol
function and also adds a check in snapshot.PackageHandles for the file type
and returns an error. This will prevent `go list` from running on go.mod files for now.

Updates golang/go#31999

Change-Id: Ic6d0e9b7c81e1f404342b98e10b9c5387adde2ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210757
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-11 23:24:34 +00:00
Muir Manders
4da4485a1c internal/lsp: invalidate metadata and type info more selectively
Say you have foo.go and foo_test.go yielding packages "foo" and
"foo.test". Previously when you changed foo_test.go we would
invalidate the foo.test and foo packages. Invalidating foo is not
necessary since it does not depend on any test files. Furthermore, it
caused problems because nothing would refetch foo's metadata until
foo.go changed, so various things (such as finding implementations in
packages that depend on "foo") would be broken.

Now we only invalidate metadata from packages that contain the
modified file. We only invalidate type info from packages that contain
the modified file, or from such packages' transitive reverse
dependencies.

Change-Id: I23d1af91bcdf22fad4faa1b048afe17ef4e403a1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210460
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 23:14:03 +00:00
Iskander Sharipov
ec14b29651 internal/lsp/source: fix all types in resolveInvalid
This CL teaches lsp to report `**T` instead of `**invalid type`,
`func (badParam) badResult` instead of `func (invalid type) invalid type`, etc.

To do that, we need to detect "invalid type" inside any part of a type.
I've added typeIsValid() function for that.

To simplify type formating code in resolveInvalid(), formatNode
function is added that can also format *ast.StarExpr (of any depth).
Since we already used AST printer in the same file, I
added formatNode function that is now used in both places.
While at it, replaced bytes.Buffer to strings.Builder there.

Change-Id: I3bb84c58c417b175cceefb410e238c48425f7cee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210357
Run-TryBot: Iskander Sharipov <quasilyte@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 23:00:51 +00:00
Rohan Challa
ac2db28e81 internal/lsp: invalidate workspace packages when go.mod file changes
When the go.mod file changes, we should invalidate all the files that are
contained in the package for the mod file. This will allow the files to recheck
their packages in case new packages were added in the go.mod file.
This still does not fix issue where changes to go.mod files do not trigger recalculation of diagnostics.

Updates golang/go#31999

Change-Id: I6d8f1531f5c28ed2dca7fb8ad4ee0317fada787b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210557
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 22:23:25 +00:00
Muir Manders
a27fdba277 internal/lsp: check all package variants in find-implementations
We previously only searched for implementations of the object we found
in the "widest" package variant. We instead need to search all
variants because each variant is type checked separately, and
implementations can be located in packages associated with different
variants.

For example, say you have:

-- foo/foo.go --
package foo
type Foo int
type Fooer interface { Foo() Foo }

-- foo/foo_test.go --
package foo
func TestFoo(t *testing.T) {}

-- bar/bar.go --
package bar
import "foo"
type impl struct {}
func (impl) Foo() foo.Foo { return 0 }

When you run find-implementations on the Fooer interface, we
previously would start from the (widest) foo.test's Fooer named
type. Unfortunately bar imports foo, not foo.test, so bar.impl
does not implement foo.test.Fooer. The specific reason is that
bar.impl.Foo returns foo.Foo, whereas foo.test.Fooer.Foo returns
foo.test.Foo, which are distinct *types.Named objects.

Starting our search instead from foo.Fooer resolves this issue.
However, we also need to search from foo.test.Fooer so we match any
implementations in foo_test.go.

Change-Id: I0b0039c98925410751c8f643c8ebd185340e409f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210459
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 21:44:05 +00:00
Rohan Challa
3785370768 internal/lsp: fix circular import errors to account for import stack
Hotfix for broken tests after the import stack got added to the circular import
error statement.

Change-Id: I0179b9590cad38cf9cb903f9932d9bf8fb8dc6df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210939
Run-TryBot: Rohan Challa <rohan@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-11 19:05:55 +00:00
Muir Manders
912f50adde internal/lsp: don't invalidate dependents' metadata
When a file is changed, we invalidate various cached data so we
re-type check and refetch metadata as needed. Previously when a file
changed we would delete the metadata for all transitive reverse
dependencies. This broke all-packages-in-workspace features since we
could no longer fetch the package handle for packages without
metadata.

Fix by only deleting metadata for the packages that the file being
changed belongs to. It doesn't seem like a package's metadata contains
anything that is sensitive to changes in the package's dependencies.

Change-Id: I6a2d5df49ecd4d627b37689e48ed48fe78ce658d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210458
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 18:25:29 +00:00
Clint J Edwards
98df123772 internal/lsp: add comment completions for exported vars
This should provide simple name completions for comments
above exported variables.

Can be activated with `ctrl+space` within a comment.

Pretty new, so all help is welcome.

Fixes #34010

Change-Id: I1c8f71baa3beaa22ec5fd9fd4a531284a8d125f3
GitHub-Last-Rev: a9868eb69dc587cb4579268b2c3ae46932702641
GitHub-Pull-Request: golang/tools#166
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197879
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-10 22:11:41 +00:00
Iskander Sharipov
fe93f4a7d4 internal/lsp: suggest "fallthrough" only inside switches
Change-Id: I3a6ddbc12e068da151699a1d0377670695dcf5aa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210358
Run-TryBot: Iskander Sharipov <quasilyte@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-10 22:10:49 +00:00
Peter Weinberger
1bcf67c9cb internal/lsp: Make Text in DidSave at *string rather than a string
Fix code.ts to match CL 210780.

Change-Id: Iaaa1f8b78d483e4281e6d513cf4d20ae44e46cb7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210783
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-10 20:07:04 +00:00
Rebecca Stambler
0bd90eac95 internal/lsp: make Text in DidSave request a pointer
Fixes golang/go#36063

Change-Id: I223ead138111239ae1894f5565414ac384c016e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210780
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2019-12-10 19:28:57 +00:00
Heschi Kreinick
22774f7dae internal/lsp/cache: invalidate metadata even without Create
When a new file is opened, the first time we learn about it will be a
didOpen event. We need to invalidate the package's metadata in that
case too.

Fixes golang/go#35638.

Change-Id: I36c6171e9c959c48ede9e125679e8dd1be7609f4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210559
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-09 22:52:34 +00:00
Rohan Challa
115af5e89b internal/lsp: fix control flow highlighting taking precedence
The control flow highlighting is taking precedence when
you are highlighting a key:value expression within the return statement.
Expected behavior is to just highlight all instances of the key or value and ignore
the control flow statement when inside the scope.

Fixes golang/go#36057

Change-Id: If4b254151c38d152f337833c55a456f8dce18be7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210558
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-09 20:59:57 +00:00
Muir Manders
9a30a9a96c internal/lsp: trim down implementations code
Remove the unused code that was tracking concrete-type =>
interface-type mappings. It isn't clear if there is a good spot for
this in LSP.

I also made it skip interface types when looking for implementations.
It doesn't seem useful to be shown other interface types/methods when
you are looking for implementations of a given interface type/method.

Change-Id: Ib59fb717e5c1a181cc713581a22e60ed654b918c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210279
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-09 20:39:02 +00:00
Muir Manders
259af5ff87 internal/lsp: tweak implementation tests
- Add test count to golden file so test count gets checked.
- Make @implementation note take a list of marks similar to completion
  tests.
- Get rid of unnecessary intermediate test data type.

Change-Id: I741eb14b77b0b8ed08e86c634ed39457116e8718
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210278
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-06 20:40:35 +00:00
Rebecca Stambler
bc369361f3 internal/lsp: fix error suppression in (*session).createView
I had mistakenly forgotten to return a snapshot along with the view.

Fixes golang/go#36020

Change-Id: I1fc802b8924fccec1d6aaa110640eaed490c3aa1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210215
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-06 20:33:56 +00:00
Heschi Kreinick
6d582d504c internal/lsp/source: optimize computeFixEdits
In the common case that a file has imports, we're going to diff just the
import block. That means that ApplyFixes doesn't need to produce the
whole formatted file, which is a huge speedup. We will do more work twice
for files with no imports, but those are presumably pretty short.

Hat tip to Muir for pointing towards this in
https://go-review.googlesource.com/c/tools/+/209579/2/internal/imports/imports.go#87
even if I didn't catch it.

Updates golang/go#36001.

Change-Id: Ibbeb4d88c6505eac26a36994de514813606c8c79
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210200
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-06 20:21:26 +00:00
Heschi Kreinick
330b9f1384 internal/lsp/source: cap number of unimported completions
Building unimported completions requires re-parsing and formatting at least
some of the file for each one, which adds up. Limit it to 20; I expect
people will just type more rather than scroll through a giant list.

Updates golang/go#36001.

Change-Id: Ib41232b91c327d4b824e6176e30306abf356f5b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210198
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-06 20:21:18 +00:00
Rebecca Stambler
786dcba013 internal/lsp: respect References.IncludeDeclaration setting
Previously, (*IdentifierInfo).References was returning the declaration
of the identifier among the reference results. This change alters the
behavior of this function to only ever return non-declaration
references. Declarations can be accessed through the
IdentifierInfo.Declaration field.

Fixes golang/go#36007

Change-Id: I91d82b7e6d0d51a2468d3df67f666834d2905250
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210238
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-06 20:05:57 +00:00
Rohan Challa
cec958058c internal/lsp: add error handling for self imports
This change will provide a more useful error when you
are self importing a package. It has TODOs in place to propagate the
"import cycle not allowed" error from go list to the user.

Updates golang/go#33085

Change-Id: Ia868a7c688b0f0a7a9689cfda5ea8cea8ae1faff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209857
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-06 19:13:54 +00:00
Rebecca Stambler
db903f390e internal/lsp: fix concurrent map write in file invalidation
The invalidateContent function does not acquire a snapshot's mutex to
avoid blocking other work (even though it probably should since it's
only called after a context is canceled). A case was added to iterate
through files when a file is created, and it did not respect the fact
that the snapshot's mutex was not locked, resulting in a concurrent map
read and write. This change makes sure that the access of the snapshot's
files map is guarded by a mutex.

As a follow-up, we should just acquire snapshot.mu in invalidateContent.

Updates golang/go#36006

Change-Id: Idd904ae582055ce786062df50875ac7f0896fd1c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210199
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-06 18:53:04 +00:00
Rebecca Stambler
3393d29bb9 internal/lsp: propagate and handle context cancellation errors
We don't distinguish between genuine errors and context cancellation in
diagnostics, which often results in superfluous logging of these errors.
Avoid spamming the logs with them by checking.

Also, remove the logic for sending undelivered diagnostics. It's a relic
of old bugs and isn't useful.

Change-Id: I7df226539b9b1eb49ab3aae8d7b0a67f59fb3058
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210197
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-05 22:50:56 +00:00
Heschi Kreinick
7b8c8591a9 internal/lsp/cache: clean up dead code after CL 209737
Apparently I should've had staticcheck on. We were only reading the
metadata in updateMetadata to calculate unused imports, but that's now
at a higher level.

Change-Id: Id3d54fa736062bbbf1c207b8739e87ed5a90293d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210078
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-05 21:55:04 +00:00
Heschi Kreinick
addffd168b internal/lsp: fix golden generation for import tests
A long time ago I only fixed golden generation for lsp/source. Get lsp/
and lsp/cmd too.

We have import tests that aren't formatted correctly, so we can't use
goimports to generate goldens. Just trust got.

Change-Id: If924503c0c0f6c60cd31fce194a8c1216001035b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209981
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-05 21:54:53 +00:00
Barnaby Keene
69111344d4 internal/lsp: expose godoc or pkg.go.dev link on hover
This adds a link to documentation to the hover contents for the
current symbol if it is exported.

Updates golang/go#34240

Change-Id: I19c66e91e46f79284bfd0006c53f518eda4edef7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/200604
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-05 20:53:10 +00:00
Heschi Kreinick
61fa4dffed internal/memoize: fix race on read of handle.function
Late into CL 206879 I started nulling out a handle's function when the
handle finished running. That invalidated a previous assumption that the
field was immutable. Fix the assumption, and since the case of having
multiple computations in flight is at least a little bit possible, try
harder to avoid duplicate work.

Fixes golang/go#35995.

Change-Id: Ib5e3640f931f95e35748f28f5a82cf75585b305d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210077
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-05 18:38:34 +00:00
Rebecca Stambler
d1f10d1c4e internal/lsp: refactor and clean up text synchronization
This change is the first step in reorganizing the logical flow of file
changes in the internal/lsp package. A new function,
(*server).didModifyFile does the bulk of the work, but we will be able
to push most of its details into the cache layer in a follow-up.

Also, some refactoring of the applyChanges function to flow more
logically. It was unnecessarily convoluted.

Change-Id: Icc1b8642a4cb04d309338b0f8840fe58133d3df1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209979
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-05 13:33:40 +00:00
Rebecca Stambler
a588733072 internal/lsp: return snapshot when creating a view
Previously, we returned CheckPackageHandles when creating a new view.
Now, return the view's snapshot. Also, add a WorkspacePackageIDs
function in order to run diagnostics on them.

Fixes golang/go#35548

Change-Id: Ica7e41f5a7aa3ee9413feb4de4ee16e1825db2e1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209418
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-05 13:33:17 +00:00
Muir Manders
73c7173a9f internal/lsp: fix AST bookkeeping as we repair nodes
We weren't maintaining our ancestor node list correctly. This caused
us to fail to make AST repairs in certain cases. Now we are careful to
always append to the ancestors list when recursing.

Updates golang/go#34332.

Change-Id: I9b51ec70572170d9f592060d264c98b1f9720fb8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209966
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-05 06:08:18 +00:00
zikaeroh
e84277c2c0 internal/lsp/cmd: use x/tools/gopls as the gopls bug prefix
"x/tools/gopls" appears to be the currently used prefix for gopls
issues. Make "gopls bug" use this prefix instead of just "gopls" to
avoid needing to edit titles before/after submitting.

Change-Id: I7244aa5539332cc361870f49ae4f27b2a2441571
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209964
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-05 01:26:23 +00:00
Rebecca Stambler
7a2a8a0471 internal/lsp: propagate errors through source.DocumentSymbols
We had previously been ignoring many errors in
textDocument/documentSymbols, which led to errors appearing in the VS
Code extension logs (see
https://github.com/microsoft/vscode-go/issues/2919 for more context). We
should return errors so that we can more easily debug these issues in
gopls directly.

Change-Id: Ieef7c9f0bc8296f7e12d8c84e60d8b978d311651
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209858
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-05 01:21:29 +00:00
Rebecca Stambler
ac417207ef internal/lsp: run packages.Load only if imports are added or changed
Previously, we would reload if a user's import list decreased or simply
changed order. This is not necessary. Now, we only re-run if a new import
needs to be loaded.

Updates golang/go#35388

Change-Id: I47874afe773dddb835ac27b18895e7a082950dc7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209057
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-05 01:20:12 +00:00
Muir Manders
d79e56da46 internal/lsp: always ParseFull in-workspace dependencies
When searching for implementations we look at all packages in the
workspace. We do a full parse since we need to look for non-exported
types and look in functions for type declarations. However, we always
type check a package's dependencies in export-only mode to save work.
This leads to what I call the "two world" syndrome where you have both
the export-only and full-parse versions of a package in play at once.
This is problematic because mirror objects in each version do not
compare equal.

For example:

-- a/a.go --
package a

type Breed int
const Mutt Breed = 0

type Dog interface{ Breed() Breed }

-- b/b.go --
package b

import "a"

type dog struct{}
func (dog) Breed() a.Breed { return a.Mutt }

---

In this situation, the problem is "b" loads its dependency "a" in
export only mode so it gets one version of the "a.Breed" type. The
user opens package "a" directly so it gets fully type checked and has
a second version of "a.Breed". The user searches for "a.Dog"
implementations, but "b.dog" does not implement the fully-loaded
"a.Dog" because it returns the export-only version of the "a.Breed"
type.

Fix it by always loading in-workspace dependencies in full parse mode.
We need to load them in full parse mode anyway if the user does find
references or find implementations.

In writing a test I fixed an incorrect import in the testdata. This
uncovered an unrelated bug which made a different implementation test
very flaky. I disabled it for now since I couldn't see a fix simple
enough to slip into this commit.

Fixes golang/go#35857.

Change-Id: I01509f57d54d593e62c895c7ecb93eb5f780bec7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209759
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-04 21:49:57 +00:00
Heschi Kreinick
660eba4da3 internal/lsp/source: extract helper, improve error messages
Lack of context in error messages is making my life difficult. Add
context to a few, refactoring out some duplicate code along the way.

Change-Id: I3a940b12ec7c82b1ae1fc477694a2b8b45f6ff71
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209860
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-04 19:34:30 +00:00
Heschi Kreinick
9611592c72 internal/lsp/cache: fix load race, refactor
As far as I can tell, the code I removed in from load did roughly
nothing -- returning nil metadata didn't suppress type checking as I
think was intended. Throwing away the metadata also created the race in

Pull the check for missing import changes up to PackageHandles, where it
is non-racy and can cause type checking to be skipped. Simplify and
refactor.

Fixes golang/go#35951.

Change-Id: Id4b32b86569afb36863aaf982616b2b3727b0e83
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209737
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-04 01:13:08 +00:00
galaxy-designer
db047d72ee internal/links: improve links parser, no protocol specification
The existing implementation has no consideration of links with no
protocol specification, so "example.com/comments" now it's trated as
"https://example.com/comments"

"Fixes golang/go#33505"

Corrects the regexp definition

Change-Id: I587d611f26a3f3c5ea89eda7b2c3ccf369e8bb2f
GitHub-Last-Rev: 740ffca04dd16b36a96f03781d58ff727e39ae79
GitHub-Pull-Request: golang/tools#154
Reviewed-on: https://go-review.googlesource.com/c/tools/+/194661
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-03 05:17:22 +00:00
Muir Manders
5ae4576c3a internal/lsp: improve completion after accidental keywords
Sometimes the prefix of the thing you want to complete is a keyword.
For example:

variance := 123
fmt.Println(var<>)

In this case the parser produces an *ast.BadExpr which breaks
completion. We now repair this BadExpr by replacing it with
an *ast.Ident named "var".

We also repair empty decls using a similar approach. This fixes cases
like:

var typeName string
type<> // want to complete to "typeName"

We also fix accidental keywords in selectors, such as:

foo.var<>

The parser produces a phantom "_" in place of the keyword, so we swap
it back for an *ast.Ident named "var".

In general, though, accidental keywords wreak havoc on the AST so we
can only do so much. There are still many cases where a keyword prefix
breaks completion. Perhaps in the future the parser can be
cursor/in-progress-edit aware and turn accidental keywords into
identifiers.

Fixes golang/go#34332.

PS I tweaked nodeContains() to include n.End() to fix a test failure
against tip related to a change to go/parser. When a syntax error is
present, an *ast.BlockStmt's End() is now set to the block's final
statement's End() (earlier than what it used to be). In order for the
cursor pos to test "inside" the block in this case I had to relax the
End() comparison.

Change-Id: Ib45952cf086cc974f1578298df3dd12829344faa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209438
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-03 04:30:02 +00:00
Rohan Challa
2b6af5f9ac internal/lsp: add nil check for control flow highlighting
Added a check to make sure that highlighting the control flow of
a function only continues if the cursor is actually in a function.

Change-Id: Idac90d9e55c09c3dcb9ae938585157658acc95e9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209581
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-02 20:31:27 +00:00
Heschi Kreinick
5a103c92be internal/imports: make ApplyFixes work despite syntax errors
ApplyFixes is only used by gopls, which cares a lot about files with syntax
errors, and not at all about files that aren't structurally valid. Use
the standard ParseFile function instead of goimports' weird one.

Adding a test is impractical because it seems to break type checking of
whatever package it's in.

Fixes golang/go#35915.

Change-Id: Iaf0e331978415428a422d942a1e0c5f6e66dc8a1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209579
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-02 20:30:33 +00:00
Rohan Challa
aa29eadba2 internal/lsp: add control flow highlighting for functions
When the cursor is on a return statement or in the function declaration
it will highlight the control flow for the function. It will also highlight
individual fields and results if the cursor is specifically in one.

Fixes #34496

Change-Id: I71d460cd174a8fbc61d119b9633c3c3ecbde2af9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208267
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-02 19:01:20 +00:00
Peter Weinberger
713d4893e8 internal/lsp/protocol: replace code for generating LSP types and stubs
The new code generates all 3 files (tsprotocol.go, tsserver.go, tsclient.go)
at once and tries not to generate unneeded types. This is the code that
generated the checked-in files currently being used (including CL208272
and 209219).
README.md has been modified correspondingly.

Change-Id: I719781a09f27bf0a426f8da3e45f7fa2eb0a7484
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208665
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-02 18:46:12 +00:00
Rebecca Stambler
ffc413ea38 internal/lsp: suppress all errors when a view is loaded and checked
We were previously returning errors when we failed to load/check a
user's workspace folder, but now we suppress all errors. We shouldn't
disable gopls functionality if something is broken in a user's workspace
folder, rather, we should fall back to the file= queries that will run
when a user edits a file.

Change-Id: Iae05174ca80d2573c0222ac42f29e5556bda0134
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209420
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-12-02 18:41:08 +00:00
Rebecca Stambler
a51b8faf84 internal/lsp: rename CheckPackageHandle to PackageHandle
Change-Id: I4ea5fed9fcb71b77da4a15c9d85792bda815ddf5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209419
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-12-02 18:29:46 +00:00
Jędrzej Szczepaniak
6e064ea0cf internal/lsp: link to the new pkg.go.dev instead of godoc.org
Updates golang/go#35563

Change-Id: I88ae3f742daf5043d4784fe8827454fb1ce1f9db
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209337
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-30 07:06:09 +00:00
Rebecca Stambler
ecd32218bd internal/lsp: make sure CodeAction.Command is a pointer
This is causing the "command '' not found" errors that we've been
seeing, specifically reported in microsoft/vscode-go#2920.

Also, fixed an issue with import organization in single-line files that
was caught as a result of this.

Change-Id: I2dfedb5d1b8dda976f356b0d6fcd146e53f1a650
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209219
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-27 20:10:27 +00:00
Peter Weinberger
c1736c0f0a lsp/protocol: make sure RenameProvider is an interface{}
CL 208272 made one occurrence of RenameProvider an interface{}.
This CL reflects the effect of making that change in the code
generator. (That is, the other occurrence of RenameProvider is now
an interface{} too.) gopls seems to still work, and all tests pass.

Change-Id: Icfc4a5639192c46b564509a601b8c03bbe2665a2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209158
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-27 17:13:10 +00:00
Ian Cottrell
99399511c1 internal/telemetry: lift the tests up to the request level
rather than testing events or metrics directly, we
test them in the context of a full message that would
get sent to the agent

Change-Id: I238a7f9ab7b1456d1b4b2bac2519d814928f2283
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209098
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-11-27 15:41:43 +00:00
Ian Cottrell
7360bd5c0f internal/telemtry: changed to a simpler threading model for stats
this is not a final solution, but it makes it easier to debug
and reason about, and does not require a go routine or buffered
channel

Change-Id: I758758ac80fcd525ab5264e34c48941766a8db11
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208664
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-11-26 22:52:16 +00:00
Ian Cottrell
9fe613bd66 internal/lsp: build the wire.Node lazily
this is needed to move to a model where we do not need to have
the wire form at all

Change-Id: I3b3693e027b568de4e8b4d10f7d5dd022a616e2e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208958
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-11-26 22:51:56 +00:00
Rebecca Stambler
69a79c76c7 internal/lsp: add some minimal validation for client capabilities
We've had a couple of breakages with changes to the protocol that are
bugs on our end. It's hard to review changes to the protocol, and it's
not reasonable to expect that we would remember the correct types for
everything, so we should have a test that validates some basic expectations
about the expected responses. We can add more here as issues come up.

Also, change RenameProvider back to an interface.

Updates golang/go#32703

Change-Id: Ic5f0b0ece40b05e4425cd98ab7bf18db3ad74601
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208272
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-11-26 21:34:59 +00:00
Rohan Challa
e13f15d1b9 internal/lsp: fixes premature return in find implementations
Find implementations sometimes returns no results, as it prematurely returns when it
finds an invalid object. Instead the behavior should be to check all the objects in case
a later object is a valid interface.

Fixes #35602

Change-Id: I0e3e2aa8d3afeaa34e392c2fe3ef8cdcd13b3d1e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208959
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-26 21:00:16 +00:00
Rohan Challa
af8577037c internal/lsp: remove duplicate implementations when finding implementations
Finding implementations adds the same implementation multiple times, this commit
removes the duplicates and ensures that only one instance of each implementation
gets returned. Also moves the sorting of results to the test file to ensure that
the tests are deterministic.

Fixes #35600

Change-Id: I244d36a46b7e31bf3c1f845e241239de05d45e6f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208668
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-26 20:43:40 +00:00
Francesco Renzi
20805546e7 tools/gopls: add cmd support for highlight
This change adds command line support for highlight.
Provided with an identifier position, it will display
the list of highlights for that within the same file.

Example:

$ gopls highlight ~/tmp/foo/main.go:3:9
$
$ 3:9-6:0
$ 10:22-11:32
$ 12:10-12:9
$ 12:20-30:0

Updates golang/go#32875

Change-Id: I5de73d9fbd9bcc59a3f62e7e9a1331bc3866bc75
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207291
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-26 20:36:08 +00:00
Ian Cottrell
fc82735a89 internal/telemetry: delay the conversion of metrics
convert to wire form only when we need to encode it

Change-Id: Ib36ee2fbef773241a30b9aa707ebf311119b8705
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208658
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Nathan Dias <nathan.dias@orijtech.com>
2019-11-26 18:15:43 +00:00
Rebecca Stambler
73cd2cc3b5 internal/lsp: don't run analyses on the entire view
Running staticcheck on the entire workspace causes a slowdown, and most
likely users don't want to see staticcheck reports for every
subdirectory of their workspace. Only run staticcheck on open files.

Also, fixed a staticcheck warning that showed up along the way. Filed
golang/go#35718 to remind ourselves to fix all of the staticcheck warnings
that showed up when we ran gopls with staticcheck on x/tools.

Finally, made sure that we don't send empty diagnostics when diagnosing
the snapshot on start-up, as that is not necessary.

Change-Id: Ic51d1abfc80b1b53397057f06a4cfd7e2dc930f9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208098
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-11-25 22:48:44 +00:00
Heschi Kreinick
9f1eb44090 internal/lsp/source: fix crash on short file
The import formatting code tries to extend the range it's diffing to
the next line after the last import so that it's working with whole
lines. Make sure that the next line actually exists before trying to use
it.

Fixes golang/go#35604.

Change-Id: I18fe61843aa11e62ed311a9ddff62ff876888a15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208672
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Muir Manders <muir@mnd.rs>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-25 22:36:40 +00:00
Heschi Kreinick
efa866333f internal/lsp/tests: skip cgo tests when not supported
I really should have read the trybot results... :(

Change-Id: If2f5d1b8078827efb0cd8ea9165941864bb94d3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208669
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-25 21:54:41 +00:00
Rohan Challa
73db347c3b internal/lsp: do not return interface itself when finding implementations
Finding implementations of an interface should not give the interface itself
as an implementation.

Fixes #35601

Change-Id: Id3352619ece90fb7ca906ddabca613742d156c76
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208667
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-25 20:50:44 +00:00
Heschi Kreinick
66af5afb16 internal/lsp/source: give more imports names
Expose ImportPathToAssumedName (internally) and use it in an LSP
completion case that doesn't go through the usual imports code.

Fixes golang/go#35401.

Change-Id: If87912072e11e22c542f7474841e53467a33ef2b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206890
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-25 20:50:14 +00:00
Jędrzej Szczepaniak
59b2cd78f8 tools/gopls: add cmd support for implementation
This change adds command line support for implementation.

Example:

$ gopls implementation ~/tmp/foo/main.go:8:6
$ gopls implementation ~/tmp/foo/main.go:#53

Updates golang/go#32875

Change-Id: I3aa89a788ded886368b07c1824325069f3cba88a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208357
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-25 20:27:09 +00:00
Rebecca Stambler
b99b2d090f internal/lsp: fix return variables for FindPosInPackage
Change-Id: Icaa9595f05ab9583e60fc0392cbe21e1f20a3934
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208666
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-11-25 19:51:13 +00:00
Rebecca Stambler
d7101b74a4 internal/lsp: set version correctly after textDocument/didOpen
The early return logic for didOpen events in
(*snapshot).invalidateContent was preventing the creation of a new
snapshot, which was in turn stopping the versions from being updated.

This exposed a fundamental issue in the way we were calculating
workspace diagnostics. Since we weren't waiting for diagnostics to be
completed for an entire snapshot before replying that the server had
been initialized, snapshots were being cloned without any type
information. For quickfix code actions, we assume that we have all
information cached (since we need to have sent the diagnostics that the
quickfix is mapped to), so we were not finding the cached analysis
results.

To handle this in the short-term, we key analyses by their names, and
then regenerate results as-needed for code actions. This is technically
more correct than simply assuming that we have the analyses cached. In a
follow-up CL, I will send a follow-up that will make sure that
snapshots "wait" on each other to be fully constructed before being
cloned.

Change-Id: Ie89fcdb438b6b8b675f87335561bf47b768641ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208265
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-11-25 19:35:51 +00:00
Heschi Kreinick
05c67e95c4 internal/lsp: add tests for cgo package users
We now have pretty good support for users of cgo packages. Add tests.

Closes golang/go#35720.

Change-Id: Icdc596038bc6fca1c08eacd199def12264cf512d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208503
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-25 19:20:57 +00:00
Heschi Kreinick
ef6787d357 internal/lsp: track and parse non-compiled go files
When packages.Load'ing cgo packages, the authored files show up in
GoFiles, and the generated files show up in CompiledGoFiles. We need the
AST and type information for the latter, since they're the only thing we
can type check. But we also need the contents (and column mapper) for
the authored file so that we can navigate into it.

Store GoFiles in package metadata and checked Packages. Parse the extra
files, just for their mappers. Refactor the View functions a little bit,
since there's only one place that actually needs to find the mapper for
a file.

Updates golang/go#35720.

Change-Id: I9f96872a9a592bf0e11da27ebd8976c6db8752c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208502
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-25 19:20:50 +00:00
Heschi Kreinick
761dbfd69d internal/span: support line directives
When //line directives are in play, the ast.File's Offset function will
return offsets in the generated file. We want offsets in the authored
file, so we need to pass a Converter for the authored file, in addition
to the ast.File for the generated file. For the same reason, we have to
start (Range).Span() by translating into positions in the authored file,
then calculate offsets from that.

A lot of call sites outside of the LSP don't pass the Converter, but
they probably don't matter much. I think everything inside does because
it ends up using mappedRange.

Updates golang/go#35720.

Change-Id: I7be09b3a50720b078e862d48cfdb02208f8187ae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208501
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-25 19:20:43 +00:00
Rohan Challa
acc15743c3 internal/lsp: add documentation for package-level vars
Adds documentation on hover for package-level variables and constants.

Fixes #33793

Change-Id: I01b9d36b0551f246d2ad6056806db18bdd7adb5e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208662
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-25 18:28:23 +00:00
Muir Manders
a99e43fcff internal/lsp: fix literal completions in variadic params
In cases like:

var foo []bytes.Buffer
foo = append(foo, <>)

you will now get a literal candidate "bytes.Buffer{}". Previously we
were skipping all literal candidates at the variadic position, but the
intention was to only skip literal slice candidates (i.e.
"[]bytes.Buffer{}" in the above example).

I also improved the literal struct snippet to not leave the cursor
inside the curlies when the struct type has no accessible fields.
Previously it was only checking if the struct had no fields at all.
This means after completing in the above example you will end up with
"bytes.Buffer{}<>" instead of "bytes.Buffer{<>}", where "<>" denotes
the cursor.

Change-Id: Ic2604a4ea65d84ad855ad6e6d98b8ab76eb08d77
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207537
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-25 18:03:14 +00:00
Rebecca Stambler
a911d9008d internal/lsp: only search for references in reverse dependencies
Updates golang/go#35597

Change-Id: I78e83ad0ee1ae3c59a7452c467b3abd34587a845
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208657
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-11-25 14:46:06 +00:00
Ian Cottrell
89d49d945a internal/telemetry: make the metrics tests external
This is the same changes we already made to the trace tests, where we check the
encoded json instead of the wire structs, and we make the tests external using
the public encoding function only

Change-Id: I289d46dd5ad0efe0b2fba0a71b188b4f9edc5676
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208504
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-11-25 14:11:28 +00:00
Rebecca Stambler
cc15fab314 internal/lsp: use AST to construct placeholders
Type aliases don't work well with types.TypeString. Work around that by
using the AST to build this information. Follow up from CL 201677.

Fixes golang/go#33500

Change-Id: I8b2d4ea238eb5d284a419f2b0bbf9655e69d434d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208497
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-11-25 01:11:57 +00:00
Ian Cottrell
f5828fc9a1 internal/telemetry: merge the metrics tests
This merges all the metrics tests into something that converts top level metrics
only, and relies on that to cover all the lower level functions

This is in preparation for moving the tests to be external without exposing all
those functions.

Change-Id: Iecce1ddc522db9fc926817e4e748d718cbc740a9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208499
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-11-24 02:19:06 +00:00
Ian Cottrell
2a6ccf25d7 internal/telemetry: compare the compact JSON
It is sufficient to just compact the JSON to compare it rather than
bothering to decode it.

Change-Id: Ied39d462eec77623187422a9c58f83f8d1630269
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208498
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-11-22 23:29:04 +00:00
Rebecca Stambler
c02aa52d2b internal/lsp: handle first change behavior on the server side
I'm not sure why this was being managed by the view, but delete the code
that handles tracking a file's first change. It is only used to avoid
spamming the user with error messages.

Change-Id: Id95089478ffb7e189d38cbc147e3dde6a1c55c5e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208274
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-22 18:53:53 +00:00
Rebecca Stambler
2189885de9 internal/lsp/cache: disable analysis on dependencies (temporarily)
Right now, we request analyses for files in ParseExported mode, which
doesn't actually produce any meaningful facts. Disable it until we
resolve golang/go#35089, since right now, all this is doing is wasting
memory and CPU.

Change-Id: I6ffb7bdf6c915159b55753b51289cef4bd937603
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208270
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-11-22 18:46:19 +00:00
Muir Manders
035a8167be internal/lsp: improve completion ordering workaround
Instead of making all completion candidates look like perfect matches
to VSCode, we now make all candidates match exactly like the first
candidate. This still causes VSCode to maintain the ordering from
gopls, but it fixes the absolute match score of gopls's top
candidates. This fixes interplay with other sources of VSCode
completions, such as user defined snippets.

Fixes golang/go#35782.

Change-Id: Ie7e489b76a02fb1353b63fa3c6fa42afee2e1441
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208439
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-22 18:27:03 +00:00
Ian Cottrell
0ae87fff1b internal/lsp: fix a race in the command line tests
except the race was a symptom of a larger problem, so the fix
actually invovles cleaning up the way we run command line tests
totally to have common shared infrastructure, and also to clean up
the way we handle errors and paths into the temporary directory

Fixes: golang/go#35436
Change-Id: I4c5602607bb70e082056132baa3d4b0f8df6b13b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208269
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-22 16:15:56 +00:00
Nathan Dias
f774e2e2e5 internal/telemetry/export/ocagent: update usages of BucketOptions to use pointers
This change updates initializations of DistributionValue to pass in a pointer for
BucketOptions rather than a value so that the custom MarshalJSON for
*BucketOptionsExplicit will be called when marshalling distributions.

Updates golang/go#33819

Change-Id: I6d1a393dfa67d626bf5cdd2cfbc0c931d376f60c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208401
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-22 08:00:28 +00:00
Nathan Dias
df8e87c2ce internal/telemetry/export/ocagent: add tutorial for exporting metrics
This change adds a README that describes how to export metrics from
Go tools to Prometheus via OpenCensus.

Updates golang/go#33819

Change-Id: Ic417b539fd5ef95fee642321bd30997146cbedb3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208400
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-11-22 07:16:40 +00:00
Nathan Dias
2d3bb8ce05 internal/telemetry/export/ocagent: correctly JSON marshal BucketOptionsExplicit
This change adds a custom MarshalJSON method to BucketOptionsExplicit for
marshalling parity with protobuf/jsonpb. This allows the OpenCensus service
to correctly decode a distribution's BucketOptions.

Updates golang/go#33819

Change-Id: Ia9dc868e1cbfc32a956f6a276dfd1591f7d4d31a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208398
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-22 06:42:13 +00:00
Rebecca Stambler
f191eec953 internal/lsp: use snapshot to get reverse dependencies
This change modifies the behavior of the GetReverseDependencies function
used for diagnostics. Since we now return diagnostics for the entire
workspace, we don't have to worry if a file is open to show errors in
it. This change requires the addition of a new (*snapshot).PackageHandle
function that gets a CheckPackageHandle for a given package ID. This
function does not cause a re-load of the package metadata, though if we
feel that this is something we need in the future we can add it.

Change-Id: I863bdf284d15f2317d8fae395928a90b9455146b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208102
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-11-22 02:13:35 +00:00
Rebecca Stambler
004141db30 internal/lsp: delete the source.Diagnostic.File field
Since diagnostics are published with the URI separately, there's no need
for us to keep the FileIdentity around in two places.

Change-Id: I5724b9582e5eee49f66fcf9f08625f14a69e3fc0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208263
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-11-22 00:05:30 +00:00
Rohan Challa
66c5a5ad76 internal/lsp: add control flow highlighting inside for loops
When the cursor is on a "for" statement or on any branch statement inside
the for loop. It will highlight the control flow inside the for loop.

Updates #34496

Change-Id: Idef14e3c89bc161d305d4a49fd784095a93bbc03
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208337
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-21 21:43:27 +00:00