1
0
mirror of https://github.com/golang/go synced 2024-10-01 04:08:32 -06:00
Commit Graph

4410 Commits

Author SHA1 Message Date
Rebecca Stambler
55b11c713e internal/lsp: clear diagnostics for deleted files
Diagnostics should be cleared for files which are (1) deleted on disk
and not open in the editor, and (2) closed and only open in the editor.

Enable the corresponding regression test, and fix a few issues raised by
staticcheck.

Fixes golang/go#37049

Change-Id: Iff736a7f6c3eaacda4237c2e4cf7926e9949dece
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220079
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-19 20:26:41 +00:00
Rohan Challa
7c4b6277d7 internal/lsp: add module versions from "go list" to pkg.go.dev links
This change appends to the pkg.go.dev link the version of the module that is being used. To get this functionality, go/packages.Package now contains a module field which gets populated from the "go list" call. This module field is then used to get the version of the module that we are linking to.

Updates golang/go#36501

Change-Id: I9668a6da0fd3ec8f4cde017986419c8d28196765
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219079
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-19 19:55:21 +00:00
Rob Findley
c4d4ea9c79 internal/lsp/cache: return concrete types where possible
For testability, and to allow the exchange of debug information when
forwarding the LSP, it will be necessary to access debug information
stored in cache objects. This is cumbersome to do if our constructors
return source interfaces rather than concrete types.

This CL changes cache.New and (*Cache).NewSession to return concrete
types. This required removing NewSession from source.Cache. I would
argue that this makes sense from a philosophical perspective: everything
in the source package operates in a context where the Session and Cache
already exist.

Updates golang/go#34111

Change-Id: I01721db827d51117f9479f1544b15cedae0c5921
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220077
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-19 18:42:16 +00:00
Heschi Kreinick
33153249e7 internal/lsp: limit diagnostics concurrency
Diagnostics runs cannot be canceled until they finish a package. If a
user has a very expensive package, we may stack up diagnostics runs to
the point where the machine runs out of memory. We see hints of this in
various issues.

To avoid that, only allow one diagnostics run at a time. We can change
the limit later if we want.

Updates golang/go#37223.

Change-Id: Icd0eec4da936153306cf0a1f7175ae2b4b265272
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219958
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-19 18:35:52 +00:00
Rob Findley
66de428735 internal/jsonrpc2,internal/lsp/regtest: clean up some leaked tempfiles
Not all regtests resulted in LSP shutdown, which caused temp modfiles to
be leaked. After this fix I have confirmed that /tmp is clean after a
successful run of the regtests.

Also proactively clean up the unix socket file when serving jsonrpc2
over UDS.

Change-Id: I745fbd3d2adeeb165cadf7c54fd815d8df81d4e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220061
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-19 18:32:50 +00:00
Rob Findley
5fb17a1e7b internal/jsonrpc2: support serving over unix domain sockets
For tests (and perhaps later, for daemon discovery), unix domain sockets
offer advantages over TCP: we can know the exact socket address that will be
used when starting a server subprocess. They also offer performance and
security advantages over TCP, and were specifically requested on
golang.org/issues/34111.

This CL adds support for listening on UDS, and uses this to implement an
additional regtest environment mode that starts up an external process.
This mode is disabled by default, but may be enabled by the
-enable_gopls_subprocess_tests.

The regtest TestMain may be hijacked to instead run as gopls, if a
special environment variable is set. This allows the the test runner to
start a separate process by using os.Argv[0]. The -gopls_test_binary
flag may be used to point tests at a separate gopls binary.

Updates golang/go#36879
Updates golang/go#34111

Change-Id: I1cfdf55040e81ffa69a6726878a96529e5522e82
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218839
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-19 16:14:01 +00:00
Rob Findley
741f65b509 internal/lsp/lsprpc: add a forwarder handler
Add a forwarder handler that alters messages before forwarding, for now,
it just intercepts the "exit" message.

Also, make it easier to write regression tests for a shared gopls
instance, by adding a helper that instantiates two connected
environments, and only runs in the shared execution modes.

Updates golang/go#36879
Updates golang/go#34111

