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

556 Commits

Author SHA1 Message Date
Rebecca Stambler
89a01ca1a8 internal/lsp: support an experimental structured hover format
Updates golang/go#33352

Change-Id: Ibf18e2529c9ba8c94c66942ea6f2c27f047ed285
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189977
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-12 21:55:50 +00:00
Rebecca Stambler
0d62d4405e internal/lsp: change ordering of hover depending on hoverKind
This change configures the ordering of documentation on hover. If the
user has requested full documentation, the signature appears at the top,
to avoid the user having to scroll. Otherwise, the signature appears at
the bottom, to minimize the distance between the triggering identifier
and the signature.

Updates golang/go#33352

Change-Id: I017baaabd0ee0c31cb13cb6abdda296782929823
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189943
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-12 21:11:28 +00:00
Rebecca Stambler
f07d81a593 internal/lsp: fix documentation for completion items
This change fixes documentation for completion items by using cached
package and AST information to derive the documentation. We also add
testing for documentation in completion items.

Change-Id: I911fb80f5cef88640fc06a9fe474e5da403657e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189237
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-12 17:13:29 +00:00
Michael Matloob
e713427fea go/analysis: remove +experimental build tag from suggested fixes
We're still leaving open the possibility of changing this API,
but things have baked for a bit so I feel comfortable removing the
build tag.

Also add some documentation.

Change-Id: I3beb666b58177553fc406dc9670d569d5928fedd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189460
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-08 19:51:39 +00:00
Sander van Harmelen
128824a23e internal/lsp: prevent too much open files issues
On MacOS the default open file limit is 256 files per process. For big
projects this could cause issues when reading all files (more or less)
at the same time.

By moving up the `parseLimit` so the reading of the file is only done
when it is allowed to start parsing the file, we stay well below the 256
files per process (as the `parseLimit` is currently set to 20).

Since `parseLimit` is actually only used to limit IO access, let's also
rename the const to `parseLimit`.

Change-Id: Ie8744030875d84d0d6095ee4ec2d9d553911bed1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189437
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-08-08 17:29:24 +00:00
Sander van Harmelen
b346f7fd45 x/tools/cmd/gopls: prevent nil pointer dereferences
The `files` slice is used twice. First it's used to get all results from `ph.Parse`, and then it's reused to filter all `nil` values (which may have been returned by the `ph.Parse` method).

After the loop to "filter" out all the `nil` values, we also need to strip the remaining values.

I also changed the ordering so that we first check the errors and
only then perform this loop. That way the code will return earlier
when the context was canceled.

Partially fixes #33531 by prevention the panic reported in that issue.

Change-Id: I09478e765adcd0384ec4745921eb5c5aea405ef2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189397
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-07 22:35:07 +00:00
Rebecca Stambler
8be58fba63 internal/lsp: minor refactoring for source.Identifier
Change-Id: Ia604f59d6229c2086fe63e73466de7489e1cda2d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189321
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-08-07 20:13:05 +00:00
Rebecca Stambler
cae9aa5434 internal/lsp: show "do not edit" message when user opens generated file
This is probably a better approach than showing an extra diagnostic,
since a user cannot dismiss a diagnostic.

Fixes golang/go#33397

Change-Id: I92b9a00f51a463673993793abfd4cfb99ce69a91
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188766
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-07 16:44:42 +00:00
Michael Matloob
9fb8e5c879 internal/lsp/testdata: delete nodisk/newdisk_exists.go
It should work now that go packages accepts go1.13's new go list
behavior.

Updates golang/go#33157

Change-Id: I1780210b414bc0556e10e10c8c775fbfd2922b2e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189038
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-06 20:59:09 +00:00
Jan Steinke
be5259f298 internal/lsp: use x/xerrors to create new errors
This relates to https://github.com/golang/go/issues/31374 and should switch all instances within `gopls` to use `x/errors` instead of `fmt` to create new errors.

Change-Id: I18339b75d12418d852e0dcc2ba0ed6c2970783b3
GitHub-Last-Rev: f4a55d9b79e7458ef1f1e06cb5eabbabd884f321
GitHub-Pull-Request: golang/tools#108
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179880
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-06 19:46:56 +00:00
Rebecca Stambler
249e2b9b6d internal/lsp/cmd: handle errors when adding a file
Change-Id: Iaed5c92fe777e5b9b588614b5c1696851e3f6c93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188597
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-06 19:33:29 +00:00
Rebecca Stambler
73d708539c internal/lsp/cmd: remove unused isRace global variable in cmd
Change-Id: I9a71df9012fe7477b9e28b8665806d2ecc18f659
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188359
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-06 19:31:56 +00:00
Rebecca Stambler
1dcc99b65a internal/lsp: do not show errors for code actions on go.mod files
This change keys the supported code actions map by file kind, so that we
can extend it more easily for go.mod files.

Change-Id: Ic28f91bd517700cf070281b1c4d4ded14a702790
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189039
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-06 19:11:59 +00:00
Rebecca Stambler
982211fce4 internal/lsp: support single-line hover for LSP clients like Vim
Fixes golang/go#32561

Change-Id: I4399be3cfe745b85a23a82a183277e290ef2a3d8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188981
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-06 19:08:13 +00:00
Emmanuel T Odeke
e1fc249b66 internal/lsp/telemetry/ocagent: add convertAnnotation tests
* Adds tests for 'convertAnnotation'.
* Ensures that converting an empty string "" to
a truncatable string returns nil, to save bandwidth. However,
in the future, we should perhaps allow empty strings to
be serialized if say "emptyAllowed" is set.
* Caught the case where convertAttribute hadn't type
switched on "int"
* Provides 40.5% test coverage for ocagent.go

More tests for the other functions shall follow in later CLs.

Updates CL 186679

Change-Id: Ie9b46b0b320339ed79cd136fff536ccfcfbeb9e7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188877
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-05 19:50:47 +00:00
Rebecca Stambler
2756c524cc internal/lsp: format files that parse in packages with parse errors
Updates golang/go#31291

Change-Id: Ibbd0b6cef9b9ec588c8a2e0c5e7ee6e3512b8a22
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188767
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-08-05 16:54:05 +00:00
Albert Teoh
773fe550c1 gopls: return file error if file open fails
The bug manifests itself when a non-existent file is passed in as an
argument to gopls, causing a nil pointer dereference panic. This is due
to an attempt to reference the "mapper" attribute, which is not set if
the file is not found.

The resolution is to check for an informative error that is set on the
file instance after "getFile" is called and return it immediately to the
caller to allow the error to propagate up to the main() function and
print the error to stdout.

Testing:
--------

Non-existent file:
$ gopls -rpc.trace -v check gopls/doesnotexist.go
check: file:///Users/albertteoh/repo/tools/gopls/doesnotexist.go: open /Users/albertteoh/repo/tools/gopls/doesnotexist.go: no such file or directory

Existing go file:
$ gopls -rpc.trace -v check internal/lsp/definition.go
2019/08/03 13:33:00 Info:go/packages.Load
	packages = 2
2019/08/03 13:33:00 Info:go/packages.Load
	package = golang.org/x/tools/internal/lsp
...

Fixes golang/go#33445

