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

5845 Коммитов

Автор SHA1 Сообщение Дата
Rob Findley 7b9993c5d2 internal/lsp/cmd: add a command-line command to start daemon debugging
Rename the 'inspect' command to 'remote', since it makes more sense for
the command to be scoped to interactions with the gopls remote. Add a
new subcommand 'debug' to start the debug server. Leave an aliased
'inspect' command for now. I'm 99% sure nobody is using it, so we can
remove the alias in a month.

Move some things around in the lsprpc package to improve factoring a
bit.

Fixes golang/go#45518

Change-Id: Ic6d64204611552e593dcbc1b5a347ccd27a4f40c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/309810
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-27 13:49:53 +00:00
pjw fe1c5480f5 gopls/test: it is safe to ignore json unmarshalling errors
This test checks that if a single value in the Initialize message
changes, the resulting unmarshalled struct changes in no more than
one place. The implication is that ignoring UnmarshalTypeErrors
in LSP processing is safer than causing a fatal error, which is the
current state.

Change-Id: I64bbf6f785c32fa7483966a117ac3b6f11d573be
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310109
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-27 12:58:28 +00:00
Rebecca Stambler 735ed62f40 gopls: tidy module
Change-Id: Id46de70e0ca1670cb2ba0cd0961b49896e5384fd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313929
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-27 04:02:17 +00:00
Rob Findley e3dc99f812 cmd/guru: update referrers-json testdata to reflect new line numbering
CL 313251 fixed the describe test, but inadvertently broke the referrers
test due to changing line numbers in describe/main.go. This CL amends
those line numbers.

Fixes golang/go#45778

Change-Id: I1dbdd9157091e061bfa35ec0b5c4690aa09ae092
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313669
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-04-26 20:11:56 +00:00
Rob Findley 3f1e7240c0 cmd/guru: remove test assertions involving unsafe to fix the build
Go 1.17 adds the unsafe.Add and unsafe.Slice functions, which causes the
guru describe assertions about unsafe to either fail at 1.17 or fail at
earlier Go versions.

This is causing the longtest builds to break.

Remove them for now. If we remember, we can add them back once we no
longer support 1.16.

Fixes golang/go#45778

Change-Id: Ie72355fbab8e614c0150097c84c796e78d968839
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313251
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-26 17:08:16 +00:00
Anton Kuklin cf354b66fd internal/lsp/cache: improve snapshot clone perfomance
The existing implementation uses a lot of URI.Filename() calls,
which are pretty expensive. Moreover, these calls are not necessary,
as long as all the actions could be done with the raw URI string.
This patch removes such calls and uses simple string casts.

Updates golang/go#45686

Change-Id: Ibe11735969eaf0cfe33024f08418e14bf71e7fc4
GitHub-Last-Rev: 67a3ccdf30
GitHub-Pull-Request: golang/tools#306
Reviewed-on: https://go-review.googlesource.com/c/tools/+/312809
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-26 16:33:32 +00:00
Hossein Zolfi 7657be6ecf gopls/doc: fix broken link
Change-Id: I051824d44b12bbdb3bff41ff97d8583d841810e2
GitHub-Last-Rev: 7fb731de22
GitHub-Pull-Request: golang/tools#314
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313096
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-26 16:33:22 +00:00
Rob Findley 7c93484b9a internal/lsp: add a command to start the debug server
The utility of the debug server is limited by the requirement to start
gopls with the `-debug` flag and then look in the logs to see which port
the debug server is bound to.

This CL adds a new custom command `gopls.startDebugging` to start the
debug server on demand if it isn't already running, and return its debug
address. It also does some gymnastics to make this turn on debugging for
any intermediate gopls forwarders, when using daemon mode.

For golang/go#45518

Change-Id: I48a90088f96aca54f34f93bedbfe864515320f61
Reviewed-on: https://go-review.googlesource.com/c/tools/+/309409
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-26 15:43:18 +00:00
Muir Manders 716a04c652 lsp/completion: fix postfix completions preceding assignments
In cases like:

  foo.<>
  bar = 123

We weren't detecting that the selector preceding <> was a statement.
The above is parsed as "foo.<>bar = 123", so it looks like <> is
contained in an AssignStmt. This matters because we give different
postfix completions depending on whether it is valid to replace the
surrounding selector with a statement or not.

Updates golang/go#45718.