Change-Id: I7673f72ab71b5c7fd6ad65d274c15132a942e06a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218778
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-19 15:38:09 +00:00
Daisuke Suzuki
ca8c272a4d internal/lsp/tests: fix reset of golden files
internal/lsp/reset_golden.sh fails when golden file does not exist, so
skip loading the golden file on update.
Additionally, add the missing primarymod directory as the update
destination path so that golden files are placed under the primarymod
directory.
However, keep the location of summary.txt.golden in the same directory
as the primarymod directory.
As a result, some unnecessary data was deleted.

Change-Id: I98120c8b7d483174644600786fd30acdc2e4c52e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219577
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-02-19 14:42:13 +00:00
Muir Manders
753a1d49df internal/lsp/cache: kill unused func fixAccidentalDecl
I think I resurrected this accidentally when resolving a merge
conflict.

Change-Id: Ib871068902eeaaca9b95878f3e40ed5e53d6814f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220018
Run-TryBot: Muir Manders <muir@mnd.rs>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-19 05:42:38 +00:00
Heschi Kreinick
f8e42dc477 internal/span: handle URI escaping better
We expected URIs to be canonical, but VS Code's URI escaping is
overeager and escapes things that don't need to be. Forcibly unescape
them, then re-escape them with Go's encoding, so that we know they'll
match URIs generated by URIFromPath.

Fixes golang/go#37231.

Change-Id: I4b163ae3c91e8846ab72e5b5e89bd6d018c3995e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219899
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-18 20:59:02 +00:00
Heschi Kreinick
8fd784fb38 internal/lsp/debug: drop memory debug threshold to 1GiB
Most people do not have giant 64-GiB workstations, so 10GiB of RAM (5
active heap, 5 inactive for GOGC=100) is a really high threshold. Drop
to 1GiB active to drop profiles.

Change-Id: If0ae418828377a648a93322e269f4610fd64ebb3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219937
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-18 20:58:54 +00:00
Heschi Kreinick
dc8ced655d internal/lsp: add scheme checks to CodeLens
I missed this newly-added function in CL 219483.

Change-Id: I4490f579236a7ed358fb7a7ed80276560f19b04e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219539
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-18 19:00:56 +00:00
Rob Findley
b320d3a0f5 internal/jsonrpc2/servertest: support both TCP and pipe connection
Update the servertest package to support connecting to a jsonrpc2 server
using either TCP or io.Pipes. The latter is provided so that regtests
can more accurately mimic the current gopls execution mode, where gopls
is run as a sidecar and communicated with via a pipe.

Updates golang/go#36879

Change-Id: I0e14ed0e628333ba2cc7b088009f1887fcaa82a5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218777
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-16 19:22:41 +00:00
Heschi Kreinick
5916a50871 internal/lsp: check for file URIs on LSP requests
In general, we expect all URIs to be file:// scheme. Silently ignore
requests that come in for other schemes. (In the command-line client we
panic since we should never see anything else.)

The calling convention for beginFileRequest is odd; see the function
comment.

Fixes golang/go#33699.

Change-Id: Ie721e9a85478f3a12975f6528cfbd28cc7910be8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219483
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-14 22:51:26 +00:00
Heschi Kreinick
f7b8cc7bd0 internal/span,lsp: disambiguate URIs, DocumentURIs, and paths
Create a real type for protocol.DocumentURIs. Remove span.NewURI in
favor of path/URI-specific constructors. Remove span.Parse's ability to
parse URI-based spans, which appears to be totally unused.

As a consequence, we no longer mangle non-file URIs to start with
file://, and crash all over the place when one is opened.

Updates golang/go#33699.

Change-Id: Ic7347c9768e38002b4ad9c84471329d0af7d2e05
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219482
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-14 22:51:03 +00:00
Rohan Challa
548b770e2d internal/lsp/cache: parse go.mod file before running go mod tidy
This change reorders the logic within ModTidyHandle and ParseModHandle to parse the modfile first before we copy the contents to the temporary go.mod file. This was causing issues where a go.mod would be in a bad state and then we would try to run "go mod tidy" on the corrupted file.

Change-Id: I1df8fb70f5f3e2bcff306a58b16bc96c32debf2a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219480
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-14 20:11:35 +00:00
Rohan Challa
bc664416c6 internal/lsp: fix error handling when getting go.mod codelens
This change has a fix for mod/codelens: check if we get an error from ParseModHandles().Upgrades(). This change also only runs codelens on save.