Change-Id: Ib56d8a4b7f23f4882b75cf684c5d18a49d27b824
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188857
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-05 16:01:13 +00:00
Rebecca Stambler
43c5e4ca5b internal/lsp: handle potential nil pointers in GetToken
Change-Id: Icd24c7c717099209f246fd4c0d5dc2e424613962
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188757
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2019-08-02 20:08:13 +00:00
Suzy Mueller
5f95ed5921 internal/imports, internal/lsp: quick fix import errors
Get quick fixes for the diagnostics related to import errors. These
fixes add, remove, or rename exactly one import.

This change exposes the individual fixes found by the imports package,
and then applies each of them separately to the source.  Since applying each
fix requires a new ast anyway, we pass in the source to be parsed each time.

Change-Id: Ibcbfa703d21b6983d774d2010716da8c25525d4f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188059
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-01 20:53:47 +00:00
Ian Cottrell
c001e47e7f internal/lsp: extra telemetry tagging of files and packages
Change-Id: Ia9a8fb5dcfb74e86b9366849810dd3edc1f898dd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186918
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-31 19:44:43 +00:00
Muir Manders
dddb761723 internal/lsp: fix watched file protocol constants
The "Create" and "Delete" WatchKind values were missing from the
generated code because their names were colliding with other
constants. Add "WatchKind" to go.ts prefix map to disambiguate.

Updates golang/go#31553

Change-Id: I60269969831c0822896e87b3f2332ded71748f42
GitHub-Last-Rev: 6d85cf9b3865ba5af0b5ec7f90358e5734ed9451
GitHub-Pull-Request: golang/tools#136
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186097
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-31 19:43:47 +00:00
Billie Cleek
09f9cfa882 internal/lsp: set initialized state
Set the server state to initialized so that dynamic configuration
requests will be sent to the client.

Rename the mutex that guards state. The state field was previously named
initialized, so it only makes sense to similarly rename the mutex that
guards the state field.

Always unlock stateMu before calling other functions so that callees
that need to check state can acquire the lock.

Change-Id: Ia5592ca1dedfc6f004ae6b61548890624ae98d59
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188097
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-31 19:33:23 +00:00
Suzy Mueller
a81e99d748 internal/lsp: find import errors for named imports
String matching is used to find diagnostics that could be fixed by
organizing imports. Unused imports are of the form:
	"X imported but not used"
	"X imported but not used as Y"

Check that "imported but not used" is contained in the message to
include both named and unnamed imports.

Change-Id: I478d1fb239962e706eb1adf305b858fcc875b7f0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188158
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-31 16:32:15 +00:00
Odin Ugedal
ed3277de27 internal/lsp: use correct desc for annotation
If the message is empty and there is and there is an error,
the description of the annotation should be the error message.

More info can be found here:
https://go-review.googlesource.com/c/tools/+/186679

Change-Id: Ica0a9cc132de912b2e14ab527baf4304f8b5d8ba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188118
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-30 21:53:28 +00:00
Edward Muller
7deaedd405 internal/lsp/cache: clean up parse.go
switch the ioLimit channel from a bool to a struct{} as the values
stuffed into the channel have no meaning.

A mix of consistency and comment cleanups in *importer.parseFiles.

sameFile is reported as unused, so removed, removing some now unused
imports.

The assignment to lit in *view.parseDeferOrGoStmt's for{} loop was
reported as ineffective.

Update the comment of fix a little for clarity.

Change-Id: I50f0442bfd7e4d0cc0e6fdadbf1f6272366a716c

Change-Id: I50f0442bfd7e4d0cc0e6fdadbf1f6272366a716c
GitHub-Last-Rev: 74d8a8bdb768a827db3c1fd1723a528818e222ee
GitHub-Pull-Request: golang/tools#109
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179957
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-30 20:51:20 +00:00
Michael Matloob
ff9f140924 internal/lsp/source: fix renaming of SuggestedFixes in experimental file
Change-Id: I4a20ef09c565da39ed49f25d85133cd388c2bf05
Reviewed-on: https://go-review.googlesource.com/c/tools/+/187820
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-29 09:26:21 +00:00
Ian Cottrell
fc6e2057e7 internal/lsp: process configuration per workspace folder
Change-Id: Ibd72a13166b65e418a40bf850401573a6b9caf0f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/187819
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-28 06:35:39 +00:00
Suzy Mueller
db2fa46ec3 internal/lsp: compare mod file versions used in imports
The results of running 'go list -m' are only valid as long as the
current module and the modules in its replace directives do not
change their go.mod files. Store the 'go.mod' versions that are
used in the imports call, and reinitialize the module resolver if
they change.

Change-Id: Idb73c92b9e4dc243a276885e5333fafd2315134d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186597
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-27 17:31:35 +00:00
Suzy Mueller
1bd56024c6 internal/lsp: format files in packages with errors
Packages with errors may still contain files that can be formatted.
Try to format the source of the files in packages that have errors.
This change will still not format files with parse errors.

Updates golang/go#31291

Change-Id: Ia5168d7908948d201eac7f2ee28534022a2d4eb0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/187757
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-26 23:07:22 +00:00
Jorge Araya
4e8ec5a316 internal/lsp: swallow hover error over identifier not found
Fixes https://github.com/golang/go/issues/32967

Change-Id: I41245582f95f8a31e0d1990eac7aeb2a9c29cf05
GitHub-Last-Rev: 5d257b66138be4b9ea502af89ff48f0574c91718
GitHub-Pull-Request: golang/tools#140
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186997
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-24 18:42:53 +00:00
Ian Cottrell
8bb11ff117 internal/lsp: fix lockup for packages with many files
We should not be sending messages from within the telemetry worker. This does it in a new go routine now.

Change-Id: I55e3b6df04699b8e45bc37b99997463f45ee114e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186958
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-23 02:17:37 +00:00
Ian Cottrell
e377ae9d63 internal/lsp: add an ocagent exporter for the telemetry system
Metrics will be added once the agent supports the json form.

Change-Id: I40f6790970311b020a7cab72474b71f4e2aa32e9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186679
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-19 00:56:02 +00:00
Ian Cottrell
87e92536fd internal/lsp: the json wire format of the open cencus agent
These are hand written structs that when passed through the standard json
encoder produce output that mathches the json form of the open census protobuf
messages.
This allows us to talk to the agent without any extra dependancies.

Change-Id: I23d617018009520aad3832e0425ed0a53c51fd1f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186678
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-18 23:01:37 +00:00
Ian Cottrell
625c92e46d internal/lsp: have tests report a different application name to the main gopls binary
Change-Id: I246dc9c468ee35586a8332ebdf41f23521adbc6c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186677
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-18 23:01:26 +00:00
Ian Cottrell
38daa6564b internal/lsp: new tracing system
Change-Id: Id6e6b121e8c69d6324a15cb46b3b9937dfe7a1dd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186201
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-18 23:00:54 +00:00
Suzy Mueller
82a3ea8a50 internal/imports: save scanned module cache results
Save the packages found when scanning of the module cache.
The computed package may have a different import path due
to replace directives, so this needs to be updated
when the moduleResolver is initialized again.

Change-Id: Ib575fcc59b814ff263b431362df3698839a282f6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186301
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-18 20:03:17 +00:00
Rebecca Stambler
c81b74871b go/packages, internal/lsp: modify tests to expose overlays bug
https://golang.org/issue/33157 explains the issues with overlays. The
gopls tests caught this bug, but the go/packages tests didn't, so modify
the go/packages tests correspondingly.