Change-Id: I8f74505b2c8c7060f1e94433904ff0a987d0cc57
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313269
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
2021-04-26 15:26:58 +00:00
William Langford f74a6698e3 internal/lsp/cache: preallocate internal maps when cloning snapshots
For large codebases, the cost of copying these maps can be fairly high,
especially when it needs to repeatedly grow the map's underlying storage.
Preallocate these to the size of the original snapshot maps to prevent
the need to grow the storage during the clone.

Updates golang/go#45686

Change-Id: I4cfcd5b7cba8110e4f7e706fd9ea968aaeb6ff0c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/312689
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-23 21:15:18 +00:00
Heschi Kreinick e435455aa1 internal/lsp: introduce MemoryMode
We still hear from users for whom gopls uses too much memory. My efforts
to reduce memory usage while maintaining functionality are proving
fruitless, so perhaps it's time to accept some functionality loss.

DegradeClosed MemoryMode typechecks all packages in ParseExported mode
unless they have a file open. This should dramatically reduce memory
usage in monorepo-style scenarious, where a ton of packages are in the
workspace and the user might plausibly want to edit any of them.
(Otherwise they should consider using directory filters.)

The cost is that features that work across multiple packages...won't.
Find references, for example, will only find uses in open packages or in
the exported declarations of closed packages.

The current implementation is a bit leaky; we keep the ParseFull
packages in memory even once all their files are closed. This is related
to a general failure on our part to drop unused packages from the
snapshot, so I'm not going to try to fix it here.

Updates golang/go#45457, golang/go#45363.

Change-Id: I38b2aeeff81a1118024aed16a3b75e18f17893e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310170
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-23 19:11:18 +00:00
Heschi Kreinick f7e8e24497 internal/lsp: support Check For Upgrades in vendor mode
Essentially the same bug, and fix, as golang/go#38711.

Fixes golang/go#44756.

Change-Id: Ib4aaa73c2036e23f7afd7e48b685096039759ef9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/311909
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-23 17:35:25 +00:00
Paul Jolly a8e7c0c9c2 internal/lsp: move gopls/internal/regtest -> internal/lsp/regtest
Note: this only moves the regtest framework, not the gopls regtest
tests.

Change-Id: Ia70d2e97df8a8bd48a042e5b037c1e56a210b594
Reviewed-on: https://go-review.googlesource.com/c/tools/+/312412
Trust: Paul Jolly <paul@myitcv.org.uk>
Run-TryBot: Paul Jolly <paul@myitcv.org.uk>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-23 16:19:37 +00:00
AGMETEOR f946a157ee passes/sigchanyzer: allow valid inlined unbuffered signal channel
Permit signal.Notify(make(chan os.Signal)) which is valid code,
given that the channel isn't read elsewhere, the fact that signals
can be lost is unimportant.

Updates golang/go#45043

Change-Id: Ie984dfeedbb4e1e33a29391c3abb1fc83299fed3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/311729
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-22 17:05:18 +00:00
Muir Manders 4934781c1f lsp/completion: offer candidates converting arrays to slices
For example:

    var b [4]byte
    var s []byte = <>

At <> we now prefer "b" and insert as "b[:]".

Fixes golang/go#40277.

Change-Id: I5fe9d153813dac7218edf31c7c33610130eef9bc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/311169
Run-TryBot: Muir Manders <muir@mnd.rs>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-04-22 04:15:51 +00:00
Rob Findley b3e5b99972 internal/lsp: update unsafe completion test for upcoming spec changes
With unsafe.Slice about to be added, we'll get varying completions at
'unsafe.S_' depending on the Go version. Change the completion position
to be 'unsafe.Si_'.

Change-Id: Ib537fefceda7864b7a256565a3a7286d18e845c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/312470
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-22 02:57:26 +00:00
pjw e74674aed1 internal/lsp/protocol: latest version of LSP
Includes some proposed 3.17.0 changes to the LSP:
1. CompletionItemLableDetails
2. New diagnostics requests. (the existing ones are notifications):
textDocument/diagnostic, workspace/diagnostic, workspace/diagnostic/refresh.

Change-Id: I534c56526fb0dc3f09e5dc21dce3c2e894d93116
Reviewed-on: https://go-review.googlesource.com/c/tools/+/311769
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-20 19:23:16 +00:00
pjw dbc8747628 internal/lsp/semantic: avoid doing semantic tokens for large files
LSP (and gopls) support both full-file semantic token requests and
requests for just a range, typically roughly what's visible to the user.
It can be slow to produce the full set for a very large file, so
this code now responds with an error if the file is bigger than
100,000 bytes. After getting this error, vscode, at least,
will stop asking for full requests and use range requests.