Change-Id: I6dab7ddf3a08c650e4c670b039b1e99153ec8187
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219478
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-14 19:54:16 +00:00
Ayke van Laethem
9976379007 go/ssa: add DebugRef.Object
This function is in the documentation for *ssa.DebugRef but is not defined anywhere, so define it now.

Change-Id: I0a6c07ccac16851541a5fe337f0bba66608949cb
GitHub-Last-Rev: 30f39663b48acd419a9ae8a90ae34d9350aff218
GitHub-Pull-Request: golang/tools#201
Reviewed-on: https://go-review.googlesource.com/c/tools/+/216477
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-02-14 19:16:34 +00:00
Muir Manders
ea829e2eb2 internal/lsp/source: handle completing into variadic params
For example:

func foo(string, ...int)

func a() string
func b() (string, int)
func c() (string, int, int)

// Prefer "a()" and "b()" and "c()". Previously we didn't prefer any of
// them.
foo(<>)

Fixes golang/go#36540.

Change-Id: I144b3f63942b7699d3034efcc9ad8535a7fa3165
Reviewed-on: https://go-review.googlesource.com/c/tools/+/215538
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-02-14 18:12:26 +00:00
Muir Manders
c229649527 internal/lsp/cache: fix crash fixing curlies near EOF
We were crashing in cases like:

1:    func foo() {
2:     if b<> <EOF>

We were trying to get the line start position for line 3, but there is
no line 3. Fix by bailing out early if we are the last line in the
file because there is nothing to fix in that case.

Fixes golang/go#37226.

Change-Id: I4ad5746d7b55bdcc2de57c04e972c15a61084faa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219498
Run-TryBot: Muir Manders <muir@mnd.rs>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-14 17:25:38 +00:00
Rob Findley
88be01311a internal/jsonrpc2: fix races in cancellation
We had a deadlock in cases where a request was cancelled (1) after being
written to the stream, but (2) before a response was received. This
resulted in the request ID being removed from the pending map while the
server has the request, after which point the server response would hang
in Conn.Run trying to send to a nil channel.

After fixing this nil send there was still a race: it was possible that
Conn.Run could get the pending request, and Conn.Call would select
ctx.Done before Conn.Run could send to the response channel, again
resulting in a blocking send. Fix this by adding a buffer to the
response channel.

The response channel management is also made less forgiving, because we
should be able to reason precisely about how many sends and receives
will occur:
 + Don't close the response channel after sending a response: there
   should only be one recipient.
 + Don't delete the ID from pending map twice: it should only be cleaned
   up by Conn.Call.

Cancellation tests in the lsprpc package are updated to exercise the
race conditions.

Fixes golang/go#37159

Change-Id: Ie3207442ea910f79247b18d8647fd52f39fb15db
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219126
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-14 14:43:24 +00:00
Rob Findley
0fd2d649e6 internal/lsp/lsprpc: add an LSP forwarder and regtest environment
Add a new Forwarder type to the lsprpc package, which implements the
jsonrpc2.StreamServer interface. This will be used to establish some
parity in the implementation of shared and singleton gopls servers.

Much more testing is needed, as is handling for the many edge cases
around forwarding the LSP, but since this is functionally equivalent to
TCP forwarding (and the -remote flag was already broken), I went ahead
and used the Forwarder to replace the forward method in the serve
command. This means that we can now use the combination of -listen and
-remote to chain together gopls servers... not that there's any reason
to do this.

Also, wrap the new regression tests with a focus on expressiveness when
testing the happy path, as well as parameterizing them so that they can
be run against different client/server execution environments. This
started to be sizable enough to warrant moving them to a separate
regtest package. The lsprpc package tests will instead focus on unit
testing the client-server binding logic.

Updates golang/go#36879
Updates golang/go#34111

Change-Id: Ib98131a58aabc69299845d2ecefceccfc1199574
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218698
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-14 14:21:06 +00:00
Rohan Challa
98b3097d01 internal/lsp: add codelens for go.mod dependency upgrades
This change adds a code lens for go.mod files that will let a user know if a module can be upgraded, once it is clicked gopls will run a command to update that module.

Updates golang/go#36501

Change-Id: Id22b8097ede4972cf73bc029ec927544a71b7150
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218557
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-14 14:15:08 +00:00
Muir Manders
88e652f7a8 internal/lsp/cache: improve completion after dangling selector
Dangling selectors such as:

    func _() {
      x.
    }
    var x struct { i int }

tend to wreak havoc on the AST. In the above example you didn't used
to get completions because the declaration of "x" was missing from the
AST.

We now work around this issue by inserting a "_" into the source code
before parsing to make the selector valid:

    func _() {
      x._ // <-- insert "_" here
    }
    var x struct { i int }

This makes completion work as expected because the declaration of "x"
is present in the AST.

I had to change fixAST() to be called before fixSrc() because
otherwise this new workaround in fixSrc() breaks the "accidental
keyword" countermeasures in fixAST().

Fixes golang/go#31973.
Updates golang/go#31687.

Change-Id: Ia7ef6c045a9c71502d1b8b36f187ac9b8a85fe21
Reviewed-on: https://go-review.googlesource.com/c/tools/+/216484
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-13 22:46:42 +00:00
Daisuke Suzuki
885dec1b2d internal/lsp/source: make matchers selectable in WorkspaceSymbols
This change allows to use fuzzy or case-sensitive matchers in addition
to case-insensitive when searching for symbols.
Matcher is specified by UserOptions.Matcher just like Completion.

Updates golang/go#33844

Change-Id: I4000fb7984c75f0f41c38d740dbe164398032312
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218737
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-13 22:46:20 +00:00
Rohan Challa
695c81b9c6 internal/lsp: fix diagnostics not clearing when creating new files
This change fixes an issue where import errors would not disappear when creating new files in a module by removing the segment of code where we check for listErrors when fixing imports.

Updates golang/go#36960

Change-Id: Iefa17edeb0417cac7e33ffa88faf7c9a607e98b3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219222
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-13 21:50:53 +00:00
Peter Weinberger
e3acd584e2 internal/lsp: two trivial cleanups from CL 219077
Change-Id: Ia55bfc4d8283589a7a70e2b7b2ed3265ead18d62
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219378
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-13 21:22:11 +00:00
Peter Weinberger
63d1300efe internal/lsp: change return type of PrepareRename to *Range
PrepareRename used to return interface{}, but now returns the more
precise result *Range.

Almost all the changes in code.ts come from vscode reformatting it.
The sole substantive change is in goUnionType, near line 685.

Change-Id: If575cb166f26962d24261e79f9d958006011402e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219077
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-13 20:00:52 +00:00
Muir Manders
9f716520f4 internal/lsp/cache: improve completion in init statements
In cases like:

  if i := foo<>

we get an *ast.BadExpr because the parser is expecting the condition
expression, but "i := foo" is not a valid expression. Now we move the
statement into the "init" field and add a dummy "cond" expression.

We also needed a slight tweak to our missing curly brace fix. Now we
insert an extra semicolon in cases like:

for i := 0; i < foo

yielding

for i := 0; i < foo;{}

The parser doesn't like having only two clauses in the three clause
"for" statement.

Updates golang/go#31687.

Change-Id: I12d51e0d8af03436741227753f8e71452a463b05
Reviewed-on: https://go-review.googlesource.com/c/tools/+/216483
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-13 18:11:06 +00:00
Muir Manders
2f0693cea3 internal/lsp/cache: improve completion when missing opening curly
In cases like:

func _() {
  if fo<>
}

func foo() {}

Completing at "<>" does not include "foo" because the missing "if"
opening curly brace renders the rest of the file unparseable. "foo"
doesn't exist in the AST, so as far as gopls is concerned it doesn't
exist at all.

To fix this, we detect when a block is missing opening "{" and we
insert stub "{}" to make things parse better. This is a different kind
of fix than our previous *ast.BadExpr handling because we must reparse
the file after tweaking the source. After reparsing we maintain the
original syntax error so the user sees consistent error messages. This
also avoids having the "{}" spring into existence when the user
formats the file.

Fixes golang/go#31907.
Updates golang/go#31687.

Change-Id: I95ba60a11f7dd23dc484c063b4fd7ad77daa4e08
Reviewed-on: https://go-review.googlesource.com/c/tools/+/216482
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-13 18:10:51 +00:00
Rohan Challa
0abbfa5d31 internal/lsp: turn tempModfile flag on by default
This change turns the tempModfile flag on by default in the master branch.

Change-Id: If96369aee4e970421a80d5ff89385a38c7ccf0b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219225
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-13 15:33:58 +00:00
Rohan Challa
3187b3c415 go/packages/packagestest: fix grouping to account for module versions
This change adds support within packagestest for multiple versions of a supporting module. An example folder structure could now be:

- primarymod
- modules
  - repo1
    - mod1@v1.0.0
      - files
    - mod1@v1.1.0
    - mod2

Since packagestest creates a fake module proxy, we can now supply that proxy with multiple versions of a single module. This will allow us to add more comprehension to tests and be able to test new features (i.e: CodeLens for upgrading dependencies).

Fixes golang/go#36091

Change-Id: I7516e2525228e78b3f5bf1f7d1da1e42038dee37
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218502
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-13 14:44:51 +00:00
Muir Manders
49b8ac185c internal/lsp/cache: add file contents to ParseGoHandle
Currently there is no need for this because the file contents are part
of the file handle. This change is in preparation for an impending
improvement that tweaks the source code during the parse stage to fix
certain kind of terminal parse errors. Any code that wants to use
an *ast.File or *token.File in conjunction with the file contents
needs access to the doctored source code so things line up.

Change-Id: I59d83d3d6150aa1264761aa2c1f6c1269075a2ce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218979
Run-TryBot: Muir Manders <muir@mnd.rs>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-13 05:05:14 +00:00
Muir Manders
cbc0cc175f internal/lsp/source: fix completion crash in append()
We were crashing in cases like:

    var _ []byte = append([]byte{}, ""...<>)

We were type asserting the type of append's second param
to *types.Slice, but in this case it is a string (*types.Basic). Fix
by checking the type assert was successful.

Note that we still don't attempt to give string completions when
appending to a byte slice. We can add that special case later once
everyone is clamoring for it.

Change-Id: I1d2fbd7f538e580d33c2dab4ef127a88e16d7ced
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219144
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-13 02:33:03 +00:00
Rebecca Stambler
2ee7536ab1 internal/lsp: remove nilness analyzer
The nilness analyzer requires SSA, which is very expensive to build and
uses a lot of RAM. It also seems to really shoot up memory usage when it
hits certain cases, which is causing a lot of problems for users.
Disable this analysis - we'll leave SSA to staticcheck.

Updates golang/go#36639

Change-Id: I46e67a6fd7828a5fddcd42d1aa00876f17c79e3d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219203
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-12 21:32:43 +00:00
Rebecca Stambler
6dd6151793 internal/lsp: ignore irrelevant on-disk changes
Change-Id: Ibdceadbfc822a64066d9370eefa9ff5f7988d0a2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219202
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-12 21:15:05 +00:00
Muir Manders
ea181f53ac internal/lsp/source: filter candidates when type name required
Now when we expect a type name at the cursor, we omit non-type name
completion candidates. For example:

inch := 1
var foo in<> // don't offer "inch"

I also added expected type name detection for value specs:

// Expect a type name at <>
var foo <>

Fixes golang/go#32806.

Change-Id: I32477cb286d2050bac5ccc767f8a608124fa5acd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/216400
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-02-12 15:05:39 +00:00
Andrew Bonventre
11eff242d1 Revert "go/analysis: add pass to check for impossible interface-to-interface type assertions"
This reverts commit 7a72f3f8e9.

Reason for revert: The 1.15 tree is not open yet.

Change-Id: I5b3e458748bb3d69950f6331672e8c883d6234fb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219119
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-11 20:56:36 +00:00
Rebecca Stambler
6822f1ada4 internal/lsp: disable nilness analyzer, unless staticcheck enabled
Users with staticcheck enabled will be more tolerant of increased RAM
usage. We might be able to disable this check entirely once the next
version of staticcheck is released with a similar analysis (https://staticcheck.io/docs/checks#SA5011).

Change-Id: I1a844cc226e34e0f62222f12912797a6cc9d06e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219018
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-11 20:49:38 +00:00
Rebecca Stambler
e2a38c8363 internal/lsp: propagate file invalidations to all views
We were previously only invalidating files if they were contained within
a subdirectory of a view, but we should really be invalidating all files
that are known to a view.

Fixes golang/go#34955

Change-Id: I2eb1476e6b5f74a64dbb6d47459f4009648c720d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218859
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-11 18:37:05 +00:00
Rob Findley
f41547ceaf internal/lsp/debug: fix early closure of logfile
As of https://golang.org/cl/218457, logs are not being captured because
the logfile is prematurely closed due to the scope of the deferred
closure changing.

Change-Id: I1754e5555025c7b2a5da58f621184d6740fd03cb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219080
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-11 18:05:03 +00:00
smasher164
7a72f3f8e9 go/analysis: add pass to check for impossible interface-to-interface type assertions
For a type assertion V.(T), where V and T are both interfaces, the
concrete type of V cannot possibly implement T if V and T contain a method
with the same name, but different signature. This change adds an
analysis pass to flag such cases.

Updates golang/go#4483.

Change-Id: Ib1e91794ca7079b3f450520cc1a57d91e46e42fa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218779
Reviewed-by: Alan Donovan <adonovan@google.com>
2020-02-11 17:49:21 +00:00
Muir Manders
2de505fc53 internal/lsp: support multi-dereferencing completion candidates
Now we keep a count of how many times to dereference a candidate. For
example:

    var foo ***int
    var _ int = f<> // Now we offer "***foo" instead of "*foo".

Change-Id: I14edc40aeec6884399eceb3dd3b4f85dc74a773c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218580
Run-TryBot: Muir Manders <muir@mnd.rs>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-11 04:52:51 +00:00
Muir Manders
1e13d9580f internal/lsp/source: fix type modifier detection in composite literals
When completing a composite literal value, we were returning from
candidate inference before we recorded type modifiers such as prefix
"&" or "*". This was causing funny completions like:

type myStruct struct { s *myStruct }
myStruct{s: &mySt<> // completed to "&&myStruct{}"

Now we properly pick up on the "&" prefix so we know our literal
"myStruct{}" candidate does not need a "&".

Change-Id: I908936698cfedfef81bc0c1cbcd93e14dc00e3a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218377
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-11 03:24:02 +00:00
Tomohiro Kusumoto
8feddd8b6a internal/lsp/tests: fix missing period
Change-Id: Idb0b6405aefec1dcef84958482325a68afec5348
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218957
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-11 03:20:47 +00:00
Muir Manders
0bc66720f3 internal/lsp/source: limit to 5 unimported package name candidates
Currently we show up to ~100 unimported package names matching the
completion prefix. This isn't useful since, assuming the user even
wants an unimported package, they will just type more to narrow it
down rather than scroll through 100 options. Having so many candidates
also slows things down due to per-candidate overhead in gopls and in
the LSP client. Now we instead limit to 5 unimported package names.

Unimported package members, on the other hand, make sense to list
many. The user may want to scroll through because they don't remember
the name of what they are looking for. I left the max value at 100.

Change-Id: I00e11fa0420758f8db6c7049f80fa156773a5ee6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218879
Run-TryBot: Muir Manders <muir@mnd.rs>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-11 00:32:09 +00:00
Heschi Kreinick
b0390335f4 internal/lsp/debug: write debug info for large goplses
We've had various reports of high memory usage in gopls. Catching it in
the act can be difficult, so check every second and write relevant
profiles to os.TempDir every time the heap reaches a new watermark.

Note that the logging in this package is broken. I didn't fix it, so
nobody will know this is happening until we tell them. So it goes.

Change-Id: I972d7ccfe5308658f86dde717465f0e0151b396d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218858
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-10 22:37:59 +00:00
Jay Conrod
1ace956b0e internal/imports: import packages from x/mod instead of internal copy
This CL deletes ./internal/module and ./internal/semver, which are
copies of packages in golang.org/x/mod. The copies were created before
x/mod was a separate module.

./internal/imports is updated to use the packages in x/mod.

Change-Id: Id434f5f0a240de97d18505cb7c925c2e062f6231
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218897
Run-TryBot: Jay Conrod <jayconrod@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-10 19:23:13 +00:00
Rohan Challa
3868802a52 internal/imports: change processEnv to use buildflags
This change adds a buildFlags variable to the processEnv struct rather than appending them to the GOFLAGS by using a space separator.

Fixes golang/go#37108

Change-Id: I4331066c30fa51f0133504d723132527b00ce74a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218857
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-10 18:52:02 +00:00
Ian Cottrell
bdd8440908 internal/lsp: move all debugging support to the debug package
We now carry around a debug instance in the app, and it manages the log file and
all telemetry

Change-Id: If4a51a36c38ef301b1b2bbda8e4c0a8d9bfc3c04
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218457
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-02-10 18:44:17 +00:00