Change-Id: I8ea8e06e145aa2420655cbe4884e60f36acfad7b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186299
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-18 19:31:13 +00:00
Ian Cottrell
7caf8110c9 internal/lsp: purge the remains of the xlog system now it is not used
Change-Id: Iad8f037de88c2657734b8a1b5c73fc708d3b5924
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186198
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-18 19:11:56 +00:00
Ian Cottrell
73497f0562 internal/lsp: convert logging calls
Change-Id: I09ee44d0121b7ced001b8195f9fa81b5225cb0c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186197
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-18 19:03:12 +00:00
Ian Cottrell
7ec096a112 internal/lsp: add a new telemetry based logging system
Also add enough support that using it from within the context of the lsp will
report back to the original client.

Change-Id: I081f157c289642454e9f0476747b2131dcd4e16c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185996
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-18 19:02:45 +00:00
Ian Cottrell
f2838559cb internal/lsp: use a background context for the background worker
A detatched context ends up attributing all background work to the initialize
function.

Change-Id: I81206462752228d5ac81408fb1e3fb86ab36796e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186457
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-18 19:01:55 +00:00
Ian Cottrell
128ec6dfca internal/lsp: fixed broken tracing
I dropped the line that added the stats to the context when merging the recent changes.

Change-Id: I66ab2958b0737360896b40bf30c5ca3c2cebbae5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186300
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-17 19:45:35 +00:00
Rebecca Stambler
e98af23098 go/packages: add debug logging via the packages.Config
This change adds a Logf field to the packages.Config.

Change-Id: I144a9a1e1181585bbe621898c4a3e6a007a38322
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185993
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-07-16 22:11:50 +00:00
Suzy Mueller
fdb8f0bb4e internal/lsp: cache the imports ProcessEnv across imports calls
The imports ProcessEnv contains cached module and filesystem state. This change
allows gopls to use the same ProcessEnv and resolver across multiple calls to the
internal/imports library.

A ProcessEnv belongs to a view, because the cached module state depends
on the module that is open in the workspace.

Since we do not yet track whether the 'go.mod' file has changed, we
conservatively reset the cached state in the module resolver before
every call to imports.Process.

Change-Id: I27c8e212cb0b477ff425d5ed98a544b27b7d92ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184921
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-16 21:50:18 +00:00
Ian Cottrell
b0712d6011 internal/lsp: fix the incomplete and broken commit
https://go-review.googlesource.com/c/tools/+/186297 was the wrong commit, this
adds the changes that were supposed to be part of it.

Change-Id: I0c4783195c2670f89c3213dce2511d98f21f1cf4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186379
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-16 20:34:22 +00:00
Rebecca Stambler
b667c4c58e internal/lsp: cache the *ast.File and *token.File on the package
This change removes the need for the ast and token fields on the *goFile
object. We switch to using source.ParseGoHandles on the package, which
means that we can easily access both the AST and token via the package,
which is already cached.

Change-Id: I5f78bbe09362f4d95eb15556617bdbd809a7a55d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185878
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-16 19:44:59 +00:00
Ian Cottrell
502543d2ed internal/jsonrpc2: move stats and logging across to gopls
Change-Id: I718ad6075028e922a1a046b22fd01a1315421be1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186297
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-16 19:44:06 +00:00
Ian Cottrell
0b5a7f81db internal/lsp: add tracing to the didOpen call
We only had the tracing on didChange before this

Change-Id: Iadec8a43d439931bf58925f149a1d32b3ae29c36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186199
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-16 17:52:09 +00:00
Rebecca Stambler
919acb9f1f internal/lsp: add continue to source_test
Noticed this because I was accidentally running these tests with Go
1.11.

Change-Id: Ic35d71bd1da9078b4bde6aa2ed62d54a8b95b0e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186298
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2019-07-16 15:00:14 +00:00
Ian Cottrell
9b2cb0e5f6 internal/lsp: add temporary file to fix bug with tip go
There is a problem with this test failing in module mode only with the
tip of the go tree. Adding this file changes it from a pure overlay package
to one that has an extra file, which fixes it for now.

updates golang/go#33125

Change-Id: I87dae0b44691246a1f79df454afb190f944cc886
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186259
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-15 22:19:14 +00:00
Suzy Mueller
a0f5e6c5c2 internal/lsp: sort rename results
We recommend that gopls integrators apply the []TextEdit responses in
reverse order to get a correct resulting document. This strategy works
when the response is already sorted. Have gopls return sorted []TextEdit
for each file.

Fixes golang/go#33123

Change-Id: Ib570881c9623695d2ae3194fa8a97b0a681a3250
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186258
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-15 22:13:26 +00:00
Rebecca Stambler
607ca053a1 internal/lsp: fix panics in loading, add more logging
Fixes golang/go#32929

Change-Id: I15e258fe03ef07dbb4ece79f52cb0d0353c8b0b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185994
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-15 04:47:52 +00:00
Ian Cottrell
ef8e083144 internal/lsp: add an rpc summary debug page using the metrics
Change-Id: I92481b0e7996747d70081d575a47768222219506
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185986
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-15 03:47:58 +00:00
Ian Cottrell
565492930f internal/lsp: remove the non context xlog path
And purge the loggers from the view and session.

Change-Id: I262958f340e9a5ac9cc9b3db9e9910381e457478
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185989
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-15 03:45:47 +00:00
Ian Cottrell
1b7e409d2c internal/lsp: convert all logging calls to the context version
Change-Id: I20e3acee4272f05a9f31a7bb4219fc2fe751e6b3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185988
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-15 03:44:59 +00:00
Ian Cottrell
c8ecc7589e interal/lsp: add context based version of xlog
this is a temporary migration solution

Change-Id: Idb6542298dff85a0926aae761f6317ea155293db
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185987
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-15 03:44:47 +00:00
Ian Cottrell
8b927904ee internal/jsonrpc2: extract logic to handler hooks
Change-Id: Ief531e4b68fcb0dbc71e263c185fb285a9042479
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185983
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-12 21:32:46 +00:00
Ian Cottrell
b32ec66a23 internal/jsonrpc2: cleanup the jsonrpc2 callbacks
We merge them into a single interface and support multiple of them rather than
just one.
This will allow us to stack handlers with different responsabilities and extract
some core logic (like tracing) out to a handler where it belongs.

Change-Id: I6aab92138550c5062fcb1bed86171e0850d1eb38
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185879
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-12 21:23:00 +00:00
litleleprikon
f4b4e63240 internal/lsp: fix unnecessary error logging
In internal/lsp/link.go appeared a bug that error message is printed
even if error is not apeared. this commit is fixing this behaviour.

Fixes golang/go#33087

Change-Id: I932546867d78c5c0c3d2c9dabd13287f6837f458
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186037
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-07-12 19:52:12 +00:00
Rebecca Stambler
128c804424 internal/lsp: handle language ID in didOpen calls
This change merely modifies session.DidOpen to accept the document's
language ID. It does not actually add any handling of the language ID.

Change-Id: I2582ae307d1ca062f37b4683907cdbcfdfc61809
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184160
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-12 19:25:23 +00:00
litleleprikon
8308f91286 internal/lsp: add links search in comments and string literals
Add to "textDocument/documentLink" request handler ability to search
URLs in string literals and comments.

Fixes golang/go#32339