Alternatively, server capabilities could say gopls never responds to
full-file requests, but doing that doesn't stop vscode from asking for
them. Another possibility would be to fix a time limit (like 8ms) for
how long to spend generating full-file semantic tokens. That's tricky
to get right, but one could instead generate an error when there
are more than 4,000 semantic tokens (on my laptop, that's about 8ms.)

Large files are unusual; a simple size limit seems adequate for now.

Change-Id: Ieea0d16aad6e37cc4f14b1a6a7116a4e41197aae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/307729
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-20 17:53:17 +00:00
Muir Manders a13dbf1ae0 lsp/completion: omit deep completions into unimported package names
Don't offer deep completions when completing the name of unimported
packages.

For example:

    var _ int = <>

Completing at <> previously would offer an eclectic array of
candidates such as "bits.LeadingZeros()", "time.Now().Day()", or
"zlib.BestCompression", depending on your luck. These candidates stem
from unimported packages candidates such as "bits" which we continue
searching into for deep candidates.

There are two main reasons these deep completions are not useful:
1. They are not dependable. Not all unimported packages are even
   searched (it stops as soon as it finds a set number).
2. Fuzzy matching does not work (e.g. typing "bilz" will not filter to
   "bits.LeadingZeros" as it does in other cases).

2) could be remedied, but there are so many unimported
package members that I'm not sure it is possible to reduce false
positive deep completions to a satisfactory level.

I also made a couple relevant minor tweaks:
- Fallback sort the unimported packages by path to keep a consistent
  order.
- Don't offer unimported packages at all if there is no prefix.

Updates golang/go#43374.

Change-Id: I9fbcde34a3a9e7781568515bddab9da2fc931139
Reviewed-on: https://go-review.googlesource.com/c/tools/+/311069
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-20 15:21:37 +00:00
Heschi Kreinick 10909d8c27 internal/lsp/cache: remove type info trimming
This broke staticcheck and x/tools/refactor, most notably used for our
rename support. Doesn't look like a winner. Roll it back :(

Updates golang/go#45457.

