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

139 Commits

Author SHA1 Message Date
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
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
Paul Jolly
ce1a3806b5 internal/lsp: send void client response to client/registerCapapbility
Following CL 179157, client/registerCapapbility and
client/unregisterCapapbility are both (void) requests, not
notifications. Hence the client must send a response, else the server
will wait forever.

Fixes golang/go#32322

Change-Id: I77969317465c0c31fb29d27519d655712d8c3c2a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179359
Reviewed-by: Peter Weinberger <pjw@google.com>
2019-05-30 18:43:49 +00:00
Peter Weinberger
d238219cc2 internal/lsp: client/registerCapapbility is a request, not a notification
Although they have null responses, client/[un]registerCapability messages
are RPCs from golps to the editor, not notifications.
(This bug had unknown impact.)

Change-Id: I3be2eb30b46f937b8ec29d1668f682b797d84be9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179157
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-28 15:12:38 +00:00
Peter Weinberger
991f294999 internal/lsp: remove SelectionRange and textDocument/selectionRange
These are the latest changes to vscode-languageserver-node brought to Go.

Change-Id: I88d0b384356964c358cb2c51ea3b79cb6b51b434
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178357
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-24 12:55:31 +00:00
Rebecca Stambler
9558fe4a78 internal/lsp: update column mapper with content on incremental changes
Fixes golang/go#32114

Change-Id: If2ffade3d8d1e026e3b0aa7f2c9db4dc46d7c8b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178157
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-20 19:04:59 +00:00
Evan Digby
d88f79806b internal/lsp: fix swallowed package errors
If a package has an error that makes it completely unparseable, such as containing a .go file with no "package" statement, the error was previously unreported. Such errors would manifest as other errors.

Fixes golang/go#31712

Change-Id: I11b8d0e2e4d64b03fbcb4c35e7f0b02fccc83fad
GitHub-Last-Rev: 1581cbe36c269dd964f0b9226dbd63b1650c2a5b
GitHub-Pull-Request: golang/tools#102
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177605
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-17 18:33:31 +00:00
Peter Weinberger
8696927a28 internal/lsp: respond to shutdown requests and add DO NOT EDITs
Partly fixes golang/go#31333 (responds to shutdown request, but does
not reject later requests)
Fixes: golang/go#31375 by adding DO NOT EDIT comments to tsclient.go,
tsserver.go, and further details in the package doc in tsprotocol.go,
following the rule in golang/go#13560

Change-Id: I412e3dc6661373b8b70cdd15a385ad7bbd55a897
Reviewed-on: https://go-review.googlesource.com/c/tools/+/176921
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-13 17:21:55 +00:00
Peter Weinberger
08ecc9edd9 internal/lsp: generate RPC interface from Typescript source
The generated code adds some server methods that are unsupported, but were
prviously unimplemented, and makes small adjusments to some parameter types.

Change-Id: I3dd32cafa3e457193f0771e0f8e150c88b381c82
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173420
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-30 16:16:08 +00:00
Koichi Shiraishi
61c0d37527 internal/lsp: fix typo on 'textDocument/foldingRange' method
LSP specification define 'foldingRange', not 'foldingRanges'.
Just trims end of 's' and rename interface method name.

ref: https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md#folding-range-request-leftwards_arrow_with_hook

Change-Id: Ie2a91f6c0bdd99b8ae9000ba87c24118b264b934
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173079
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-22 18:44:13 +00:00
Rebecca Stambler
a5870b4038 internal/lsp/protocol: add a compare function for span.URI
Add an additional check to handle URI comparisons. This fixes Hover on
Windows.

Change-Id: Ibfc816f1ec374144377a873c5b52867fafa3d7e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172659
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-17 22:30:02 +00:00
Rebecca Stambler
34437f544f internal/lsp: refactor server.go to separate into LSP categories
This change separates the different behaviors of server.go by the
categories defined in the spec. This allows us to differentiate more
easily between the language features and the text synchronization code.