Change-Id: Ic67ad7bd94feba0bb67ab090a8903e30b2dff996
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185219
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-12 18:53:41 +00:00
Muir Manders
63f37bb4d3 internal/lsp: fix some cases of stuck files
If typeCheck() returned an error, we could get into a state where a
package had an entry in the pcache, but the package's files had an
empty "pkgs" map. When we got a DidChange event for one of the files,
no packages would get invalidated since the file's "pkgs" was
empty. This resulted in the cached typeCheck() error persisting
indefinitely. Fix by never caching pcache entries on error.

An easy way to reproduce the problem was to delete the package name
from a file. For example, edit "package foo" to be just
"package". This caused the package to get stuck with an "AST for %s
has an invalid position" error.

Change-Id: I330bf9e419852dffa0f2dee94b56226367488dd1
GitHub-Last-Rev: 18be7078521b942694c76f799a2d520eee47167d
GitHub-Pull-Request: golang/tools#135
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185839
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-07-12 18:43:07 +00:00
Ian Cottrell
9a621aea19 internal/lsp: update the generated lsp protocol
Change-Id: Ic30a6e9e49a67f93419547ea2c61d87109959393
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185777
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-11 19:11:10 +00:00
Ian Cottrell
9c57229d8a internal/lsp: add prometheus exporting of all metrics
Change-Id: I1e7ce371d8abd2eb80aad70935695f61b6374ff8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185347
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-11 17:26:14 +00:00
Ian Cottrell
75aaabac35 internal/lsp: reduce trace package to minimal StartSpan for now
also change the return type to be and end function and not an incomplete span

Change-Id: Icd99d93ac98a0f8088f33e905cf1ee3fe410c024
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185349
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-11 17:25:55 +00:00
Ian Cottrell
6156d14a7a internal/lsp: add the metrics package
This provides the basic support for aggregating stats into useful metrics,
utilizing tags.
This change also adds the standard rpc metrics for the stats the jsonrpc2 system
is already filling in.

Change-Id: Ibe1b64c4c4c587dacd53112454606634e9f682ce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185342
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-11 17:12:21 +00:00
Henry Wong
01b81f4f93 internal/lsp: support hover for *ast.ImportSpec
Since 'IdentifierInfo' doesn't contain ast node of import spec,
gopls will construct an empty string under plaintext mode and
'```go\n\n```' under markdown mode for *ast.ImportSpec. For now,
the hovering result of import spec is the corresponding node
format.

Fixes golang/go#33000

Change-Id: I4c25782ddb5bcc557ace82f46d480316b0b90509
GitHub-Last-Rev: 150728f401c5f9b161b557584ad3250f46e50869
GitHub-Pull-Request: golang/tools#134
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185357
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-11 17:06:56 +00:00
Ian Cottrell
5f9351755f internal/lsp: stop making background contexts everywhere
For all uses inside the lsp we use the detatch logic instead
For tests we build it in the test harness instead
This is in preparation for things on the context becomming important

Change-Id: I7e6910e0d3581b82abbeeb09f9c22a99efb73142
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185677
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-11 16:38:52 +00:00
Rebecca Stambler
554846603d internal/lsp: update version and go.mod
Change-Id: I637085b8866d561b9ac21a6612b3bdad8cf6c99a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185557
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-10 16:59:51 +00:00
Rebecca Stambler
831012c29e internal/lsp/debug: increase gopls version before tagging new version
Change-Id: I4273faa26e23dd237078c02439c1bafa2904fcc5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185348
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-10 15:33:21 +00:00
Suzy Mueller
7b25e351ac internal/lsp: rename identifiers in test packages
Support renaming of identifiers in test packages. The packages for
all of the references must be checked and the changes need to be
deduped, since both a package and its test package contain some of the
same files.

Fixes golang/go#32974

Change-Id: Ie51e19716faae77ce7e5254eeb3956faa42c2a09
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185277
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-09 21:17:00 +00:00
Ian Cottrell
f82b303b69 internal/lsp: add new stats library
This is the basic library that allows for recording of stats about the program
operation.

Change-Id: I09f7e3de5fc37aaf29bc0db46f15b15056fc0eb2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185338
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-09 19:46:23 +00:00
Ian Cottrell
75a6f91e26 internal/lsp: add the new form of the telemetry tagging package
This maps more directly to the basic telementery tagging requirements and uses
the context package in a way that is more idomatic.

Change-Id: If08c429b897bddfe014224ac2d92d7796a521ab9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184941
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-09 19:46:06 +00:00
Ian Cottrell
8962968d5a internal/lsp: add the worker package
This is used by all the telemetry packages that come next

Change-Id: Ic84d91da2a792b53ee8839aae207ae5767ab17e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184940
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-09 19:45:51 +00:00
Rebecca Stambler
4f9eeaf1bf internal/lsp: add documentation to completion items
This change adds documentation to the completion items. This normally
should be done in completionItem/resolve, since it takes more time to
compute documentation. However, I am not sure if that latency incurred
by pre-computing documentation is actually significantly more than the
latency incurred by an extra call to 'completionItem/resolve'. This
needs to be investigated, so we begin by just precomputing all of the
documentation for each item.

Updates golang/go#29151

Change-Id: I148664d271cf3f1d089c1a871901e3ee404ffbe8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184721
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-09 19:19:00 +00:00
Suzy Mueller
e491332ed8 internal/lsp: compare names when finding references
Objects for builtin types all have position token.NoPos. We do
not want all objects that have position token.NoPos to be matched
when we are looking for references for this object, so we need to
compare the names of the objects as well.

Fixes golang/go#32991

Change-Id: I67e7aba9909ebcbb246203ea5c572debf996c792
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185247
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-09 18:45:27 +00:00
Muir Manders
d255de4fdb internal/lsp: don't refresh metadata when context canceled
We err on the side of refreshing package metadata if something goes
wrong getting a file's AST, but we don't want to refresh in the case
of context cancellation. Now we check for that error explicitly.

In particular, I noticed that completions would stop working when
typing quickly. Refreshing the metadata triggers "go list" calls which
can take a long time in certain cases.

Change-Id: I1b0c580e5541b1536a69ccaef241d7e8c5720d60
GitHub-Last-Rev: 6a82bfb586f93ef5e8e5996b11e06ffc7808f529
GitHub-Pull-Request: golang/tools#130
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184977
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-09 18:24:20 +00:00
Suzy Mueller
07655f7ec7 internal/lsp: return an error when renaming a builtin
Return an error when attempting to rename a builtin identifier.

Fixes golang/go#32992

Change-Id: I7fb0f9cc9499e5afdfb14805c49c820e4da3b601
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185246
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-09 18:23:51 +00:00
Suzy Mueller
c93f28baaa internal/lsp: check no errs for assignability rename
The satisfy package has a precondition for Finder.Find that requires
that the package has no type errors. If this is a check that we would
perform, give an error and do not rename.

Fixes golang/go#32882

Change-Id: Id44b451bf86ff883fd78a6306f2b2565ad3bdeb9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184857
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-08 20:09:55 +00:00
Henry Wong
dd7c7173f1 internal/lsp: remove the unused function 'markupContent'.
The last usage of 'markupContent' has been deleted in
https://go-review.googlesource.com/c/tools/+/172958.