Change-Id: I30d5aa160fd9319329d36b2a534ee3c756090726
Reviewed-on: https://go-review.googlesource.com/c/tools/+/311549
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2021-04-19 19:59:27 +00:00
Heschi Kreinick 1dce19db54 internal/lsp/cache: don't trim types.Info with staticcheck enabled
As predicted in CL 308730, there are some analyzers that need this: all
of staticcheck. (I probably should've seen that coming.) For now, don't
do the trimming when staticcheck is on. Since staticcheck ~doubles
memory footprint, those users probably don't care much.

Change-Id: I7cfd96b3654e3617d28d62015928a45a85407d13
Reviewed-on: https://go-review.googlesource.com/c/tools/+/311376
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-19 17:36:27 +00:00
Heschi Kreinick 07295caad0 internal/lsp/cache: prune types.Info entries in slice literals
The type checker emits a TypeAndValue entry for (among other things)
every constant in a Go file. Normally, that cost is moderate. However,
in the case of a large slice literal, it can get out of control very
quickly. Imagine a code generator that creates a 2KB byte slice literal;
that's 2K TypeAndValue entries, each of which is considerably larger
than the 1-3 bytes for the source text.

Unfortunately, there are a number of such code generators. Notably,
there are such slice literals in proto code, e.g.
https://github.com/grpc/grpc-go/blob/master/examples/route_guide/routeguide/route_guide.pb.go#L360

This CL changes the type checking code to remove the TypeAndValue
entries for slice literals of basic types after the checker returns.
In the extreme case of https://github.com/googleapis/go-genproto, which
is nothing but protos, I see a ~40% drop in heap usage.

I believe this change is generally safe, but there's no way to guarantee
it. I don't think any editor features need to know the type or value of
an arbitrary slice element, but it is just barely possible that an
analyzer does.

Change-Id: Iee1af2369f994597a42fd1dcbf8af20faa43410e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/308730
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-16 22:42:28 +00:00
Peter Weinbergr 1a0c6081c5 internal/lsp/protocol/typescript: update documentation and generated code
Modifies README.md to be clearer about the necessary version of the
typescript compiler. Adds generated code that allows unmarshalling
type errors on Initialize messages.

See https://go-review.googlesource.com/c/tools/+/310109
Fixes  golang/go#35316

Change-Id: Id128c23e807e67e02d1354edaa0b164c9d36101c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310753
Trust: Peter Weinberger <pjw@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-16 22:07:20 +00:00
Shoshin Nikita fe5037164a internal/lsp/source: fix Deref function for cyclic types
The previous fix (d1362d7) is not sufficient for all cyclic types.
This change updates Deref function to support more complex cases.
We use a map with underlying types to detect cycles.

Fixes golang/go#45510

Change-Id: I28f655a9c1d4f363cb7ae3f47db3e8567fe6e80a
GitHub-Last-Rev: 4c898741c0
GitHub-Pull-Request: golang/tools#305
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310311
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-16 18:23:08 +00:00
Rob Findley cb5dc85ca1 internal/lsp/cache: add a scheme for types error code links
Links in the new LSP diagnostic CodeDescription for go/types errors are
missing a scheme (unclear why they work in some clients). Fix this by
delegating to the existing source.BuildLink helper (this also adds the
utm_source query parameter for pkg.go.dev).

Fixes golang/go#44360

Change-Id: Ife8969f32bb11840c0fdd31765b6051b3d997a93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/293509
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-15 23:21:34 +00:00
Shoshin Nikita 799b6824f9 gopls/internal/hooks: respect the default checks of the staticcheck tool
Disable non-default checks by default. Also, update the regression
test because the previous version used a non-default check (ST1022).

Fixes golang/go#44712

Change-Id: I825cac8387b33307e529fc27ca2f54c2d0d50cc7
GitHub-Last-Rev: 3ad413a50d
GitHub-Pull-Request: golang/tools#303
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310449
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-15 21:16:26 +00:00
Shoshin Nikita d1362d7aca internal/lsp/source: fix an infinite loop in Deref function
Return a pointer type if the type refers to itself (for example, type a *a).

Fixes golang/go#45510

Change-Id: Ifaf9c0fe9df8a1cab300479394a7127dfb820a88
GitHub-Last-Rev: 0098023416
GitHub-Pull-Request: golang/tools#302
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310050
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-14 19:50:58 +00:00
Shoshin Nikita 59a2b45a1d internal/lsp/source: update process of hover signature creation for type declarations
Always use (*ast.TypeSpec).Type as a HoverInformation source.
Store a type name and an indication of whether it's a type alias
declaration as fields of HoverInformation.

Fixes golang/go#45261

Change-Id: Ifbcdc15990379d0c73a419dd6cdf175d53dce925
GitHub-Last-Rev: 556dc94ab7
GitHub-Pull-Request: golang/tools#293
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305189
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-14 19:20:17 +00:00
Sergey Kacheev 2140ccea5d fix the argument of the goimports example
After the last code correction, the name of the argument is different from the name used in the code.
Was "timeoutms" became "timeout_ms"

Change-Id: Id2c94b9a39ea162a9102e20e33b5ffcd019c5225
GitHub-Last-Rev: 4a2d3c8c6d
GitHub-Pull-Request: golang/tools#301
Reviewed-on: https://go-review.googlesource.com/c/tools/+/309229
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-12 17:45:26 +00:00
Rebecca Stambler ec686a2a72 all: upgrade all dependencies except for go-diff
https://github.com/sergi/go-diff/issues/115 prevents us from upgrading
go-diff in gopls.

Change-Id: I19aa01aa201b894a537480500ea435f2951a3082
Reviewed-on: https://go-review.googlesource.com/c/tools/+/308829
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-09 16:31:56 +00:00
Rebecca Stambler 0243799cfe gopls/internal/coverage: apply gofmt to the build tag syntax
Change-Id: I947cf23cdf1c7968cfacb9a97d374f06a51f9adb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/308491
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2021-04-08 20:55:59 +00:00
Heschi Kreinick be791d07ff internal/lsp/source: small fixes to directory filters
Add missing newlines in documentation, and allow trailing slashes in the
filter expressions.

Change-Id: I90106b209222d8cc542e3517c6ff6edb2569243d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/308453
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-08 19:22:05 +00:00
Keith Randall b261fe9609 go/tools: add vet check for direct comparion of reflect.Values
Comparing reflect.Values directly is almost certainly not what you want.
That compares reflect's internal representation, not the underlying
value it represents. One compares reflect.Values correctly by comparing
the results of .Interface() calls.

Fixes golang/go#43993
Update golang/go#18871

Change-Id: I6f441d920a5089bd346e5431032780403cefca76
Reviewed-on: https://go-review.googlesource.com/c/tools/+/308209
Trust: Keith Randall <khr@golang.org>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Keith Randall <khr@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2021-04-08 02:08:45 +00:00
Rebecca Stambler e78b40c7d0 internal/lsp: switch to 'go get -u ./...' for transitive upgrades
'go get -u all' works for this in Go 1.16, but in earlier versions,
we need 'go get -u ./...'. Also, include the -d and -t flags to avoid
building binaries and to upgrade test dependencies.

Fixes golang/go#45262

Change-Id: I8b04783ffcd53e8066c5a25fef72d91ae975f5a2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/307889
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-04-07 17:38:53 +00:00
pjw 3ac76b8bb7 gopls/internal/coverage: better error messages and output
First test that it's being run from the tools module's root, and then
that the directory structure is ok.

Fix the formatting of verbose output.

Change-Id: Icd27fb24277ca80069da12825ea60fc30ff399b8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/307269
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-07 10:44:45 +00:00
Steeve Morin c602466154 Revert "internal/lsp/cache: disable GOPACKAGESDRIVER"
Now that https://github.com/bazelbuild/rules_go has a working prototype of a `GOPACKAGESDRIVER`, it may be time to revert that commit.

The draft implementation is at https://github.com/bazelbuild/rules_go/pull/2858.

Change-Id: Ia738e8be448d936f8a3b2b421d0a765f94bbff52
GitHub-Last-Rev: 0df6c91074
GitHub-Pull-Request: golang/tools#297
Reviewed-on: https://go-review.googlesource.com/c/tools/+/307169
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-06 19:05:28 +00:00
Rob Findley 35a9159336 go/internal/gcimporter: ensure that imported floats are of float kind
As of CL 290630, go/types enforces some bitsize limits on integer const
values. We need to be careful to preserve the constant Kind when
importing from gc export data.

Ideally we could follow CL 288632, but the go/constant APIs used in that
CL are not available to x/tools, which (at least for the moment) must
still build at go1.12. Instead, simply call constant.ToFloat to force
the Kind.

Add a test for the imported Kind. This test should probably also be
upstreamed to std/go/internal/gcimporter, now that go/types relies on
this behavior.

Change-Id: I84b4b15b398962305aa6e3e9e12ede6a7373230b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/307590
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-04-06 13:38:10 +00:00
Rob Findley 5d334387e1 go/internal/gcimporter: merge go1.11 tests back into gcimporter_test.go
The go1.11 build constraint has been removed from gcimporter11_test.go,
so it no longer needs to be a separate file.

Change-Id: I84d498b0dd637e4436ec497be81d2866a5acee31
Reviewed-on: https://go-review.googlesource.com/c/tools/+/307589
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-04-06 04:24:37 +00:00
Shoshin Nikita 11c3f835bb internal/lsp/source: fix Highlight for std and 3rd-party packages
Don't use GetParsedFile because it extracts a package with
TypecheckWorkspace mode, but we want to support std and
3rd-party packages. So, we reuse the content of GetParsedFile
directly in Highlight function with TypecheckFull mode.

Fixes golang/go#43511

Change-Id: Ibd1d42e28a6739ba011113df0e6e7e98d1b86eb5
GitHub-Last-Rev: 3746092210
GitHub-Pull-Request: golang/tools#298
Reviewed-on: https://go-review.googlesource.com/c/tools/+/307171
Trust: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-05 22:17:18 +00:00
Rebecca Stambler 8c34cc9caf internal/lsp/cache: fix race condition in snapshot's initializedErr
Use the snapshot's mutex to guard the initialize error. See the race
here: https://storage.googleapis.com/go-build-log/bb2fc21c/linux-amd64-race_8a495dc7.log.
Change-Id: I81628b19430fee318cd506ed86d12c6c007e71d1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305789
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-03-30 23:33:37 +00:00
Rob Findley 0deaffd200 gopls/internal/regtest: re-enable the gc_details regtest for -short
My hope is that CL 304169 resolved this flake, but we'll have to see.

For golang/go#44099

Change-Id: Iac82dc24167daacd0361eac1a5567048a7ecf11c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305409
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-03-30 20:26:08 +00:00
Shoshin Nikita af36406620 internal/lsp/source: respond with the underlying type to Type Definition requests for composite types
Go to Type Definition works for all composite types except maps because
it is not clear which type to return if both key and value are named types.

Fixes golang/go#45029

Change-Id: Ie14f333c51af11033e2494aaaac367d35e7dc87b
GitHub-Last-Rev: 94a04812ea
GitHub-Pull-Request: golang/tools#292
Reviewed-on: https://go-review.googlesource.com/c/tools/+/304789
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-30 19:14:42 +00:00
Dmitri Shuralyov 682c7e60bf godoc/static: link to golang.org for content moved out of Go root
More of the golang.org website content has moved from the Go tree to
the x/website repository in CL 291711, resulting in broken links or
otherwise missing resources in godoc. None of it is affecting godoc's
core functionality, but it's good to fix broken links, so link to the
resources served by golang.org for now.

If it becomes important to make these resources available while godoc
is running offline, that can be done later. (It will be easier once
we can start relying on //go:embed for all supported Go versions.)

Include a local copy of a favicon.ico since the one in Go root is no
longer there as of CL 300549.

For golang/go#32011.

Change-Id: If5bd8e61b72dd9ca1db469d9121e43742846c115
Reviewed-on: https://go-review.googlesource.com/c/tools/+/300394
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Agniva De Sarker <agniva.quicksilver@gmail.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
2021-03-30 17:48:30 +00:00
pjw ca627f833c internal/lsp/semantic: fix some type definitions
xyz and err in
type A func(xyz int) (err error), or
type B struct{xyz int}
were incorrectly marked as types, when they are not.

These are now marked as variables (although the choice is somewhat
arbitrary for A).

Fixes golang/go#45233

Change-Id: I2df4eab7606c356f30bf3337c12d9190e74bc392
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305209
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2021-03-30 15:15:52 +00:00
pjw 0459589001 internal/lsp/protocol/typescript: small cleanups and add tsconfig.json
It would be nice if tsc -script code.ts util.ts ran without errors,
but it doesn't. tsconfig.json documents which strict setting work and
which ones don't. code.ts and util.ts have some small typescript improvements
and running them has changed slightly, as documented in README.md.

Change-Id: Idee4934bede900df2f64165359e17a42d695f518
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305210
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2021-03-30 15:02:49 +00:00
Ian Cottrell b0e994dcc9 internal/jsonrpc2_v2: move the idle timeout handling out of the server
Change-Id: Ia7dedd84171f4fc4818fb00b154c21b04887391f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305129
Trust: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-30 14:25:40 +00:00
Rebecca Stambler 955357534d internal/lsp: remove unnecessary call to WorkspacePackages in mod tidy
Change-Id: I85ecae0af7176f35ffbc4a916d656ac28deaba35
Reviewed-on: https://go-review.googlesource.com/c/tools/+/303210
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-03-30 04:13:47 +00:00
Shoshin Nikita 769264cf08 internal/lsp/source: fix docs for fields of anonymous structs/interfaces
There are 2 different anonymous struct declarations that require
different approaches:

1. var x struct{...}
2. x := struct{...}{}

For the first one we can use the existing solution with a minor update.
However, it returns the wrong docs for the fields of nested structs.
To fix this we need to visit all fields recursively.

The second one is not a generic declaration. So, the simplest solution
is to use the method Snapshot.PosToField.

Fixes golang/go#43675

Change-Id: I46685e7985cbf2c1c5b1b74ef3cd3a70b920feba
GitHub-Last-Rev: 8a5704c2ec
GitHub-Pull-Request: golang/tools#284
Reviewed-on: https://go-review.googlesource.com/c/tools/+/300029
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-30 03:09:04 +00:00
Shoshin Nikita cb7d59931e internal/lsp/source: skip blank identifiers during the function extraction
The blank identifier is always a local variable. It can't be
a function parameter or a return value.

Fixes golang/go#44813

Change-Id: Ieca9da35aaa9f5826ab89ded73702bed952e1226
GitHub-Last-Rev: bb7a2353ab
GitHub-Pull-Request: golang/tools#294
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305429
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-29 19:56:10 +00:00
Muir Manders 94a19427f1 internal/lsp/completion: move postfix completions behind option
Move postfix completion functionality behind an experimental option
flag. For now users can enable it by setting
"experimentalPostfixCompletions" or "allExperiments".

I added a RunnerOption so regtest tests can tweak *source.Options. I
didn't refactor the "Experimental" mode to use the new RunnerOption
because I didn't fully understand its purpose.

Change-Id: I75ed748710cae7fa99f4ea6ea117ce245a4e9749
Reviewed-on: https://go-review.googlesource.com/c/tools/+/296109
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-29 18:55:49 +00:00