I also renamed the "Symbols" function to "Symbol", which fits with the
specification
(https://microsoft.github.io/language-server-protocol/specification#workspace_symbol),
and makes clearer the distinction between DocumentSymbols and Symbol.

Change-Id: I926b8a772c478f6ae426352fb12dc4403f0e736a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172637
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-17 20:54:51 +00:00
Rebecca Stambler
6149f385e4 internal/lsp: reply to shutdown request
Fixes golang/go#31333

Change-Id: I5cb40baee49c4b1644df5612c977ab1d71942022
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172639
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-17 20:25:44 +00:00
Ian Cottrell
7b3e515a8c internal/lsp: switch completion item tests to using the enum strings
Also change the enum values to match the prior string conversion routine.

Change-Id: I23ac6a72c8e116c5ee05e9324356481e519781e9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172410
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-17 17:57:43 +00:00
Ian Cottrell
e528388d46 internal/lsp: Add to and from string handling for the enums
This is to help with debugging, and to allow us to write tests that do not
rely on hard coded constants.

Change-Id: Ica9ed5eee3d35539fe50d76276988852e62b81ca
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172401
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-16 21:24:01 +00:00
Peter Weinberger
04e50493df cmd/gopls: fix incomplete ClientCapabilities struct
go.ts, the program that generates Go types for the LSP protocol, now
handles Typescript type merging for ClientCapabilites, so fields are no
longer missing. Also, to silence go lint and go vet there are changes
in the comments generated in tsprotocol.go. All the *structs were changed
to structs in ClientCapabilities as it was absurdly complex to write literals
of the type. Finally, several otherwise unused types are no longer
generated.

Change-Id: If414a32bc4d733adb2cf8befda9d8a0703c568a6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/171026
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-09 15:09:02 +00:00
Ian Cottrell
12dd9f86f3 internal/lsp: remove defunct copy of the LSP protocol
Change-Id: I1cf3f670a3ca0fd9af18a3889ce5ad3d4128e002
Reviewed-on: https://go-review.googlesource.com/c/tools/+/171028
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-08 17:02:12 +00:00
Ian Cottrell
c5ac96b4c4 internal/span: span to protocol needs position as well as offset
Change-Id: I4f39abb5932a951b2e5fa0932f478b00138e626a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170186
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-02 16:07:49 +00:00
Ian Cottrell
5d16bdd7b5 internal/lsp: add the ability to log back to the client
Also use it for errors that were otherwise silently dropped
This makes it much easier to debug problems.

Also added command line control over whether the rpc trace messages are printed, which allows you to read the
log, otherwise the file edit messages swamp the log.

Change-Id: I7b70fd18034a87b2964e6d6d5f6f33dcaf7d8ea8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170178
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-01 16:22:08 +00:00
Rebecca Stambler
a96101f168 internal/lsp: add a work-around for golang.org/issue/31090
Change-Id: I6be1a61bc0b573913ef86b7a47e9f71d036f84e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170011
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-29 22:58:45 +00:00
Ian Cottrell
0ec5c269d4 internal/lsp: clean up the confguraton handling
Now the jsonrpc2 library allows you to call outgoing methods within a handler
we can clean up some stuff and also have it work correctly in more cases.

Change-Id: I8633069816d92f7cc16842431775efb1a98a506a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170008
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-29 20:00:12 +00:00
Ian Cottrell
a8f40b3f4d internal/jsonrpc2: split main loop from construction to fix race
This changes the basic API of a jsonrpc2 connection to run the
read loop as a method rather than in a go routine launched in
the NewConn. This allows the handler to be created and bound
between construction and the read loop starting, which fixes
the race.

Fixes golang/go#30091

Change-Id: I8201175affe431819cf473e5194d70c019f58425
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170003
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-29 19:31:51 +00:00
Ian Cottrell
2f43c6d1a2 internal/span: change to private fields
Change span to hide its fields and have validating accessors
This catches the cases where either the offset or the position is being used
when it was not set.
It also normalizes the forms as the API now controls them, and allows us to
simplify some of the logic.
The converters are now allowed to return an error, which lets us cleanly
propagate bad cases.
The lsp was then converted to the new format, and also had some error checking
of its own added on the top.
All this allowed me to find and fix a few issues, most notably a case where the
wrong column mapper was being used during the conversion of definition results.

Change-Id: Iebdf8901e8269b28aaef60caf76574baa25c46d4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167858
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-15 18:05:47 +00:00
Ian Cottrell
dbad8e90c9 internal/lsp: convert to the new location library
This rationalises all the position handling and conversion code out.
Fixes golang/go#29149

Change-Id: I2814f3e8ba769924bc70f35df9e5bf4d97d064de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/166884
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-13 19:34:21 +00:00
Peter Weinberger
0bb0c0a6e8 tools/internal/lsp/protocol: generate LSP protocol types from source
The existing code implementing the jsonrpc LSP (language server protocol)
relies on hand-translated definitions for the needed Go data types.
Unfortunately Microsoft makes changes, not always backwards
compatibly. This code generates the Go data types directly from the
Typescript source.

Adapting gopls to the new data definitions will happen in a future CL.

Change-Id: I032c69a16b6f2614370765dcd6dbdb38e9f40ab6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/166277
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-12 15:15:45 +00:00
Peter Weinberger
6a988fd03a tools/cmd/gopls: modify gopls to use automatcally generated types
Gopls presently uses hand-coded data types (in internal/lsp/protocol)
for communicating with LSP clients. Instead, modify it to use the
automatically generated file (internal/lsp/protocol/tsprotocol.go).

Replaced files have been put (temporarily) in a directory 'preserve'
so readers can compare the old data types with the new ones.

Change-Id: Idfa53a5783e2d6a47e03b20641dd76fbc2c32677
Reviewed-on: https://go-review.googlesource.com/c/tools/+/166757
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-12 15:13:52 +00:00
Yasuhiro Matsumoto
a24c58a209 internal/lsp: implement incremental updates to document
gopls return Incremental for TextDocumentSyncKind.

Change-Id: I7b302a540a4d2ef9eaa079cea5155859febb9a95
Reviewed-on: https://go-review.googlesource.com/c/162921
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-21 17:53:26 +00:00
Rebecca Stambler
f3aee3358b internal/lsp: allow ExecuteCommandParams to be nil
The ExecuteCommandParams field is optional, so it can be set to nil.

Change-Id: If440257e6b64ce5189b0a4b39a6ed7fc867da5af
Reviewed-on: https://go-review.googlesource.com/c/162402
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-13 22:34:05 +00:00
Rebecca Stambler
069601f371 internal/lsp: use interface for diagnostics code
Since the diagnostics code can be either a string or a number, use an
empty interface.

Change-Id: Ie1a4183b5c82ef177176075828511070ae3520bd
Reviewed-on: https://go-review.googlesource.com/c/161217
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-05 18:07:22 +00:00
Peter Weinberger
98df4c70be tools/internal/lsp/protocol: add LocationLink type
LocationLink was added in 3.14.0 of lsp.

Change-Id: I388dba5ab43b195cc3965e4199b49155094a2627
Reviewed-on: https://go-review.googlesource.com/c/156617
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-01-09 16:41:58 +00:00
Peter Weinberger
54d1bacb4e internal/lsp/server: fix typo in name of method foldingRange
It should say "textDocument/foldingRange" even though everyone names
the associated function FoldingRanges.

Change-Id: I79c8449a689dc8c80f745c875d9ec9892d926e9c
Reviewed-on: https://go-review.googlesource.com/c/155578
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-21 18:55:09 +00:00
Elias Naur
2b6afc6596 internal/lsp/protocol: use correct JSON name for RootURI
According to the spec,

https://microsoft.github.io/language-server-protocol/specification#initialize

the JSON name of the RootURI field is "rootUri", not "rootURI".

Change-Id: I187be9e517a6c70dabc09de4215326f2555c3f1c
Reviewed-on: https://go-review.googlesource.com/c/153537
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-12-11 20:04:12 +00:00
Rebecca Stambler
fc4f04983f internal/lsp: add more testdata for completion and diagnostics
Change-Id: I2a73e51b60f76a2af0f8ff4d34220b551e0cd378
Reviewed-on: https://go-review.googlesource.com/c/150041
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-20 06:06:34 +00:00
Ian Cottrell
1aef897494 internal/lsp: fix for limitations of export data
It is impossible to reconstruct a line and column correctly from export data, so
we have to attempt to find open and process the file in order to guess what the
original pos was when we have one that originated in export data.
This occurs in any time in go to definition when the target is not in the same
pacakge as the source.

Change-Id: Ib2ee404d4f1c39d8bd7f1fbc2096d8d6cbeed6f8
Reviewed-on: https://go-review.googlesource.com/c/150044
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-19 18:00:18 +00:00
Ian Cottrell
68f7e630ce internal/lsp: make all the tests work on 1.10
Also improve the error messages from a failing diagnostic tests so you can read
them.

Change-Id: I3554ce5a029de22a55a9636ed26ba02d95fc3246
Reviewed-on: https://go-review.googlesource.com/c/150042
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-19 17:55:51 +00:00
Ian Cottrell
8190738e3d internal/lsp: add formatting functions to some common lsp protocol types
These are intended only for debug printing and error messages for the most
common protocol types that you need to know the contents of.

Change-Id: I1f0f7b17b4b12c3b26096b46808bce37c3722ced
Reviewed-on: https://go-review.googlesource.com/c/150037
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-16 18:53:46 +00:00
Ian Cottrell
94339b8328 internal/jsonrpc2: change to a more synchronous dispatch model
Delivering each message in a go routine turned out to be problematic, there are some messages
that must be fully processed before later messages are started, and there was no way to guarantee that.
We now push concurrence handling up to the higher level, this has the disadvantage of not being able to guarantee
we respond to call messages correctly, but its a small price to pay.
The LSP currently processes each message fully in order blocking the handler, while we still work on basic
functionality.

Change-Id: If0648c77713ddbe4fed69da97a57696f433b8002
Reviewed-on: https://go-review.googlesource.com/c/149497
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-14 19:09:51 +00:00
Rebecca Stambler
6f4a86804e internal/lsp: add implementation of completion to LSP
Add an autocompletion implementation to the LSP. Also, add a function
that type-checks a package at a certain position, returning an *ast.File
and token.Pos for querying completion.

Change-Id: I288d4e6ed168e6014e79a4436f31f5b4a99b7139
Reviewed-on: https://go-review.googlesource.com/c/147657
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-06 21:04:51 +00:00
Ian Cottrell
ff3f684ce0 internal/lsp: the core lsp protocol
This is not intended to be a user friendly package, just the rawest correct
implemenation of the protocol as a building block

Change-Id: Ib672b7f1e2fd8284be422dc7964f1876e94c9578
Reviewed-on: https://go-review.googlesource.com/136676
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-09-25 15:17:08 +00:00