Change-Id: I03296fa93069427339f17c7b2ad2267030a5b99b
GitHub-Last-Rev: a85b88cdfd00c8d1edf4fdad6302486379beae9a
GitHub-Pull-Request: golang/tools#132
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185237
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-07-08 17:12:32 +00:00
Paul Jolly
60762fc531 internal/lsp: fix test failure introduced in CL 185058
Failed to properly check the try-bot result in CL 185058. Hence didn't
spot the LSP tests that also verify offset behaviour. This CL fixes
those tests to align the LSP tests with the change introduced in CL
185058.

Change-Id: Ia81ab6db7a2c3a4729d8ef73205b6071af270b00
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185220
Run-TryBot: Paul Jolly <paul@myitcv.org.uk>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-08 15:18:58 +00:00
Rebecca Stambler
2214986f16 internal/lsp/fuzzy: add fuzzy matching library
This change uses a fuzzy matching library to score completion results.

Updates golang/go#32754

Change-Id: Ia7771b33534de393a865443e05c0fcbf1e9a969b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184441
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-03 21:24:19 +00:00
Rebecca Stambler
719fbf7c21 internal/lsp: move function signature into detail instead of label
Fixes golang/go#32414

Change-Id: If08e655d7a0e29b0865c13d8377e98be01cf24c5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184777
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-03 21:07:46 +00:00
Ian Cottrell
504de27b36 internal/lsp: connect memoize actions to their callers
This adds the ability to tie a background context to the context that created it
in traces, and also cleans up and annotates the context used in type checking.
This gives us detailed connected traces of all the type checking and parsing
logic.

Change-Id: I32721220a50ecb9b4404a4e9354343389d7a5219
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183757
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-03 19:15:39 +00:00
Ian Cottrell
4457e4cfd4 internal/lsp: add some trace spans to important functions
This uses the new opencensus compatability layer to add telementry to some of
the functions in the lsp, in order to allow us to understand their costs and
call patterns.

Change-Id: I7df820cd4eace7a4840ac6397d5df402369bf0a7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183419
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-03 19:14:57 +00:00
Suzy Mueller
abb7e64e89 internal/lsp: include declaration for references
A client can specify "IncludeDeclaration" in its ReferenceParams.
When they do so, we want to include the declaration, even if it was not
in the scope we searched for references.

Additionally, we also return the location of the declaration first in
the result array when it is included in the results.

Updates golang/go#32572

Change-Id: I12837cd98102ee8d531f0f4bac2fb7bded2564c0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184723
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-03 18:39:24 +00:00
Jonathan Amsterdam
063514c48b internal/lsp/cmd: replace time.Tick with time.After
time.Tick produces multiple ticks (and leaks a Ticker); time.After
produces a single tick, which is what is called for here.

Change-Id: I922b11e1263a8367afec76c10831b7284f3559ec
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184938
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-03 17:54:00 +00:00
Muir Manders
a00916dd39 internal/lsp: fix deadlocks loading lots of files at once
The first deadlock involved differing mutex acquisition order in two
code paths:

1. loadParseTypecheck() holds the "mcache" mutex then eventually
   acquires the "handleMu" file mutex.
2. (*goFile).invalidateContent() acquires the "handleMu" mutex first and
   then the "mcache" mutex.

Fix by changing the acquisition order in invalidateContent().

The second deadlock involved the file watcher. The two code paths
involved were:

1. (*goFile).GetPackages() holds the view mutex and eventually calls
   (*WatchMap).Watch, which acquires the watcher mutex.
2. (*session).openOverlay acquires the watcher mutex as it triggers a
   file's callbacks, and then the callback
   "(*goFile).invalidateContent" acquires the view mutex.

Fix by not holding the watcher mutex as we invoke the callbacks.

Fixes golang/go#32910

Change-Id: I9d060e0d80fd86a317a1d6c7aaa736a8ce10bd07
GitHub-Last-Rev: 04944fa0249c0e6f1022a415787e23abce21bc2e
GitHub-Pull-Request: golang/tools#129
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184880
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-03 17:22:52 +00:00
Rebecca Stambler
1c78e26233 internal/lsp: add configuration for hover levels
Instead of defaulting to a one sentence synopsis for documentation on
hover, allow the user to configure the amount of documentation they want
to see. Right now, the options are none, some (using go/doc.Synopsis),
or all. We should add a 4th, single-line, mode, which will allow clients
like vim-go to stop stripping off documentation on hover.

Updates golang/go#32561

Change-Id: I529242da84b794636984d5ef2918b7252886f0ef
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184797
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-03 17:17:32 +00:00
Muir Manders
9d59f9e855 internal/lsp: improve completion support for untyped constants
Add some extra smarts when evaluating untyped constants as completion
candidates. Previously we called types.Default() on the expected type
and candidate type, but this loses the untypedness of an untyped
constant which prevents it from being assignable to any type or named
type other than the untyped constant's default type.

Note that the added logic does not take into account the untyped
constant's value, so you will still get some false positive
completions (e.g. suggesting an untyped negative integer constant when
only a uint would do). Unfortunately go/types doesn't provide a way of
answering the question "is this *types.Const assignable to this
types.Type" since types.AssignableTo only considers a constant's type,
not its value.

Change-Id: If7075642e928f712b127256ae7706a5190e2f42c
GitHub-Last-Rev: 124d2f05b0aec09c9d7004d9da0d900524185b92
GitHub-Pull-Request: golang/tools#128
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184477
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2019-07-03 16:30:32 +00:00
Rebecca Stambler
7e72c71c50 internal/lsp: hide signature help in function literals
Often anonymous functions can be passed as arguments to a function. In
these cases, it can be annoying for a user to see signature help for the
entire duration of their writing this function. This change detects if
the user is typing in a function literal and disables signature help in
that case.

Fixes golang/go#31633

Change-Id: I7166910739b6e1ec0da2ec852336136b81d13be0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184260
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2019-07-02 15:22:45 +00:00
Suzy Mueller
f80f67146e internal/lsp: support renaming import specs
Support the renaming of the imported name of a package within a file.
This case needs to be special cased because the ident may be added or
removed.

Change-Id: I333bc2b2ca5ce81c4a2afb8b10035f525dfad464
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184199
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-02 14:51:11 +00:00
Rebecca Stambler
38ae2c8f64 internal/lsp, internal/imports: use the internal goimports library
This change modifies gopls to use the internal goimports library, which
allows us to manually configure the ProcessEnv. We also add a logger to
the ProcessEnv to allow this change not to conflict with gopls's logging
mechanism.

Fixes golang/go#32585

Change-Id: Ic9aae69c7cfbc9b1f2e66aa8d812175dbc0065ce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184198
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-07-01 19:45:22 +00:00
Rebecca Stambler
e47c3d98c3 internal/lsp: check file content on disk when opening
As per discussion on golang/go#32810, to avoid the `go list` storm caused by many
files being opened, we check if the file content opened is equivalent to
the content on disk. If so, we mark this file as "on disk" so that we
don't send it as an overlay to go/packages.

Updates golang/go#32810

Change-Id: I0a520cf91bbe933c9afb76d0842f5556ac4e5b28
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184257
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-01 19:36:37 +00:00
Suzy Mueller
58bb5bbe30 internal/lsp: find references in test packages
Find references to identifiers in both a package and its test package.

Change-Id: I9d9da4aa37c36c448336aed044df79cfd1c903f1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183990
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-01 19:17:42 +00:00
Rebecca Stambler
e750c417fb internal/lsp: handle the context.only parameter for code actions
This change refactors code actions to handle the Context.Only parameter,
which indicates which code actions a language server should execute.

Change-Id: Iddfccbbeba3a53fde2aa8df844434f2ab9d01666
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184158
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-01 18:53:50 +00:00
Muir Manders
30f1cf78d7 internal/lsp: improve completion support for type conversions
Now when completing in code like:

foo := int64(<>)

we prefer candidates whose type is convertible to int64.

Change-Id: Iadc6cdc7de097ac30d8807d6f5aa21d83f89d756
GitHub-Last-Rev: a86dd72496ba752a1f20877c0594ec6a0ed8160e
GitHub-Pull-Request: golang/tools#127
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183941
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-01 17:57:14 +00:00
Rebecca Stambler
970b2b065d internal/lsp: fix bug where gopls hangs on manually typed imports
Fixes golang/go#32797

Change-Id: I0d2975561035c3ac5f5cd460ecdee452c2f6a17f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184258
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-07-01 17:55:09 +00:00
Rebecca Stambler
fb37f6ba82 internal/lsp: fix deadlock in type-checking
There was a situation where we were trying to re-acquire a lock that was
already held. This change solves this issue.

Change-Id: I97cf6bad7e7c219a267e3ca5d174a2573f70ebe2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184217
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-28 22:25:27 +00:00
Rebecca Stambler
59bec04229 internal/lsp: clear diagnostics for files on close, even with errors
Change-Id: I7230d560c57455c53200f4d8f2702fbbdd3f5e51
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184162
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-28 20:33:36 +00:00
Suzy Mueller
6cfa55603c internal/lsp: check ident exists for comment rename
The identifier in a reference is used to check for a doc comment.
Implicits do not have an ident, so do not use that to look for a doc
comment.

Also set the context.Context for the renamer.

Change-Id: I085d9e6c11d919222592dcb6fb30982eeb0fc7cd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184042
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-28 17:52:03 +00:00
Rebecca Stambler
86796bd73f internal/lsp: update version
Change-Id: Ic56ff917846589f12c4c214ea1ac19eac45b187e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184167
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-28 16:54:56 +00:00
Rebecca Stambler
af4a5fc627 internal/lsp: fix bug in missing imports tracking
Change-Id: Iaba7e9cd8a8fb54f8e78f52afa0ef98790288c93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184161
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-28 16:38:22 +00:00
pjw
6cdbf07be9 internal/lsp: new requests.ts to generate new versions of tsclient.go and tsserver.go
Adjust the output of requests.ts to use the new facilities of jsonrpc2.go.

Change-Id: I316f7846db9f683345b836915d992e751f126196
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184081
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-28 15:31:33 +00:00
Rebecca Stambler
212fb13d59 internal/lsp: match completions case-insensitively
Change-Id: I31f2ea338ae3e2ec2837a444705f990e140ebc77
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184159
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-28 03:43:36 +00:00
Rebecca Stambler
94c5763a7c internal/lsp: handle err in formatRange
Change-Id: I4aa2715c7adf541da814cb60dd5205dd6e575b61
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184044
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2019-06-27 22:00:10 +00:00
Muir Manders
4298585011 internal/lsp: provide deep completion candidates
Deep completion refers to searching through an object's fields and
methods for more completion candidates. For example:

func wantsInt(int) { }
var s struct { i int }
wantsInt(<>)

Will now give a candidate for "s.i" since its type matches the
expected type.

We limit to three deep completion results. In some cases there are
many useless deep completion matches. Showing too many options defeats
the purpose of "smart" completions. We also lower a completion item's
score according to its depth so that we favor shallower options. For
now we do not continue searching past function calls to limit our
search scope. In other words, we are not able to suggest results with
any chained fields/methods after the first method call.

Deep completions are behind the "useDeepCompletions" LSP config flag
for now.

Change-Id: I1b888c82e5c4b882f9718177ce07811e2bccbf22
GitHub-Last-Rev: 26522363730036e0b382a7bcd10aa1ed825f6866
GitHub-Pull-Request: golang/tools#100
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177622
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-27 18:58:03 +00:00
Rebecca Stambler
9947fec5c3 internal/lsp: modify check for a missing package
Trying again. Apparently it's useful to run tests before submitting
code.

Change-Id: I487ffd391663cba47d2b26e8346cc7ac589dcd1a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184041
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-27 18:28:18 +00:00
Edward Muller
1a55b1581c internal/lsp/source: move the common path to the left
As per the following guidance: "Try to keep the normal code path at a minimal indentation"

I know this is normally applied to error handling, but the same logic about improving readability applies here too.

Change-Id: Ib20dae9975e94b40fb6ff7049782375b18ef59ba

Change-Id: Ib20dae9975e94b40fb6ff7049782375b18ef59ba
GitHub-Last-Rev: 97919272de76ec15845556e032985c5969a277fa
GitHub-Pull-Request: golang/tools#125
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183698
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
2019-06-27 17:56:40 +00:00
Rebecca Stambler
ba023a1bc9 Revert "internal/lsp: modify check for a missing package"
This reverts commit 55ee3a4131.

Reason for revert: <forgot to run trybots>

Change-Id: I6d0890e2514841244a2a1f8ca861107c5de1f8aa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184040
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2019-06-27 17:28:06 +00:00
Rebecca Stambler
55ee3a4131 internal/lsp: modify check for a missing package
This change moves from marking a package with `go list` errors as
missing, to marking a package with no files as missing.

Change-Id: Ibad1e67518d8a7f4c4bde416c53ab8132ae534e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184039
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-27 17:23:46 +00:00
Rebecca Stambler
043e3d946a internal/lsp: fix race condition in type-checking
There has been a race condition that occasionally appears in test runs
on TryBots. Multiple threads perform type-checking, so they may race on
setting the fields of the *goFiles. Add a mutex to synchronize this.

Change-Id: If52c9d792c6504fc89044964998b06de7dfbd19c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183978
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-27 17:21:04 +00:00
Ian Cottrell
619de4ed67 internal/jsonrpc2: refactor to enable a more advanced request
This separates hides the wire structures, and then exposes a new Request
type to allow for it to carry advanced features.
It also embeds the connection into the request and changes the signature of the
handler to no longer require a separate Conn argument.

Change-Id: I20b54f146285f7a9cb5f279c6ebdf0f286f4b829
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183717
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-27 03:33:22 +00:00
Muir Manders
47ea21585c internal/lsp: propagate context.Canceled when type checking
typeCheck() was swallowing context.Canceled errors and leaving the
cached package in a bad state. In particular, after two rapid changes
to imports I was left in the "no package for file" error mode until I
change my imports again. The second change canceled the first change
which ended up sticking a skeleton *pkg in the package cache instead
of propagating the canceled error.

Change-Id: I15b072188c3359d9cd1812bd49e72548ba214250
GitHub-Last-Rev: 240f61718fbb5bfc787bbfaaaae1d38925d7c405
GitHub-Pull-Request: golang/tools#126
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183940
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-26 23:41:52 +00:00
Muir Manders
5d636af2a9 internal/lsp: improve completion support for type assertions
In type assertion expressions and type switch clauses we now infer the
type from which candidates must be assertable. For example in:

var foo io.Writer
bar := foo.(<>)

When suggesting concrete types we will prefer types that actually
implement io.Writer.

I also added support for the "*" type name modifier. Using the above
example:

bar := foo.(*<>)

we will prefer type T such that *T implements io.Writer.

Change-Id: Ib483bf5e7b339338adc1bfb17b34bc4050d05ad1
GitHub-Last-Rev: 965b028cc00b036019bfdc97561d9e09b7b912ec
GitHub-Pull-Request: golang/tools#123
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183137
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-26 23:33:08 +00:00
Michael Matloob
e8e6be9f45 internal/lsp: plumb suggested fixes through the LSP
Change-Id: Ia9e077e6b9cf8a817103d90481768ae99409c574
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183264
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-26 21:02:18 +00:00
Rebecca Stambler
7ef8a99cf3 internal/lsp: enable incrementalSync by default
This change also leaves in an opt-out setting (noIncrementalSync), just
in case we need to disable it at some point.

Change-Id: I3575efe942294b764c35d9259ce75d124b590e98
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182468
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-26 20:40:24 +00:00
Rebecca Stambler
cd2ed857af internal/lsp: fix panic in computing file version
Fixes golang/go#32791

Change-Id: I04fc3de5ed94137424a32f3e7200ba72d3913329
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183984
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-06-26 19:26:56 +00:00
Edward Muller
d1f656545b internal/lsp/source: don't panic compiling regex
This package is basically a library (even though it's internal) and
it's generally considered a bad practice for libraries to panic, so
don't.

Change-Id: I37d9d73ae48ececc6b31436f1076e1f85213f129

Change-Id: I37d9d73ae48ececc6b31436f1076e1f85213f129
GitHub-Last-Rev: 453b538e53e48889171d31829af3304409f9a8bc
GitHub-Pull-Request: golang/tools#124
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183680
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2019-06-26 18:09:17 +00:00
Rebecca Stambler
3cbd95df51 internal/lsp: support a file belonging to multiple packages
This change adds supports for a package belonging to multiple files.
It requires additional packages.Loads for all of the packages to which a
file belongs (for example, if a non-test file also belongs to a package's
test variant).

For now, we re-run go/packages.Load for each file we open, regardless of
whether or not we already know about it.

This solves the issue of packages randomly belonging to a test or not.
Follow-up work needs to be done to support multiple packages in
references, rename, and diagnostics.

Fixes golang/go#32791
Fixes golang/go#30100

Change-Id: I0a5870a05825fc16cc46d405ef50c775094b0fbb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183628
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-26 17:56:19 +00:00
Rebecca Stambler
252024b829 internal/lsp: separate refactorings out of memoization CL
This change just separates minor changes made along the course of the
memoization CL out into their own change. This will clean up the diffs
in the memoization CL.

Change-Id: I7d59e05ba6472af5f1bf516b1e5b879a5815b9a5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183250
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-25 16:04:30 +00:00
Ian Cottrell
64633d5e86 internal/lsp: add telemetry stubs
This is designed to provide a compatible API to opencensus libraries while we
still cannot directly depend on it.
Most of this will be deleted again when we move the code over into the
sub-module.

Change-Id: I42b561f4f403c18cd22fb909b037f584ea90ad1b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183247
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-24 18:10:36 +00:00
Suzy Mueller
70d37148ca internal/lsp: update doc comments on rename
Replace doc comment text for the declaration of an identifier with the
new name.

This implementation is taken from golang.org/x/tools/refactor/rename.

Change-Id: Id1b80fad456646a46c8ae2caa4e8febf05aaf798
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183261
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-24 18:02:13 +00:00
Rebecca Stambler
6e04913cbb internal/lsp: fix bug in creating token.Files
Change-Id: Ib133762b6848d78fd3d264b211b44b36316a551d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183260
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-21 19:58:16 +00:00
Suzy Mueller
1fa568393b internal/lsp: check for conflicts on rename
Before renaming a variable, check the package to make sure that this
renaming would not result in a conflict that could break the program.

All of the implementation is taken from "refactor/rename" with the
dependency on "go/loader" removed.

Change-Id: Ib0782ec8f247a6df1750f2c8213f69186699ce1a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183257
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-20 19:17:50 +00:00
Suzy Mueller
494e18b268 internal/lsp: send client expected rename provider
This change sends the expected boolean value for 'renameProvider'
to the client.

When a client does not send 'prepareSupport' in its initial
'initialize' request, the client expects to get a boolean value for
'renameProvider'. Since we do not yet provide prepare support, we just
set 'renameProvider' to true regardless of the value of prepareSupport.

Fixes golang/go#32703

Change-Id: I1103e51e1a2927b98aaedf2839996e9cd7f7cbcc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183259
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-06-20 18:21:41 +00:00
Muir Manders
431033348d internal/lsp: fix function value completions
Previously we would always expand *types.Func completion candidates to
function calls, even if the expected type matched the function itself,
not its return value. Now we check the function itself before we check
its return value. This fixes cases like this:

func foo() int { return 0 }
var f func() int
f = <foo> // now completes to "foo" instead of "foo()"

Also, *types.Var function values were never getting expanded to calls.
I fixed the completion formatting to know that both *types.Func
and *types.Var objects might need to be invoked in the completion
item. This fixes cases like this:

foo := func() int { return 0 }
var i int
i = <foo()> // now completes to "foo()" instead of "foo"

Change-Id: I8d0e9e2774f92866a3dd881092c13019fb3f3fd5
GitHub-Last-Rev: 7442bc84b5bbb86296289bbc745ec56a5f89d901
GitHub-Pull-Request: golang/tools#122
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182879
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-20 15:43:39 +00:00
Suzy Mueller
4adf7a708c internal/lsp: add identifier renaming
This change provides support to rename identifiers within a single
package.

The renaming is performed by finding all references to an identifier,
and then creating text edits to replace the existing text with the
new identifier.

Editing an import spec is not supported.

Fixes #27571

Change-Id: I0881b65a1b3c72d7c53d7d6ab1ea386160dc00fb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182585
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-19 21:54:42 +00:00
Muir Manders
22e91af008 internal/lsp: apply type modifiers to completion candidate
In situations like:

var buf bytes.Buffer
var w io.Writer = &b<>

if we want to complete to "buf" properly we need to apply the "&" type
modifier to buf's type of bytes.Buffer to see that it is assignable
to type io.Writer. Previously we applied type modifiers in reverse to
the "expected" type (io.Writer in this case), but that is obviously
incorrect in this situation since it is nonsensical to
dereference (the reverse of "&") io.Writer.

Change-Id: Ib7ab5761f625217e023286384c23b8c60e677aac
GitHub-Last-Rev: 4be528f2572c9c987334552e3f8a31d4eddce81a
GitHub-Pull-Request: golang/tools#121
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182598
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-19 20:27:14 +00:00
Suzy Mueller
b76e30ffa0 internal/lsp: fix references for type switch vars
Implicit local variables for type switches do not appear in the Uses
map and do not have objects associated with them.  This change
associates all of the different types objects for the same local type
switch declaration with one another in the declaration.

The identifier for the implicit local variable does not have a type but
does have declaration objects.

Find references for type switch vars will return references to all the
identifiers in all of the case clauses and the declaration.

Fixes golang/go#32584

Change-Id: I5563a2a48d31ca615c1e4e73b46eabca0f5dd72a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182462
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-19 18:18:01 +00:00
Michael Matloob
8b2b8cf54a internal/lsp: add a field on the package to store diagnostics
So we can surface their code actions later.

Change-Id: I735e5d025a1250861d49db227f5a79453f599140
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182837
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-19 16:20:43 +00:00
Henry Wong
bf5f34bf87 internal/lsp: remove the redundant Server.Run() call.
`go s.Run(ctx)` repeats `h(s)`.

Change-Id: I03ae6df64ad34194b8f46aabd0cf67e5a9e8c777
GitHub-Last-Rev: 3669875d72a196a8c84fb1709a7cf9f84fdbb688
GitHub-Pull-Request: golang/tools#105
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179297
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-19 15:21:02 +00:00
Rebecca Stambler
04b924abaa internal/lsp: enable textDocument/didSave notifications
The previous change to handle didSave never actually was turned on
because you need to specify it in the server capabilities.

Change-Id: I5ce40b4270eda125e0af6accf144d2a96070238c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182777
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-18 23:32:49 +00:00
Ian Cottrell
ab136c9d47 internal/lsp: switching debug pages to not use the default mux
Change-Id: I270fd1d4d44986aed6655da93e7388628f7b8b9c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182467
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-18 23:29:48 +00:00
Rebecca Stambler
fdf1049a94 internal/lsp: determine diagnostics to show per-file, not per-package
Previously, if any one file in a package had a parse error, we would not
send type errors for any of the other files. Now we make this decision
per-file, so that, even if a file has parse errors, type errors in the
other files will be shown.

Fixes golang/go#32596

Change-Id: I086c04f0ec37cd1b33845153328faf368232d834
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182466
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-18 16:30:18 +00:00
Muir Manders
da514acc47 internal/lsp: suggest completions that satisfy interfaces
When checking if a completion candidate matches the expected type at
the cursor position, we now use types.AssignableTo instead of
types.Identical. This properly handles cases like using a concrete
type to satisfy an interface type.

Calling AssignableTo triggered some crashes related to the fake
"resolved" types we create. Their underlying type was nil, which is
not allowed. We now set their underlying type to the invalid type.

I've also rearranged things so expected type information lives in a
dedicated typeInference struct. For now there is no new information added,
but in subsequent commits there will be more metadata about the
expected type.

Change-Id: I14e537c548960c30e444cf512a4413d75bb3ee45
GitHub-Last-Rev: 7e64ebe32938562648938d7a480195d954b018f2
GitHub-Pull-Request: golang/tools#116
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182358
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-17 19:08:20 +00:00
Edward Muller
7653e6d3d5 internal/lsp/cache: fix ineffectual err assignment
The `if err :=` block creates a shadow err value that is then discarded
after the block.

Change-Id: I78f6a7298ac5d3d86ece056a9e328bcee9fdc683

Change-Id: I78f6a7298ac5d3d86ece056a9e328bcee9fdc683
GitHub-Last-Rev: 4bac8fb982fa3a0724206422b1a4dbc5e41c34a9
GitHub-Pull-Request: golang/tools#114
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181777
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-17 16:34:45 +00:00
linguohua
97de5656fd internal/lsp/diff: remove redundant memory allocate and copy operations in function 'shortestEditSequence'.
These redundant operations can cause more memory and cpu consumption.

Change-Id: I54e0e23a8d1079c7991f55c897c441566c5fb2d8
GitHub-Last-Rev: 13162aa1e88ff272738c6a6675010edd2140c8a4
GitHub-Pull-Request: golang/tools#120
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182478
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-17 16:22:25 +00:00
Rebecca Stambler
5aca471b1d internal/lsp: clear diagnostics when all files from a package are closed
This change clears diagnostics for a package when all files from that
package have been closed in the editor. This prevents the user from
seeing irrelevant diagnostics.

Change-Id: I63d337805835dc45086cfba684d810f86ade5655
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182463
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-14 20:56:25 +00:00
Edward Muller
6f0482744c internal/lsp/cache: fix nil check by adding missing "continue"
Without this accessing gof.ast.file.Pos() will panic if gof.ast.file is nil

Change-Id: I829f3667d201f026fcf0475f4fdabce0aced58f8

Change-Id: I829f3667d201f026fcf0475f4fdabce0aced58f8
GitHub-Last-Rev: 777c015d691bf0d14cab5bb0bca6749cc9bdf605
GitHub-Pull-Request: golang/tools#119
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182420
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-14 20:25:48 +00:00
Rebecca Stambler
9a3b5d688f internal/lsp: parse filenames only out of go list errors
This changes the packageErrorSpan function into the listErrorSpan.
Previously, this was causing the gopls-generated errors to get parsed,
which would result in attempts to send diagnostics for invalid filenames.

Fixes golang/go#32603

Change-Id: I7a54ed8884b78beb3f894598f18a24ed232f7412
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182460
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-14 19:27:58 +00:00
Rebecca Stambler
61e0f78580 internal/lsp: use the memoize package to get *token.Files
This change does not actually use the token handle for GetToken right
now, but implements the approach for memoizing *token.Files.

Change-Id: I75919f4e97abd6893b202c021adecd2c9dbfc2be
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182277
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-14 19:20:18 +00:00
Ian Cottrell
a82f0323a4 internal/lsp: block rather than reject when the message queue is full
Change-Id: Ic8d4a0a4abfed71fe9290e9aae4efd6ab55124d5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182458
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-14 18:56:17 +00:00
Rebecca Stambler
d1d6cdd8a6 internal/lsp: clear out missing imports set when we re-load package
This change ensures that we always populate a new set of missing imports
when we re-load a package. Otherwise, we might keep stale missing
imports around.

Change-Id: Id9b6b8201e3ed093a7b9ece97a81e298de612a5e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182459
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-14 18:46:33 +00:00
Ian Cottrell
1edc8e83c8 internal/lsp: update analysis runner for new features
This adds support for the AllObjectFacts and AllPackageFacts features that were
added to the analysis library.
It also moves the list of analyzers to an exported global so it can be added to
easily.

Change-Id: Ibbe81b17b190d04a0e49510c23558430bc03ca70
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182177
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-06-14 15:20:01 +00:00
Peter Weinberger
027b3b4d7b internal/lsp/protocol: bring the code generating programs up to date
This is the typescript code that generates the current versions of
tsprotocol.go, tsserver.go, and tsclient.go.

Change-Id: If40cd7a46e5e7d646d99670da5e04831b6ddc222
Reviewed-on: https://go-review.googlesource.com/c/tools/+/180477
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-13 13:40:55 +00:00
Ian Cottrell
10539ce303 cmd/gopls: preparing for v0.1.0
Change-Id: I6b749858cbba0ec300caa77426ba0ae69a97677d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181997
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-12 23:17:17 +00:00
Rebecca Stambler
59534d075a internal/lsp: use ids instead of package paths as map keys
This adds an IDs map to the metadata cache, which maps package paths to
IDs. This is only ever used by the Import function in the type checker.

Change-Id: I8677d9439895bc6cbca5072e3fa9fddad4e165d5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181683
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-12 18:00:59 +00:00
Koichi Shiraishi
028e009f40 internal/lsp: fix typo on license year
Change-Id: I3cd4a55c633fd7a154d35fd3669e13562295242b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181897
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-06-12 17:47:02 +00:00
Rebecca Stambler
7db4ac6d26 internal/lsp/debug: add newlines to debug messages
Change-Id: Ie8232bf857b8a277abb789e3788a6b6e12048731
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181938
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-12 17:36:44 +00:00