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

930 Commits

Author SHA1 Message Date
Rebecca Stambler
a4e9122f10 internal/lsp: fix regression from CL 179439
Fixes golang/go#32378

Change-Id: I7c5b794ba6137084a56e3e7bf8027a6f65819b34
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179919
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-03 19:23:55 +00:00
Rebecca Stambler
178e83bc9d internal/lsp: build the builtin package preemptively
This change fixes a regression introduced by the building the builtin
package on demand. Although this change increases the startup tasks of
gopls, it is necessary to ensure that we ignore diagnostics from
builtin.go.

Change-Id: I897e747a273056d70cecba486a74c75a736d8f80
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179921
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-03 18:19:26 +00:00
Ian Cottrell
37dc81f201 internal/lsp: add memory debugging page
Display the memory statistics provided by the runtime package.

Change-Id: I3ae9c51a847fc1808c15faaadbbdc7a4874c11f0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179517
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-03 17:43:05 +00:00
Ian Cottrell
df5f646307 internal/lsp: debug pages for sessions views and files
Change-Id: Id21f391bd66513615d274588ce7d1d1efe407074
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179438
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-03 17:39:32 +00:00
Ian Cottrell
08e0b306e8 internal/lsp: move PrintVersionInfo to the debug package
Also add a new rendering mode, and clean up the plain text one.
Then use it to add an info page to to the server in debug mode.

Change-Id: Ifa66a75260965d0e46e874200203ebbc4490e424
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179497
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-03 15:29:06 +00:00
Edward Muller
26e35f15ed internal/lsp/cache: fix leaking wg.Done() and <-ioLimit
There were several returns in this function that could leak both the
wg.Done() and <-ioLimit. This refactors them into defers close to their
counterparts.

Additionally I refactored the function to favor early returns over
nested if statements.

Fixes golang/go#32368

Change-Id: I5357d11ee526c1cb7a6bd1a0f652c61d574c10ab
GitHub-Last-Rev: bfa160b9fd75c4464d2e0a2820c04ddae01de21f
GitHub-Pull-Request: golang/tools#107
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179878
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
2019-05-31 22:35:38 +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
Michael Matloob
2b03ca6e44 go/analysis: add an End field to Diagnostic
This will allow diagnostics to denote the range they apply to.
The ranges are now interpreted using the internal/span library.

This is primarily intended for the benefit of the LSP, which will
be able to (in future CLs) more accurately highlight the part
of the code a diagnostic applies to.

Change-Id: Ic35cec2b21060c9dc6a8f5ebb7faa62d81a07435
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179237
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-30 17:14:27 +00:00
Rebecca Stambler
12d7342421 internal/lsp: refactor to separate pieces of type-checking
Change-Id: Idab49286e59803e4ae0f749eb9f2990b611ea689
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179439
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-30 04:37:10 +00:00
Ian Cottrell
b97706b7f6 internal/lsp: add debug page serving
This adds a framework for gopls server debugging pages, and adds the standard profiling pages to it.

Change-Id: Ie319e4ad070ac41b2ae7791cb3e0e5bb4ae12ef4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179277
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-30 00:16:15 +00:00
Rebecca Stambler
d850aa06e8 internal/lsp: fix setting overlays in tests
This change fixes the test failure that has appeared in a few TryBot
runs.

Change-Id: If583555250d63b7f446ec7d8eb09810b842633ae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179437
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-29 19:11:38 +00:00
Rebecca Stambler
aa71c3f324 internal/lsp: set env to os.Environ to start
Change-Id: Ia3952f76918957eba46f8ba2c616f14f424ff4b3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179221
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-29 01:04:54 +00:00
Rebecca Stambler
08bd53a4b4 internal/lsp: run analyses despite some errors
Updates golang/go#32247

Change-Id: Id474e62ea70676c782eb49dddebd64d7f274d2cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179218
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-28 20:25:02 +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
Rebecca Stambler
3d17549cdc internal/lsp: add modfile, sumfile structs, require Go files for diagnostics
This change adds a stub modFile struct for use in the future. It also
moves the singleDiagnostic function out into the lsp package, so that
the source package does not make decisions about what to show to the
user as a diagnostic.

Fixes golang/go#32221

Change-Id: I577c66fcd3c1daadaa221b52ff36bfa0fe07fb53
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178681
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-24 21:02:28 +00:00
Rebecca Stambler
d532c0723d internal/lsp: fix race condition in type-checking
Change-Id: Idff7cc3a28b4a03ce0d374c6c5035b51330143b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178724
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-24 20:33:21 +00:00
Ian Cottrell
2c0ae70061 internal/lsp: add file watching and use it to trigger invalidations
Change-Id: I6148539509364655e7d42044b73789870d30fbb6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178161
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-24 14:03:12 +00:00
Ian Cottrell
75713da896 internal/lsp: add a file system abstraction
Change-Id: Ie42835b835ed22fddbba187ab10d8c31019ff008
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178097
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-24 13:48:47 +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
38d8bcfa38 internal/lsp: don't show diagnostics for mod files
The Go file changes didn't actually check the file extensions for the
files the Go extension is receiving. This error was not noticed because
the VSCode extension doesn't yet actually send mod files to gopls yet,
but it will in its next release.

Fixes golang/go#32178

Change-Id: Ia04d0a92ce7df13fcf4c601421bc000d69855f6d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178679
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-23 17:46:34 +00:00
Rebecca Stambler
521d6ed310 internal/lsp: re-run go/packages.Load when the package name changes
Fixes golang/go#32149

Change-Id: Ic02af6fd4fb19aae0d38a4d51ec4462abdc4f446
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178162
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-21 20:35:40 +00:00
Ian Cottrell
7927dbab1b internal/lsp: build the packages config on demand from proper configuration
This moves the fileset down to the base cache, the overlays down to the session
and stores the environment on the view.
packages.Config is no longer part of any public API, and the config is build on
demand by combining all the layers of cache.
Also added some documentation to the main source pacakge interfaces.

Change-Id: I058092ad2275d433864d1f58576fc55e194607a6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178017
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-21 17:12:43 +00:00
Rebecca Stambler
2c78df6d2c internal/lsp: log when we fail to type-check a package
Change-Id: I07a0a224359b698e50da8496b21634d8bd947aa9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178277
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-21 15:28:58 +00:00
Muir Manders
eda2c2f1ae internal/lsp: fix completion insertion with non-identifier suffix
Completions like "foo.Bar(baz.<>)" were replacing one too many
characters resulting in "foo.Bar(baz.Qux()". This is because the go
parser adds a phantom "_" identifier when parsing "foo.". We thought
the "_" was really there, so we were issuing text edits to replace
it. Fix by ignoring "_" selectors when the cursor is positioned to
their left.

Fixes microsoft/vscode-go#2525

Change-Id: I1233a9d6275e2a79b666ca0230862238160b4aab
GitHub-Last-Rev: de9a3f00187b1b9bfcc4e497461f4602ae6f8923
GitHub-Pull-Request: golang/tools#104
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178217
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-20 21:53:15 +00:00
Rebecca Stambler
7e7c6e5214 internal/lsp: add nil checks for ASTs and token
Fixes golang/go#32120
Updates golang/go#32132

Change-Id: Ib4bb8a4818be7dec468c46b72afc3dd57b35f155
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178158
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-20 20:09:54 +00:00
Ian Cottrell
faf83c64e9 internal/lsp: fix race in delivering diagnostics to the command line client
Fixes golang/go#32091

Change-Id: I1399a596169384f48d9f2409988226708dcd3473
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177937
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-20 19:38: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
Muir Manders
f217c98fae internal/lsp: fix completion insertion
The insertion range for completion items was not right. The range's
end was 1 before the start. Fix by taking into account the length of
the prefix when generating the range start and end.

Now instead of a "prefix", we track the completion's
"surrounding". This is basically the start and end of the abutting
identifier along with the cursor position. When we insert the
completion text, we overwrite the entire identifier, not just the
prefix. This fixes postfix completion like completing "foo.<>Bar" to
"foo.BarBaz".

Fixes golang/go#32078
Fixes golang/go#32057

Change-Id: I9d065a413ff9a6e20ae662ff93ad0092c2007c1d
GitHub-Last-Rev: af5ab4d60566bf0589d9a712c80d75280178cba9
GitHub-Pull-Request: golang/tools#103
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177757
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-17 18:32:58 +00:00
Rebecca Stambler
bffc5affc6 internal/lsp: support definitions and hover for builtins
This change adds support for definitions and hover for builtin types and
functions. It also includes some small (non-logic) changes to the import
spec definition function.

Additionally, there are some resulting changes in diagnostics to ignore
the builtin file but also use it for definitions (Ian, you were right
with your comment on my earlier review...).

Fixes golang/go#31696

Change-Id: I52d43d010a5ca8359b539c33e40782877eb730d0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177517
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-17 00:35:10 +00:00
Rebecca Stambler
1a8f2608bd internal/lsp: use ranges instead of positions in completion items
Fixes golang/go#32078

Change-Id: If33cc6f7a914e6ef17d06a34c39dceb61cfa16d4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177657
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-17 00:27:32 +00:00
Ian Cottrell
b9584148ef internal/lsp: add structured layers to the cache
This is primarily to separate the levels because they have different cache
lifetimes and sharability.
This will allow us to share results between views and even between servers.

Change-Id: I280ca19d17a6ea8a15e48637d4445e2b6cf04769
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177518
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-16 21:30:38 +00:00
Rebecca Stambler
abbb706b23 internal/lsp: enable enhanced hover by default
This change removes the explicit configuration for improved
documentation on hover. We use a comment's synopsis rather than the full
comment.

However, we also add a "noDocsOnHover" setting that is used by the cmd
tests. Ultimately, no one should use this setting and we should remove
it. We leave it temporarily because the cmd tests still need work.

Change-Id: I5488eca96a729ed7edad8f59b95af163903740d6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174378
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-16 17:30:22 +00:00
Muir Manders
e5f21acdc3 internal/lsp: handle more expected type cases
Calculate expected type in the following cases:

- switch case statements
- index expressions (e.g. []int{}[<>] or map[string]int{}[<>])
- slice expressions (e.g. []int{}[1:<>])
- channel send statements
- channel receive expression

We now also prefer type names in type switch clauses and type asserts.

Change-Id: Iff8c317a9116868b36701d931c802d9147f962d8
GitHub-Last-Rev: e039a45aebe1c6aa9b2011cad67ddaa5e4ed4d77
GitHub-Pull-Request: golang/tools#97
Reviewed-on: https://go-review.googlesource.com/c/tools/+/176941
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-16 16:26:11 +00:00
Ian Cottrell
4f9510c6a1 internal/lsp: prepare for non go files
This abstracts out the concrete file type so that we can support non go files.

Change-Id: I7447daa2ce076ec2867de9e59a0dedfe1a0553f5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/175217
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-15 23:59:46 +00:00
Ian Cottrell
0e55654012 internal/lsp: add shutdown handling
We correcly cancel all background tasks and drop all active views when
the server is asked to shut down now.
This was mostly to support the command line being able to exit cleanly

Change-Id: Iff9f5ab51572aad5e3245dc01aa87b00dcd47963
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174940
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-15 23:16:32 +00:00
Rebecca Stambler
7c3f65130f internal/lsp: remove constant value from label and add tests
Fixes golang/go#29816
Fixes golang/go#31923

Change-Id: I4f0ff7941a5d26994ef6bbd10346eafe31160a21
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177357
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-15 19:19:14 +00:00
Rebecca Stambler
473d3dc1d7 internal/lsp: handle additional snippet cases
This change handles the case when a function that has already been
written out is being completed.

Change-Id: I0c4e9ec9bb5a8428526f00a4e62e020bcc30f0bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/176923
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-15 17:48:15 +00:00
Ian Cottrell
ce09bef8aa internal/lsp: reduce the api surface of the cache package
The cache now exposes only one symbol, NewView
This is preparing the cache for a re-write

Change-Id: I411c2cd7a7edc2e7c774218c6786f9fd4fcc53cb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/176924
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-15 16:36:46 +00:00
Rebecca Stambler
707862fa78 internal/lsp: use builtin package for signature help
This change uses the builtin package to derive the signature help for
builtin functions.

Updates golang/go#31696

Change-Id: I458b3a89bdf143e7018e8be7cb6a5e8c068a47c2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/176922
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-15 13:46:40 +00:00
Rebecca Stambler
2196cb7019 internal/lsp: make snippets private fields
Change-Id: I35d883196c7c3b35e14b49c0f5c779a91e72ce42
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177177
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-15 03:55:09 +00:00
Muir Manders
7d7faa4812 internal/lsp: fix missing parens in function call snippet
We were omitting the parens in function completions like "(foo<>)()"
because our check thought "foo" was the Fun in the outer CallExpr so
it already had parens. Fix by tightening up logic to only omit parens
for cases like "foo<>()" and "foo.bar<>()".

Change-Id: Ia602b80275f72baa6cdf6d61c22d3f3a6cfc3019
GitHub-Last-Rev: 41fecf92617e0812ee6552d8c43789eae83889bd
GitHub-Pull-Request: golang/tools#98
Reviewed-on: https://go-review.googlesource.com/c/tools/+/176944
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-15 01:24:06 +00:00
Rebecca Stambler
921b34c7d0 internal/lsp: ignore files in the builtin package
This change stops diagnostics from running in files making up the "fake"
builtin package.

Fixes golang/go#31962

Change-Id: Ic54e1587e3ad54f0c1f5e82f1a6f3522b4c6bee9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177218
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-14 23:09:02 +00:00
Koichi Shiraishi
faff00d7e7 internal/lsp: fix typo on license year
Change-Id: I5643ce049bad0dfb45405c06adc7c2eb46a394ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177017
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-14 17:17:24 +00:00
Rebecca Stambler
2d081dbd58 internal/lsp: fix nil pointer when propagating diagnostics
Fixes golang/go#32030

Change-Id: I5ae7f2dc68c68c1a4851c637dcb75f312b0b35f5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177057
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-14 14:35:49 +00:00
Rebecca Stambler
7d589f28aa internal/lsp: stop trimming prefix from InsertText
After some discussion about how to handle insert and filter text
(https://github.com/microsoft/vscode-languageserver-node/issues/488), it
seems that it is better practice to overwrite the prefix in completion
items, rather than trimming the prefix from the insert text.

Change-Id: I7c794b4b1d4518af31e7318a283aa3681a0cf66a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/176958
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-13 23:30:21 +00:00
Muir Manders
de15caf068 internal/lsp: fix composite literal completion
Fix the following issues:

- We were trying to complete struct literal field names for
  selector expressions (e.g. "Foo{a.B<>}"). Now we only complete field
  names in this case if the expression is an *ast.Ident.
- We weren't including lexical completions in cases where you might be
  completing a field name or a variable name (e.g. "Foo{A<>}").

I refactored composite literal logic to live mostly in one place. Now
enclosingCompositeLiteral computes all the bits of information related
to composite literals. The expected type, completion, and snippet code
make use of those precalculated facts instead of redoing the work.

Change-Id: I29fc808544382c3c77f0bba1843520e04f38e79b
GitHub-Last-Rev: 3489062be342ab0f00325d3b3ae9ce681df7cf2e
GitHub-Pull-Request: golang/tools#96
Reviewed-on: https://go-review.googlesource.com/c/tools/+/176601
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-13 22:24:33 +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
Ian Cottrell
99f201b680 internal/lsp: add some missing copyright notices
Change-Id: Ieba43cfb3637bb50959801ce1226431f77e16e05
Reviewed-on: https://go-review.googlesource.com/c/tools/+/176642
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-11 04:16:17 +00:00
Ian Cottrell
44dd571771 internal/lsp: add version and bug commands
Also log gopls version information on startup in server mode.

Change-Id: If7bf85d19f993430709b1fae83083e6fdfe1b2ca
Reviewed-on: https://go-review.googlesource.com/c/tools/+/175199
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-11 04:16:02 +00:00
Ian Cottrell
90441677ad internal/lsp: suppress info and default logging unless a verbose flag is supplied
Change-Id: Ib4bf2a47cad4151b4b64d922855013b22b4fbb15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/176641
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-11 04:13:52 +00:00
Ian Cottrell
80b1e8742c internal/lsp: support dynamic workspace folder changes
This also required us to change the way we map files to a view, as it may change
over time.

Fixes golang/go#31635

Change-Id: Ic82467a1185717081487389f4c25ad69df1af290
Reviewed-on: https://go-review.googlesource.com/c/tools/+/175477
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-10 21:22:50 +00:00
Ian Cottrell
4ca280b5bd internal/lsp: fix definition tests to use golden files
specifically it uses them for the guru compatability tests
This change radically increases the test coverage of the godef tests as it now
works for all the jump to definition tests not just the specialized ones.

Change-Id: I63547138566ac3de56344dcfddb758ed5f362a06
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174937
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-10 21:06:55 +00:00
Ian Cottrell
0522b6e926 internal/lsp: adding the test suite to the source package
Change-Id: Ia287d84186bccca9e74050528daf809cb0e88c46
Reviewed-on: https://go-review.googlesource.com/c/tools/+/176117
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-10 20:20:41 +00:00
Ian Cottrell
d4e30f1c22 internal/lsp: making cmd tests fast and small
This required extensive changes to the "internal" server handling and also to
the way we wait for diagnostics in the "check" verb.
It improves both memory and time by over an order of magnitude, hopefully
allowing us to renable the tests on the builders

Change-Id: I84e84ca4c449e9970ebf1d922a0a2ce0a8a49c72
Reviewed-on: https://go-review.googlesource.com/c/tools/+/175878
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-10 20:14:07 +00:00
Muir Manders
775b7fe395 internal/lsp: improve expected type determination
Improve expected type determination for the following cases:

- search back further through ast path to handle cases where the
  position's node is more than two nodes from the ancestor node with
  type information
- generate expected type for return statements
- wrap and unwrap pointerness from expected type when position is
  preceded by "*" (dereference) or "&" (reference) operators,
  respectively
- fix some false positive expected types when completing the "Fun"
  (left) side of a CallExpr

Change-Id: I907ee3e405bd8420031a7b03329de5df1c3493b9
GitHub-Last-Rev: 20a0ac9bf2b5350494c6738f5960676cc50fb454
GitHub-Pull-Request: golang/tools#93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174477
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-10 20:11:04 +00:00
Muir Manders
63859f3815 internal/lsp: add definition support for packages
Now the "type" of a *ast.PkgName is the package it points to. Of
course, a package is not a real types.Type, but we can still jump you
there. We have to pick one of the package's files, so we choose the
longest one, hoping it is the most interesting.

Similarly, the "definition" of an *ast.ImportSpec is the package being
imported.

I also added a nil check for the package in SignatureHelp. This panics
for me occasionally.

Change-Id: Ide4640530a28bcec9da6de36723eb7f0e4cc941c
GitHub-Last-Rev: 8190baa0b908065db5b53f236de03d2f3bff39b5
GitHub-Pull-Request: golang/tools#92
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174081
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-10 15:10:30 +00:00
Rebecca Stambler
3eedecdc80 internal/lsp: propagate diagnostics for reverse dependencies
Prior to this change, if a package was rendered invalid by a change in
one of its dependencies, diagnostics would not be propagated until the
user typed in one of the package's files. Now, these updated diagnostics
are sent along with the diagnostics for the dependency.

Fixes golang/go#29817

Change-Id: I4761de31c4bdee820e024005f6112b3b3d2e1da6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174977
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-10 13:52:23 +00:00
Rebecca Stambler
a1c92a4ac6 internal/lsp: add additional error handling for builtin packages
Change-Id: I1a084a47d2f171c6b94bde6fece008cddd547833
Reviewed-on: https://go-review.googlesource.com/c/tools/+/175937
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-10 13:52:03 +00:00
Ian Cottrell
cf84161cff internal/lsp: fix incremental updates and turn them on
Updates that only add text have a start and end that are the same, we were
erroring on those and failing to apply the changes.

Fixes golang/go#31800

Change-Id: Ia31b90f108742e5532d2da35137c347c26090a6a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174949
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-08 15:02:11 +00:00
Ian Cottrell
490d13020f internal/lsp: switch golden files to use txtar
I was about to add some more tests and it caused a huge number of golden files,
which was hard to deal with. Now all the golden files are packed into a single
.golden archive in the txtar format.
I also changed the tagging key for hover results to use the marker name rather
than the line and column, as it makes it more stable against test data changes.

Change-Id: Iaa1f54ab55a41d380db67b9f6f928fa7a52d9a5e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174877
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-08 14:59:27 +00:00
Rebecca Stambler
5658f888b3 internal/lsp: disable rangeFormatting temporarily
RangeFormatting was broken with the introduction of the diff library,
but not noticed until golang/go#31150. Temporarily disable this behavior
until we fix it.

Change-Id: Ie3e50a763e0c0e8672ad20c3a2e37d901325d356
Reviewed-on: https://go-review.googlesource.com/c/tools/+/175938
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-08 13:53:17 +00:00
Ian Cottrell
3b6f9c0030 internal/lsp: add document link handling for import paths to godoc
Change-Id: Ib2eef50047dfcc64110c264e77d648f959613b88
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173698
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-03 18:56:57 +00:00
Ian Cottrell
9cb3dcf692 internal/span: update the offset if the end offset should be valid but is not
It used to be that when the start offset was valid, it was presumed the end was
as well.
This was not true in the case where the start offset was not supplied but could
be inferred (at the very start of the file).

Fixes golang/go#31797

Change-Id: Ie5a079796fa0f77cef5571a4e5b309c798e1e06b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174943
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-03 18:46:43 +00:00
Rebecca Stambler
2346320968 internal/lsp: support builtin types without hardcoding
This change uses an *ast.Package built from the file
go/src/builtin/builtin.go. Completion (and ultimately other features)
will be resolved using this AST instead of being hardcoded.

Change-Id: I3e34030b3236994faa484cf17cf75da511165133
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174381
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-01 04:50:30 +00:00
Ian Cottrell
2d28432af7 internal/lsp: first pass at some hover tests
This uses golden files to hold the hover text as they are no more fragile than
hard coding the text in the tests, and much easier to update.
We need a lot more tests, and ones with actual comments, but this is a start and
at least adds the machienery it would take.

Change-Id: Ia2f79257642759e4c2f972d4037f258134e0fb33
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174380
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-30 19:42:29 +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
Rebecca Stambler
b9fed7929f internal/lsp: change some comments and variable names in completion code
Also, return diagnostics instead of errors from source.Diagnostics (to
avoid stuck diagnostics).

Change-Id: I56b067273982fd086ed74185e50eda5b72b5fba1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174400
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-30 00:41:04 +00:00
Ian Cottrell
35c670923e internal/lsp: clean up formatting header handling
This is mostly to set things up to use golden files the same way for other commands.

Change-Id: I7fcc7165706763e655b0e46f0790b367fe5d3d59
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174018
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-29 18:49:09 +00:00
Rebecca Stambler
f97eea45a1 internal/lsp: handle nil pointer in (*Package).GetActionGraph
Fixes golang/go#31700

Change-Id: I1ee71f65d2bdb2a95b261c4266df64b473d2fda5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174019
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-29 18:40:48 +00:00
Muir Manders
c6e1543aba internal/lsp: add struct literal field snippets
Now when you accept a struct literal field name completion, you will
get a snippet that includes the colon, a tab stop, and a comma if
the literal is multi-line. If you have "gopls.usePlaceholders"
enabled, you will get a placeholder with the field's type as well.

I pushed snippet generation into the "source" package so ast and type
info is available. This allows for smarter, more context aware snippet
generation. For example, this let me fix an issue with the function
snippets where "foo<>()" was completing to "foo(<>)()". Now we don't
add the function call snippet if the position is already in a CallExpr.

I also added a new "Insert" field to CompletionItem to store the plain
object name. This way, we don't have to undo label decorations when
generating the insert text for the completion response. I also changed
"filterText" to use this "Insert" field since you don't want the
filter text to include the extra label decorations.

Fixes golang/go#31556

Change-Id: I75266b2a4c0fe4036c44b315582f51738e464a39
GitHub-Last-Rev: 1ec28b2395c7bbe748940befe8c38579f5d75f61
GitHub-Pull-Request: golang/tools#89
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173577
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-29 17:59:36 +00:00
Rebecca Stambler
550556f78a internal/lsp/source: refactor completion
This change separates the completion formatting functions from the
completion logic. It also simplifies the completion logic by necessary
values per-request into a struct that is used throughout.

Change-Id: Ieb6b09b7076ecf89c8b76ec12c1f1c9b10618cfe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173779
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-28 02:47:24 +00:00
Rebecca Stambler
ad9eeb8003 internal/lsp: handle shadowed variables in lexical completions
Fixes golang/go#31621

Change-Id: I6d5cfde5d5bebc704c9178d40bb93801b255e01c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173958
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-04-25 22:28:32 +00:00
Ian Cottrell
4eab536980 internal/lsp: add the format command line
Change-Id: If7c4135b6b81b4f691d0f5eae8b49a1aca028346
Reviewed-on: https://go-review.googlesource.com/c/tools/+/171031
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-25 22:22:32 +00:00
Rebecca Stambler
079ac3a490 internal/lsp: handle error from runAnalyses
Change-Id: I73062bd3b4db8f238f009b8c8f3786c39c5d0d54
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173957
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-25 22:07:02 +00:00
Muir Manders
e54115a062 internal/lsp: fix stuck diagnostic messages
The "analyses" cache in lsp/cache.(*Package).GetActionGraph was not
getting cleared on errors. This could result in future calls to
GetActionGraph waiting on the "ready" channel indefinitely. This in
turn caused the goroutine in cacheAndDiagnose to block indefinitely
and never send the diagnostic results back.

Now we use a defer statement to always close the channel. If we did
not succeed, we also clear out the cache entry and set a "succeeded =
false" flag to signal waiters that they need to retry. If in the
future errors other than context.Canceled/Timeout are possible, this
retry behavior may need to be revisited.

Fixes golang/go#30786

Change-Id: Icacc9188f1500b00f2178521ce373a2c1363f932
GitHub-Last-Rev: 7c43afd4286a69b0d35a625716e6934c72c4cef5
GitHub-Pull-Request: golang/tools#91
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173977
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-04-25 21:19:06 +00:00
Rebecca Stambler
bb8aefc696 internal/lsp: return errors when we can't find a package
This will allow us to surface these errors as diagnostics.

Change-Id: Ic8ad11ba43c08be6f391c0e2aa95015183461133
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173780
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-04-25 18:52:35 +00:00
Muir Manders
45abd40133 internal/lsp: introduce snippet builder object
*snippet.Builder helps you construct lsp completion snippet strings.
It handles escaping for you, and it gives a convenient interface for
writing nested placeholders.

Note that the builder does not support snippet "variables" or
associated features. They add a lot of complexity and don't seem very
useful at this point (plus they aren't supported in many editors).

Change-Id: I492ab2f6f0e08ed952154cbc0a17c86f32abf40a
GitHub-Last-Rev: 35a3f5d1cd0b6fda81b2c942a02aa1bd25c90acd
GitHub-Pull-Request: golang/tools#90
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173661
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-25 18:37:29 +00:00
Rebecca Stambler
1e8e1cfdf9 internal/lsp: handle completion after defer, go statements
This change adds support for completion of incomplete selectors after a
defer or go statement. We modify the AST before type-checking it with a
fake *ast.CallExpr.

Updates golang/go#29313

Change-Id: Ic9e8c9c49aa569cd7874791692c70a28c3146251
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172974
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-24 22:01:01 +00:00
Muir Manders
3e93b52866 internal/lsp: suppress more completions in comments and literals
Completion suppression in comments wasn't working for comments in
switch case statements, select case statements, and decl statements.
Rather than adding those to the list of leaf ast.Node types to look
for, we now always check if the position is in a comment. This fix
broke some completion tests that were using re"$" since "$" matches
after the comment "//" characters.

We now also don't complete within any literal values. Previously we
only excluded string literals.

Change-Id: If02f39f79fe2cd7417e39dbac2c6f84a484391ec
GitHub-Last-Rev: 7ab3f526b6752a8f74413dcd268382d359e1beba
GitHub-Pull-Request: golang/tools#88
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173518
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-04-24 20:52:08 +00:00
Zac Bergquist
f62e16ca41 internal/lsp: make interface methods children of the interface symbol
Change-Id: I8dbb1400a228ea077f63c2c48f8dba0ac93990d2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173237
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-04-24 02:46:01 +00:00
Rebecca Stambler
e58f34171d internal/lsp: add more error propagation and logging for analyses
This change propagates more errors from analyses, instead of just saving
them in act.err, we actually return immediately. Ultimately, we'd want
to return to the previous behavior, but this will help us figure out
what's going wrong.

Updates golang/go#30786

Change-Id: I9d3288fd113c43775140e5c008e3e300b6d28c2a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173497
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-24 02:44:48 +00:00
Muir Manders
49ba83114e internal/lsp: improve composite literal completion
When the value of a composite literal key/value pair was unparsable,
you were getting completions for the composite literal keys instead of
values. For example "struct { foo int }{foo: []<>" was completing to
the field name "foo". This was because the leaf ast.Node at the cursor
was the composite literal itself, and our go-back-one-character logic
was not happening because the preceding character's node
was *ast.BadExpr, not *ast.Ident. Fix by always generating the ast
path for the character before the cursor's position. I couldn't find
any cases where this broke completion.

I also added expected type detection for the following composite
literal cases:
- array/slice literals
- struct literals (both implicit and explicit field names)
- map keys and values

Fixes golang/go#29153

Change-Id: If8cf678cbd743a970f52893fcf4a9b83ea06d7e9
GitHub-Last-Rev: f385705cc05eb98132e20561451dbb8c39b68519
GitHub-Pull-Request: golang/tools#86
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173099
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-23 22:28:03 +00:00
Ian Cottrell
18110c573c internal/lsp: delay the running of gofmt until the test is running
Change-Id: I222c83313a6366367fbeb7ce7d08058968d3a08e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173340
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-23 21:55:36 +00:00
Ian Cottrell
2acd0f4c51 internal/lsp: adding golden file support to the test harness
Also convert the format tests to use it. This means that the build bots no
longer need to run gofmt.

Change-Id: I5cb9d239183b17d81fdb00b38e9099d224c07e6a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172973
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-23 21:54:59 +00:00
Rebecca Stambler
c6b416e8a4 internal/lsp: add more error handling to analysis
Updates golang/go#30786

Change-Id: Icf054b9bcd62b36e3aa55288946a9f0d1c845300
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172972
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-22 21:49:46 +00:00
Rebecca Stambler
3ff669b183 internal/lsp: add check for nil package
Fixes golang/go#31604

Change-Id: I60ec000d505c64783e5f51f62d168dc31c2fbe19
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172968
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-22 21:23:51 +00:00
Rebecca Stambler
1e2181f3f4 internal/lsp: add additional debug logging for diagnostics
This change adds detailed debug logging for lsp.Diagnostics. This is
necessary for further investigation of cases where diagnostics aren't
propagated after a "didChange" request.

Updates golang/go#30786

Change-Id: I30eabf5a1cb17d4538a8860310b450494626b76f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172971
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-22 21:11:31 +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
micnncim
15d5d381ff internal/lsp: fix error handling in cmd
Found unnecessary error handling so removed.

Change-Id: I1a48e73186425291fdb0ede963b92ef6c9ce0ed8
GitHub-Last-Rev: d5cf67cb4a418bdc81dbd32eef9afb567ae4ff15
GitHub-Pull-Request: golang/tools#84
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173097
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-04-22 18:06:12 +00:00
micnncim
75f23652ec internal/lsp: fix query cmd usage
`query` usage has the following duplicated description.

```
Usage: query [flags] query [flags] <mode> <mode args>
```

```
$ gopls query
query: query must be supplied a mode
answer queries about go source code

Usage: query [flags] query [flags] <mode> <mode args>

The mode argument determines the query to perform:
  definition : show declaration of selected identifier

query flags are:
  -emulate string
        compatibility mode, causes gopls to emulate another tool.
        values depend on the operation being performed
  -json
        emit output in JSON format
```

Change-Id: Ib511b6c77d8b6dc8148ca46f88a1a133d21ba25c
GitHub-Last-Rev: a022377913fec65482a26e61a2b22927de7d4132
GitHub-Pull-Request: golang/tools#85
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173098
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-04-22 18:06:03 +00:00
Ian Cottrell
7f54bd5c70 internal/lsp: extract the common test logic
Change-Id: I0a3e8a2837cdeefb3dbbe7b86ed75a32b321797e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172778
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-22 16:50:02 +00:00
Rebecca Stambler
9eb0fb1732 internal/lsp: support comments on hover for typenames, funcs, fields
This change adds support for showing documentation when hovering over any
named type or function. For now, we show the entire comment associated
with the type; in future CLs, we should refine our approach and perhaps
only show the first line or sentence.

Updates golang/go#29151

Change-Id: Ib33284747b19acba67d79fb55c916574c3dd8073
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172958
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-22 16:38:38 +00:00
Muir Manders
aa740d4807 internal/lsp: handle embedded struct pointer definitions
When jumping to definition of an embedded struct pointer, be sure to
unwrap the pointer type so you properly jump to the pointee type.

Also, fix jumping to definition of an embedded struct inside an
anonymous struct inside a struct. The embedded struct detection was
continuing too far and thinking it wasn't an embedded struct when it
saw the anonymous struct.

Fixes golang/go#31451

Change-Id: I96017764270712a2ae02a85306605495075d12e7
GitHub-Last-Rev: 9997f60855ebe37bcca2fecc1ba2a7b871f393d4
GitHub-Pull-Request: golang/tools#83
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172583
Run-TryBot: Paul Jolly <paul@myitcv.org.uk>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-20 18:18:00 +00:00
Rebecca Stambler
c39e7748f6 internal/lsp: add type to placeholders in completion parameters
Fixes golang/go#31547

Change-Id: Ib6e54ae17c778421a49f34d3c60d56b126419a91
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172666
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-19 19:58:23 +00:00
Rebecca Stambler
4796d4bd3d internal/lsp: use ast.Nodes for hover information
This change associates an ast.Node for some object declarations.
In this case, we only handle type declarations, but future changes will
support other objects as well. This is the first step in adding
documentation on hover.

Updates golang/go#29151

Change-Id: I39ddccf4130ee3b106725286375cd74bc51bcd38
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172661
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-18 23:52:43 +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
f6abc2cac8 internal/lsp: check content format instead of assuming markdown
Fixes golang/go#31078

Change-Id: I2227f64d839d65d7b46d43e1b90f5b1dc298bf6f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172601
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-17 21:38:10 +00:00
Ian Cottrell
afc68fbc60 internal/lsp: a cleaner way of doing overlays
Change-Id: I3ee053cfc4b63f54b9bf43d0ce6a2bae713e3a0d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172638
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-17 21:35:05 +00:00
Rebecca Stambler
780da32332 internal/lsp: trigger signature help after completing a function
Change-Id: Ib0ee79a11dd828c77bdf22a19a24ed9d883d8393
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172600
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-17 21:12:31 +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
Muir Manders
7e40e1726e internal/lsp: improve signatureHelp in various cases
- show signature for function calls whose function expression is not
  an object (e.g. the second call in foo()()). since the function name
  is not available, we use the generic "func"
- only provide signature help when the position is on or within the
  call expression parens. this is consistent with the one other lsp
  server i tried (java). this improves the gopls experience in emacs
  where lsp-mode is constantly calling "hover" and
  "signatureHelp" ("hover" should be preferred unless you are inside
  the function params list)
- use the entire signature type string as the label since that includes
  the return values, which are useful to see
- don't qualify the function name with its package. it looks funny to
  see "bytes.Cap()" as the help when you are in a call
  to (*bytes.Buffer).Cap(). it could be useful to include invocant
  type info, but leave it out for now since signature help is meant to
  focus on the function parameters.
- don't turn variadic args "foo ...int" into "foo []int" for the
  parameter information (i.e. maintain it as "foo ...int")
- when determining active parameter, count the space before a
  parameter name as being part of that parameter (e.g. the space
  before "b" in "func(a int, b int)")
- handle variadic params when determining the active param (i.e.
  highlight "foo(a int, *b ...string*)" on signature help for final
  param in `foo(123, "a", "b", "c")`
- don't generate an extra space in formatParams() for unnamed
  arguments

I also tweaked the signatureHelp server log message to include the
error message itself, and populated the server's logger in lsp_test.go
to aid in development.

Fixes golang/go#31448

Change-Id: Iefe0e1e3c531d17197c0fa997b949174475a276c
GitHub-Last-Rev: 5c0b8ebd87a8c05d5d8f519ea096f94e89c77e2c
GitHub-Pull-Request: golang/tools#82
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172439
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-17 18:10:49 +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
Rebecca Stambler
aa385af2d9 go/packages: add support for entire packages defined in overlays
This change adds support in go/packages for defining an entire package
in an overlay. We also add corresponding tests for this in gopls, to
confirm that it works as expected.

Fixes golang/go#31467

Change-Id: Iead203ab2964a7ac4f571be97624b725ac5de7e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172409
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-17 17:55:51 +00:00
Ian Cottrell
4ca4b55e20 internal/lsp: make the symbols tests use the enum names rather than hard coding the values
this makes them less fragile, more portable and also more understandable.

Change-Id: Ife8a7ed76b7517eaae37bd3896fee87740ffb22a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172405
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-17 00:57:54 +00:00
Ian Cottrell
35716ff3bc internal/lsp: set the diagnostic source earlier
We now set the diagnostic source in the diagnostics call rather than when
converting it to the LSP protocol.

Change-Id: Ic762aaab1b2bf93b75c4c3d78aa84e2f918398fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172408
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-17 00:57:43 +00:00
Ian Cottrell
49a1609436 internal/lsp: cleanup the diagnostic and completion tests
this make the same kinds of changes I already made to the symbol tests,
to make the messages more detailed and remove the goto

Change-Id: I7cb27839b2ab696ad4e3d6537d91152e34fb1d89
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172477
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-17 00:57:32 +00:00
Rebecca Stambler
dd61c98fae internal/lsp: run source.organizeImports on all codeActions
This change addresses the additional information we received in
https://github.com/Microsoft/language-server-protocol/issues/726.

Fixes golang/go#31359

Change-Id: Ied7c97ac1f9e429e28cc44563b93acabd80921a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172406
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-16 21:54:00 +00:00
Ian Cottrell
e2848a0e7d internal/lsp: minor clean up of symbol tests
remove the goto and make it print more information about why the failed.

Change-Id: I2f5f3c7fe88eae6fe5de61c5d9b401797b6933b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172404
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-16 21:24:14 +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
Rebecca Stambler
76038274be internal/lsp: fix badly formatted error messages from go vet
Fixes golang/go#31494

Change-Id: Id65e0daaa67a9fe955b7586af82e4433762cd56c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172398
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-16 19:41:54 +00:00
Rebecca Stambler
b8fc0e1722 internal/lsp: organize imports as a quickfix
This change adds the ability to organize all imports as quickfix on a
diagnostic, in addition to the standard "source.organizeImports" code
action kind. This change still requires a bit of work, since really, we
should only add one import per diagnostic and each edit should be the
edits necessary for the addition or removal of the individual import,
but this is a good start.

Change-Id: I57679446bec833d215c35533240102fb61c86f20
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172397
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-16 19:07:07 +00:00
Rebecca Stambler
3e7148b2fa internal/lsp: log errors when diagnostics fail
This will allow us to better track the errors that might cause golang/go#30786.

Change-Id: I310ad0fd0eda3102d5763e28fc383a4994ef0ff3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172280
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-16 17:15:26 +00:00
Ian Cottrell
9c9e1878f4 internal/lsp: fix crash when there is a type alias to a struct in the symbols code
Change-Id: If492a88c9f80003d7102b4f517621e52cc15759f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/171861
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-16 15:17:39 +00:00
Rebecca Stambler
2e9de471eb internal/lsp: handle definitions for variables with error types
Fixes golang/go#31465

Change-Id: I2f79fe2167bab79b497125995efc938f2b63d274
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172117
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-15 20:59:51 +00:00
Ian Cottrell
744a51dd88 internal/lsp: normalise and make public diff<->edit conversions
This allows us to use the diff.ApplyEdits in tests, saving us from a different
implementation.
It also prepares for command lines that need to use diff features based on the
results of a protocol message.

Splitting content into lines is too easy to get wrong, and needs to be done
correctly or the diff results make no sense. This adds the SplitLines function
to the diff pacakge to do it right and then uses it everwhere we we already
doing it wrong.

It also makes all the diff tests external black box tests.

Change-Id: I698227d5769a2bfbfd22a64ea42906b1df9268d9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/171027
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-15 20:31:36 +00:00
Ian Cottrell
fa491999fb internal/lsp: add unified diff
This adds unified diff handling to the diff package.
It also adds a lot more testing and also verifies the unified
diff tests against the diff program if you run the tests with
the flag -verify-diff
This functionality is needed for some of the command verbs.

Change-Id: I817438fd25c0b16f3f31578f51a886944e74a948
Reviewed-on: https://go-review.googlesource.com/c/tools/+/171024
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-15 20:14:25 +00:00
Ian Cottrell
2b5498619e internal/lsp: Remove 1.10 compatability in tests
Change-Id: I6e136d8b3292c1bedfdbb294c0465689ad1ffafb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/171239
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-15 15:47:27 +00:00
Zac Bergquist
2538eef759 internal/lsp: enhance document symbols support
Make methods children of their receiver's type symbol.
Add struct fields as children of the struct's type symbol.
Also identify numeric, boolean, and string types.

Updates golang/go#30915
Fixes golang/go#31202

Change-Id: I33c4ea7b953e981ea1e858505b77c7a3ba6ee399
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170198
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-10 21:12:19 +00:00
Rebecca Stambler
96f2e7ef86 internal/lsp: ignore errors for completion and signature help
This change makes sure that we never return error messages for
completions and signature help requests - just empty results.

Change-Id: I00d75cd116daab63beb07f2344e47aac01bb64ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170958
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-09 22:37:05 +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
Rebecca Stambler
e5b8258f49 internal/lsp: stop formatting on files that do not parse
This change will stop formatting from working on any file that does not
parse. This is a temporary fix to handle the formatting problems
mentioned here: https://github.com/Microsoft/vscode-go/issues/2410, but
is not a long-term solution.

Change-Id: Ie34b1876519832d6859db95fdcad7cc37a20b769
Reviewed-on: https://go-review.googlesource.com/c/tools/+/171019
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-08 22:03:57 +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
a81264a823 internal/lsp: change diff tests to take strings not string arrays to make them more realistic
Change-Id: I7916c29c24cf581ddb4909a9beb8b0be3fb94c68
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170881
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-07 02:04:52 +00:00
Rebecca Stambler
ccd3732616 internal/lsp: refactor code actions
This change makes codeActions look at the diagnostics provided before
responding. Specifically, before running "source.organizeImports", we
check if there is a diagnostic relating to imports.

Change-Id: I5268d5e8f144c4f2e085b2a861d0abfb7614323b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170997
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-06 23:57:00 +00:00
Ian Cottrell
b184d1ccfc internal/lsp: change diff Op.Content to be the unjoined strings
This also means we don't need the J2 becasue it is implied by len(Content)

Change-Id: I04e2cbaa3e1faa1e3add22ec2d478821b9062419
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170878
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-05 17:03:17 +00:00
Ian Cottrell
f558378bf8 internal/lsp: make definition use the lsp protocol
instead of driving the source pacakge directly, it indirects through the lsp
protocol (the same way check does)
We are normalizing on all the command lines doing this, so that server mode
is more viable in the future.

Change-Id: Ib5f2a059a44a5c60a53129c554e3cc14ca72c4a8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170577
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-05 17:02:55 +00:00
Ian Cottrell
d996c1aa53 internal/lsp: minor comment fix
Change-Id: I6603375beac4e321dd45f99e90d7eddbae4c6c4b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170717
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-05 16:24:45 +00:00
Rebecca Stambler
1058ed41f4 internal/lsp: add a "usePlaceholders" setting to gopls configuration
This change allows us to determine if we should complete with
placeholders in the function signature or not.

We currently complete all functions with parameters with a set of
parentheses with the cursor between them. Now, we support the option to
tab through the parameters.

Change-Id: I01d9d7ffdc76eb2f8e009ab9c8aa46d71c24c358
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170877
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-05 14:18:02 +00:00
Ian Cottrell
923d258130 internal/lsp: make the guru emulation tests slightly looser with a different matching system
We now match only the things we realy need to, to allow the description to vary more.

Change-Id: Ib3591c41ed5a5c725f2a3efb180ba17f808de51a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170341
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-04 13:25:00 +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
Rebecca Stambler
4c644d7e32 internal/lsp: avoid extra work in *cache.View.remove
Fixes golang/go#31177

Change-Id: I31219c6285fecd0abc4ff5ec4ae732bcfcb69511
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170182
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-01 20:55:34 +00:00
Rebecca Stambler
36ba6a502a internal/lsp: suppress error message when there is no config
Change-Id: I04d26ec3967f6515703142a11fc88b115890ab59
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170185
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-01 20:55:12 +00:00
Ian Cottrell
5bca5db4cb internal/lsp: check the client capabilities before calling workspace/configuration
Change-Id: I88d1142f4737cb74f5d6c9409218dde674dc1834
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170184
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-01 20:27:58 +00:00
Ian Cottrell
1bac838f5b internal/lsp: support multiple views
This uses the workspace folders to build multiple views, and then tries to pick
the right view to send each incomming request to.

Change-Id: I0cc896dbbc67eb0a88225ddeca6c518f4258bbba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170179
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-01 20:12:29 +00:00
Rebecca Stambler
bf99c0974b internal/lsp: create the undelivered map
(for real, this time)

Change-Id: I563b7b34a1849914e9b922b07a86916bac7be30d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170183
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-01 19:21:32 +00:00
Rebecca Stambler
4fc9f0bfa5 internal/lsp: cache file objects for every dependency
Change-Id: I68eedc49a07aa9ba3328a4380e97ed03d1b75749
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170180
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-01 16:39:57 +00:00
Rebecca Stambler
cf22ef0385 internal/lsp: handle undelivered diagnostics
This change adds a cache of undelivered diagnostics on the server-side.
If we fail to send a diagnostic once, we will retry the next time that
the server sends diagnostics.

Change-Id: I161dfad8ea1d2cfdcee933baed2d6872dc03b0c0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167737
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-04-01 16:39:43 +00:00
Ian Cottrell
e2f00d1e07 internal/lsp: make pipe mode the default for command line tests
now there are no more race conditions in the jsonrpc or server code make
connected pipe (rather than direct API) the default in the tests to make
sure we stay clean.

Change-Id: Id1ffede795a660dbf7b265b9e0419c60cf83c6e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170181
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-04-01 16:30:59 +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
Rebecca Stambler
73054e8977 internal/lsp: use new go/packages LoadMode to get TypesSizes
This change also fixes the corresponding code in go/packages, which was
actually not filling in the TypesSizes if the bit was set.

Change-Id: I2d5a849045768a81c94218eb41da2faec26189a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170010
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-29 21:52:04 +00:00
Rebecca Stambler
24738cbdc1 internal/lsp: add an error result to findFile
This change allows us to return diagnostics in the case of a file that
doesn't exist.

Change-Id: I6275c0dc9103a3f44070919937afe27c64545828
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170009
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-03-29 21:46: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
Rebecca Stambler
0926561711 internal/lsp: fix nil pointer exception in document symbols
Change-Id: I168bf7b995aa0b609de67999879addad250eff11
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170006
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-29 18:25:15 +00:00
Ian Cottrell
23e29df326 internal/lsp: fix broken gopls query help comment
Change-Id: I7f1f9c4a56a1471ebb6f2b4d1a72b8d7c2223e85
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170017
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-29 15:12:28 +00:00
Ian Cottrell
4471d52094 internal/lsp: allow command line tests to connect through a pipe
With this change (finally, after a lot of detours) if you run the lsp tests with `-race -pipe` then you
can reliably reproduce the race in golang/go#30091

Change-Id: Ibd9fda5e07409a15d1bc8d14cb46fde41155aa6e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/169999
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-29 15:12:06 +00:00
Ian Cottrell
ab21143f23 internal/lsp: adding command line access to diagnostics
Change-Id: I011e337ec2bce93199cf762c09e002442ca1bd0d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167697
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-28 21:17:00 +00:00
Ian Cottrell
8889bfc21e internal/lsp: wire up configuration
This connects up the configuration message, and uses it to allow the client to set the environment
in the config passed to packages.Load

Change-Id: I75e03c01c74e9b11c8b4c47b9cbdd0574cddf778
Reviewed-on: https://go-review.googlesource.com/c/tools/+/169704
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-28 21:16:46 +00:00
Zac Bergquist
8f05a32dce internal/lsp: correctly report interface symbols
Updates golang/go#30915

Change-Id: I9c5faa615df506cf1d015a9eb48196fa9b0387ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/169682
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-28 03:05:05 +00:00
Rebecca Stambler
2898d834dc internal/lsp: fix tiny bug in getting files by basename
This change fixes gopls on Windows.

Fixes golang/go#30967

Change-Id: Iba5eb6932a4acd6a574ad6970faf7c133ecb7d32
Reviewed-on: https://go-review.googlesource.com/c/tools/+/169703
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-28 02:26:11 +00:00
Ian Cottrell
c70d86f8b7 internal/lsp: match files by identity
Instead of using a simple path map we now attempt to match files with
os.SameFile with fast paths for exact path matches. This should fix issues both
with symlinked directories (the mac tmp folder) and with case sensitivity
(windows)

Change-Id: I014dd01f89d08a348e7de7697cbc3a2512a6e5b3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/169699
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-27 20:14:19 +00:00
Rebecca Stambler
45dd101d87 internal/lsp: unescape uris before we convert them to span.URI
This is the first step of fixing gopls on Windows.

Change-Id: I20cea63051f448cba86996edaf7a8347b0d20bd1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/169444
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
2019-03-27 16:50:41 +00:00
Rebecca Stambler
41a94eb788 internal/lsp: add back distinction between var and const symbols
Change-Id: I59f87d4430c93438804cea7cc56a80f12bb42a00
Reviewed-on: https://go-review.googlesource.com/c/tools/+/169441
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-27 01:06:29 +00:00
Rebecca Stambler
c02eab13f0 internal/lsp: group document symbols and add more detail
This change uses go/types information to get the types for the
different symbols. It also groups the symbols according to their kinds,
though this doesn't seem to be reflected in the actual VSCode UI...

Updates golang/go#30915

Change-Id: I2caefe01f9834aaad6b9e81cd391d461405ef725
Reviewed-on: https://go-review.googlesource.com/c/tools/+/169438
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-26 23:54:22 +00:00
Ian Cottrell
0268d3dd07 internal/lsp: use main testdata folder
This upgrades the current gopls query definition tests to use the main testdata
folder. This considerably increases the coverage and also sets us up to better
test the other command line features as we add them.

Change-Id: If722f3f6d0270104000f1451d20851daf0757874
Reviewed-on: https://go-review.googlesource.com/c/tools/+/169159
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-26 19:49:56 +00:00
Zac Bergquist
ca36ab2721 internal/lsp: add support for document highlight
Change-Id: I232dbb0b66d690e45079808fd0dbf026c4459400
Reviewed-on: https://go-review.googlesource.com/c/tools/+/169277
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-26 19:08:20 +00:00
Zac Bergquist
1d95b17f1b x/tools/internal/lsp: add support for document symbols
Updates golang/go#30915

Change-Id: I9a447f7748eb9894fb6f4072febec132b2ed91d7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/168338
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-25 22:30:49 +00:00
Ian Cottrell
5a8dccf5b4 go/packages/packagestest: convert to the span library
Change-Id: Ib8984dd0828e3bb0b49eaa1604649300a4d54306
Reviewed-on: https://go-review.googlesource.com/c/tools/+/168900
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-03-25 16:17:52 +00:00
Benny Siegert
3096223ce8 internal/lsp/cmd: fix regexp in test
The test fails if the GOROOT directory contains a dash, e.g. as in
/usr/lib/google-golang on corporate workstations, or on certain
builders.

Change-Id: If08c438764f4b76fff7fb43ccf3e4fd56afeff1a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/168063
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-21 15:39:10 +00:00
Ian Cottrell
bb1270c20e internal/lsp: fix accepting line:colum forms to query definition
Change-Id: I425a9ebf77925b16fb7cb6fd5727d2377ab836b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/168178
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-03-18 20:07:14 +00:00
Ian Cottrell
a41300a290 internal/lsp: refactor query definition test to allow adding a new test
Change-Id: I360f21012f26118947dbac7c39e17c9c1f599379
Reviewed-on: https://go-review.googlesource.com/c/tools/+/168177
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-03-18 20:06:54 +00:00
Elias Naur
f0bfdbff1f internal/lsp,internal/lsp/cmd: skip tests on android
Change-Id: Idd9ddd32742a9f85096b71509511492b54538190
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167818
Run-TryBot: Elias Naur <mail@eliasnaur.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-15 21:40:10 +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
Marwan Sulaiman
f59e586bb3 cmd/lsp: skip completion in string literals
This CL ensures that a "." inside a string literal will return an empty
completion list.

Fixes golang/go#30477

Change-Id: I1442d0acab4c12a829047805f745c4729d69c208
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167857
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-03-15 16:51:35 +00:00
Rebecca Stambler
8110780cfa internal/lsp: add correct handling for circular imports
This change brings back handling for circular imports, which was removed
because I originally thought that go/packages would handle that.
However, since we are type-checking from source, we still end up having
to deal with that.

Additionally, we propagate the errors of type-checking to the
diagnostics so that the user can actually see some of the problems.

Change-Id: I0139bcaae461f1bcaf95706532bc5026f2430101
Reviewed-on: https://go-review.googlesource.com/c/tools/+/166882
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-15 16:49:21 +00:00
Rebecca Stambler
8b67d361bb internal/lsp: configure completion to preselect the first item
The language client must support the preselect feature, so as of right
now, I don't think that this change has any effect. However, ultimately,
we should preselect the first completion item we suggest, as we rank
items.

Change-Id: I977cce26157504595a0193ab551685e21a3df155
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167466
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-03-15 04:42:04 +00:00
Rebecca Stambler
8781451fe3 internal/lsp: propagate errors from in diagnostics
An ignored error in toProtocolDiagnostics could result in empty
diagnostics being (incorrectly) sent to the user.

Change-Id: I34c86a1f5bbf28888bedad094f596cc27a52b86d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167714
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-15 04:33:14 +00:00
Rebecca Stambler
1286b2016b internal/lsp: filter on insert text, not label
Change-Id: Ibd0c0c7af57cc8aeec56188cf52300f7c558adfe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167464
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-14 01:07:20 +00:00
Rebecca Stambler
a10017ccd2 internal/lsp: handle common nil pointer exceptions
We may encounter these nil pointer if go/packages cannot find the
package of the given file, for example, when the user creates a new file
or a new package.

Change-Id: I16993017243a56332dd9f7e0aaf3c1d57f20fc3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167462
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-13 23:43:22 +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
Rebecca Stambler
d55b9fb8ef internal/lsp: stop providing insertText for completion items
InsertText is deprecated, and it seems that providing both InsertText
and TextEdits causes unexpected behavior from VSCode. Avoid this by
providing only TextEdits.

Fixes golang/go#30796

Change-Id: Ieb5ad2fecd6f7083a4c1bc402634893c7e6ff49f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167457
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-13 18:39:08 +00:00
Rebecca Stambler
e65039ee41 internal/lsp: make sure completion items are never null
Change-Id: Ic6e0988319f8fb2c91b473ac2fa5480dc25dc0b7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167158
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2019-03-12 17:02:43 +00:00
Rebecca Stambler
7b79afddac internal/lsp: add a source.Package interface
This change adds a Package interface to the source package, which allows
us to reduce the information cached per-package (we don't use any of the
unnecessary fields in a *go/packages.Package).

This change also adds an analysis cache for each package, which is used
to cache the results of analyses to avoid recomputation.

Change-Id: I56c6b5ed51126c27f46731c87ac4eeacc63cb81a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165750
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-12 16:49:27 +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
Ian Cottrell
6eedde5c1d internal/lsp: using a non line based applyEdits in tests
Change-Id: Ibbef0a74b53a95d0b08fae6e8ef24be8b0f78273
Reviewed-on: https://go-review.googlesource.com/c/tools/+/166881
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-11 21:20:53 +00:00
Ian Cottrell
de4a0b36f1 internal/lsp: allow end of file byte offsets
Change-Id: I46d7e07a4603f19f615fed2e37e733573ea0fe08
Reviewed-on: https://go-review.googlesource.com/c/tools/+/166880
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-11 21:20:38 +00:00
Rebecca Stambler
00c44ba9c1 internal/lsp: add cache for type information
This change adds an additional cache for type information, which here is
just a *packages.Package for each package. The metadata cache maintains
the import graph, which allows us to easily determine when a package X
(and therefore any other package that imports X) should be invalidated.

Additionally, rather than performing content changes as they happen, we
queue up content changes and apply them the next time that any type
information is requested.

Updates golang/go#30309

Change-Id: Iaf569f641f84ce69b0c0d5bdabbaa85635eeb8bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165438
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-08 17:45:44 +00:00
Rebecca Stambler
69e0dcfa11 internal/lsp: cache package metadata to minimize calls to packages.Load
Instead of calling packages.Load on every character change, we reparse
the import declarations of the file and determine if they have
changed. We also introduce a metadata cache that caches the import
graph. This is used in type-checking and only updated on calls to
packages.Load.

Change-Id: I7cb384aba77ef3c1565d3b0db58e6c754d5fed15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165137
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-06 16:29:03 +00:00
Rebecca Stambler
f8c04913df internal/lsp: refactor type-checking code
Separate out functions to make the code more readable.

Change-Id: I4c48a8343ba5666de375c43499420bdf244aafd1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165022
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-03-05 16:07:28 +00:00
Rebecca Stambler
ac1696789e internal/lsp: temporarily disable incremental changes
It is difficult to debug gopls in combination with the incremental
changes feature. Because gopls is slow (caching CL is in progress), it
seems like the incremental changes can sometimes produce strange
behavior. Disable it for now until we can prioritize work on it.

Change-Id: I931aa39756f198d1af21dca359acc83ca3392c4c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165023
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-03-05 15:57:04 +00:00
Rebecca Stambler
d56157ae75 internal/lsp: remove handling for circular imports
Also, separate type-checking logic into its own file.
go/packages returns import cycle errors anyway, so we just return them instead.

Change-Id: I1f524cdf81e1f9655c1b0afd50dd2aeaa167bb2f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165021
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-03-04 22:34:19 +00:00
Rebecca Stambler
f0a709d59f internal/lsp: set severity levels for compiler errors and vet checks
This change adds severity levels to source.Diagnostics, allowing us to
pass this information along to the LSP. This allows compiler errors to
show up in red, while vet results show up in green.

Change-Id: I2bc0b27ed6629f987c05affe00fdbe4b9bfb3b3e
Reviewed-on: https://go-review.googlesource.com/c/164299
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-02-27 23:25:17 +00:00
Yasuhiro Matsumoto
9c8c5aeafa internal/lsp/cache: skip duplicate import of packages
Change-Id: I33e06b53269cef7aa8962dd41ea74ce25e82fc54
Reviewed-on: https://go-review.googlesource.com/c/163257
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-21 18:09:47 +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
a754db16a4 internal/lsp: absolutize paths when converting filenames to URIs
Fixes golang/go#30280

Change-Id: I95e72c8d952ce7d64114772e9ef3df6568ae5dd4
Reviewed-on: https://go-review.googlesource.com/c/163160
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-21 00:07:07 +00:00
Rebecca Stambler
8bdde6d5f2 internal/lsp: create new cache for each analysis
Because diagnostics computations happen in parallel, we were getting
concurrent map writes by keeping one cache.

Change-Id: Ifa5adffe14c509168c9f8c5cb012f3fcd3a32441
Reviewed-on: https://go-review.googlesource.com/c/163161
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-02-20 22:52:34 +00:00
Rebecca Stambler
58344e5403 internal/lsp: use cached AST when parsing files, if available
Change-Id: Ie5c9f77d973b8f9d8f7732d62b54e0a99e6b4659
Reviewed-on: https://go-review.googlesource.com/c/162890
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-20 18:46:31 +00:00
Ian Cottrell
f7b6a898a4 internal/lsp: remove unused range parameter from computeTextEdits
Change-Id: I3e9853b2a83d0328d10bcb75fc9f1f1cc996f14e
Reviewed-on: https://go-review.googlesource.com/c/163157
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-20 18:40:53 +00:00
Rebecca Stambler
550322b34f internal/lsp: return an updated view after setting a file's contents
Change-Id: I71cfa1463c3f3ec3b80faf9dd57c81d6fa75c466
Reviewed-on: https://go-review.googlesource.com/c/162892
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-20 18:06:46 +00:00
Rebecca Stambler
78f9822548 internal/lsp: fix nil pointer exception on vendored packages
Make sure to use the import path in the packages cache, rather than the
package path. Also, prefetch dependencies.

Change-Id: I0de3942346aa6755dbe904f973aca51d26ba0306
Reviewed-on: https://go-review.googlesource.com/c/162577
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-14 19:54:51 +00:00
Ian Cottrell
508f945e1a internal/lsp: change File.Read to a File.GetContent accessor
Like the previous change to the FIle interface, we treat Read as if it were an
accessor, we remember the content part but not the error part, and we may fill
it in asynchronously, so this change makes it explicit.
In the future we should probably trap the error in the read and push it back
through another channel though, it will be the root cause of later errors.

Change-Id: I3d374dd557178b4e8c5544813cd77f5c0faefe5b
Reviewed-on: https://go-review.googlesource.com/c/162403
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-14 04:36:41 +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
Ian Cottrell
69a2705782 internal/lsp: remove error return values from interface "field" accessors
we don't really use them, only generate them in cases where the failure is way more fundamental, and then also fail
to remember them for the next call to the same accessor. Better to not have them.

Change-Id: I0e8abeda688f5cc2a932ed95a80d89225c399f93
Reviewed-on: https://go-review.googlesource.com/c/162399
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-13 21:58:50 +00:00
Rebecca Stambler
740235f6c0 internal/lsp: add back check that a package was found for a given file
Added this check in golang.org/cl/161077 and unintentionally removed it in
golang.org/cl/161497.

Change-Id: I66bd2b616f4b41c25f134f6e9457c97bbcd3f72b
Reviewed-on: https://go-review.googlesource.com/c/162398
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-13 19:20:42 +00:00
Ian Cottrell
dbb4d4be53 lsp/internal: fix incorrectly formatted file
Change-Id: Ibef9c7d5ce0abfa26ba98744c26b54d843227c23
Reviewed-on: https://go-review.googlesource.com/c/162077
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-13 16:29:12 +00:00
Rebecca Stambler
0e66cc6fab internal/lsp/diff: fix bug that adds extra line to files on format
Small changes to handle the last line in the diff library, LSP tests,
and diff to text edits conversion.

Fixes golang/go#30137

Change-Id: Iff0e53a04c2dabf6f54eb7c738b4c0837f16efba
Reviewed-on: https://go-review.googlesource.com/c/162217
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-13 04:28:36 +00:00
Rebecca Stambler
a21eef959b internal/lsp: use parallel parse files function
This change adds a copy of the parseFiles function from go/packages for
file parsing. Also fix crash caused by lack of TypeSizes from
go/packages.Load when using LoadImports mode.

Change-Id: Ie8c3c653679ab81da45905c6839de7e63966d84c
Reviewed-on: https://go-review.googlesource.com/c/161670
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-13 04:21:09 +00:00
Rebecca Stambler
f7e1b50d22 internal/lsp/cmd: set Serve.app when running with remote
Change-Id: Idf299a0b28b77a3372db20ccb0f80512422e601a
Reviewed-on: https://go-review.googlesource.com/c/162138
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-13 01:59:56 +00:00
Michael Matloob
340a1cdb50 internal/lsp: copy fact support from go/analysis/internal/checker.go
This changes the analysis code from that which was in unitchecker.go
to that in checker.go, so we can run actions that get facts for dependencies
concurrently.

Adds the rest of the traditional vet suite to the LSP.

TODO(matloob): test that facts are actually propagated between packages

Change-Id: I946082159777943af81bcf10e503fecc99da521e
Reviewed-on: https://go-review.googlesource.com/c/161671
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-12 19:58:15 +00:00
Ian Cottrell
44bee7e801 internal/lsp: changing server noun to serve verb
Also adding in --remote support and using it to implement the equivalent
functionality of the external forward command
Also adding in --listen as a replacement for --port as it is more flexible,
specifically it allows localhost:port which
is helpful in environments where opening remotely accesible ports is
problematic.

Change-Id: I5de1cea7dd6f1ee46e7423f3be2a4caca6f040b2
Reviewed-on: https://go-review.googlesource.com/c/161658
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-11 22:49:14 +00:00
Michael Matloob
657755b003 internal/lsp: fix crash caused by lack of TypeSizes from go/packages.Load
Get dummy sizes values until we can get go/packages to forward the correct
values.

Change-Id: Ie31333e9ed7c57d02e1447097567fa894ea9de7d
Reviewed-on: https://go-review.googlesource.com/c/161937
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-11 18:30:33 +00:00
Rebecca Stambler
3744606dbb internal/lsp: type-check packages from source
This change moves gopls from type-checking packages using the
go/packages API to type-checking from source. This is the first step in
adding caching to gopls.

Change-Id: I2a7dcfd8c9c0bfc6c35c86eadcdc6f9ce53d9be7
Reviewed-on: https://go-review.googlesource.com/c/161497
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-08 22:27:37 +00:00
Michael Matloob
a3f91d6be4 internal/lsp: add support for analyzers with dependencies on other analyzers
Steal alan's parallel analysis-graph-running code from multichecker.
Facts are still not supported.

Change-Id: I22f83375d7a314b49d4f458d6dd40c33febc795b
Reviewed-on: https://go-review.googlesource.com/c/161659
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-08 18:55:13 +00:00
Michael Matloob
a8576e2603 internal/lsp: connect basic analysis functionality
This starts hooking up the analysis framework into the LSP. It runs
the Tests analysis (which I think might be the only one that doesn't
need facts or results) and reports its diagnostics if there are
no parse or typecheck failures.

Next step: figure out how to pass through results.

Change-Id: I21702d1cf5d54da399df54437f556b9351caa864
Reviewed-on: https://go-review.googlesource.com/c/161358
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-06 21:48:25 +00:00
Rebecca Stambler
40960b6deb internal/lsp/cmd: fix a nil pointer and some minor clean-up
This change fixes a nil error, in addition to cleaning up a spacing
error and a typo. It also fixes the golint errors in internal/lsp/cmd.

Updates golang/go#30091

Change-Id: I24867bb878fda4e341f87d31bbec701a3814a341
Reviewed-on: https://go-review.googlesource.com/c/161220
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-06 04:15:39 +00:00
Rebecca Stambler
279ab8e001 internal/lsp, go/packages/packagestest: support testing test files
This change allows testdata files to be *_test.go files.

Change-Id: Ic771ea7c89ff2d2aabd1af8be56f9c7286da9053
Reviewed-on: https://go-review.googlesource.com/c/161317
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-06 04:07:32 +00:00
Rebecca Stambler
379209517f internal/lsp: add additional logging for go/packages failures
Change-Id: I8c6dae4309df1746cd8b74d280f1f360f42cc77b
Reviewed-on: https://go-review.googlesource.com/c/161218
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-05 20:13:29 +00:00
Rebecca Stambler
90c8b4f75b internal/lsp: handle escaping URIs for files in the module cache
This change makes sure to handle escaped characters, for instance, files
in the module cache contain "@" in the path. Also, return errors when a
package is not found for a file.

Updates golang/go#30027

Change-Id: I6c4f6d0f30dde55701308b89785f02b671e81cc6
Reviewed-on: https://go-review.googlesource.com/c/161077
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
2019-02-05 18:18:01 +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
Rebecca Stambler
021ffbf1e9 internal/lsp: do not return nil identifiers without errors
Change-Id: I9ffc37dc07f46536a44f7173277d0374fdda1fb8
Reviewed-on: https://go-review.googlesource.com/c/160698
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-04 17:30:59 +00:00
Rebecca Stambler
8a24307720 internal/lsp/diff: fix sources listed for diff implementation
Change-Id: I36b2903f4938c4e7a3f15567e11ab31f3f7d78f7
Reviewed-on: https://go-review.googlesource.com/c/160840
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-04 17:30:30 +00:00
Andzej Maciusovic
7414d4c1f7 internal/lsp: rank types higher when completing in return of a function
Completion now ranks type names higher for func receiver, type params and type results (e.g. func (<>) foo(<>) (<>) {}).

Fixes golang/go#29152

Change-Id: Icdd18b1b344c1cd617a4f45a7b071e53c1345478
GitHub-Last-Rev: e6acb1f2d2a7e571ffcecc500e407fdefd118fed
GitHub-Pull-Request: golang/tools#73
Reviewed-on: https://go-review.googlesource.com/c/159797
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-02 23:51:57 +00:00
Rebecca Stambler
51e363b66d internal/lsp: implement diff for computing text edits
Rather than replacing the whole file on gofmt or goimports, use the Myers
diff algorithm to compute diffs for a file. We send those back as text
edits.

Change-Id: I4f8cce5b27d51eae1911049ea002558a84cdf1bf
Reviewed-on: https://go-review.googlesource.com/c/158579
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-01 23:18:25 +00:00
Ian Cottrell
067a2f313b internal/lsp/cmd: add the definition mode
Change-Id: Ib171016fb1bb063a6424677458b554a08144465c
Reviewed-on: https://go-review.googlesource.com/c/159438
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-01-31 16:39:42 +00:00
Ian Cottrell
cc6a436ffe internal/lsp: refactor definition and hover to share functionality
The source package now exposes an Identifier method that returns information
about an identifier, which can be used to implement Definition, TypeDefinition
and Hover, as well as other command line functions in a later cl.

Change-Id: I03629c2c940215b4e2c86ee45bee8a18b79ee0e1
Reviewed-on: https://go-review.googlesource.com/c/159337
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-01-24 21:53:03 +00:00
Andzej Maciusovic
2d2e1b1749 internal/lsp: do not complete inside comments in functions
The previous change (https://go-review.googlesource.com/c/tools/+/157678) only stopped completion in comments in global scope. This change prevents completions results from being sent for comments inside of functions.

Fixes golang/go#29370

Change-Id: I2b43ae2942c6ce7376d2a5f88c40e6ac45c2b773
GitHub-Last-Rev: bc4aac1370aa5758941cdfae63290f061a55e204
GitHub-Pull-Request: golang/tools#71
Reviewed-on: https://go-review.googlesource.com/c/158538
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-01-22 18:08:10 +00:00
Rebecca Stambler
b258f6da23 cmd/gopls: rename "golsp" to "gopls", as in "Go Please"
Change-Id: Ie5688759ce21bffa6745eb86ef3606639e3ce335
Reviewed-on: https://go-review.googlesource.com/c/158197
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-01-16 23:16:16 +00:00
Andzej Maciusovic
f94e9803bf internal/lsp: do not complete inside comments
Fixes golang/go#29370

Change-Id: I160b00f95fe44b2d87f66dc5842bb3a124e0292c
GitHub-Last-Rev: 924c13bc86f947ca01b291e7cc0d171164c2c856
GitHub-Pull-Request: golang/tools#69
Reviewed-on: https://go-review.googlesource.com/c/157678
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-01-16 17:22:44 +00:00
Rebecca Stambler
2e4132e53b internal/lsp: add a test for completion of builtin types and functions
Change-Id: I7df2cfebbf2c44d189066a6d16770c753f7bf1d4
Reviewed-on: https://go-review.googlesource.com/c/158020
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-01-16 00:24:28 +00:00
Rebecca Stambler
bf090417da internal/lsp: fix a few nil pointer exceptions in definition
Jumping to the definition of a builtin function or basic kind would
cause a nil pointer because these have no position.

Change-Id: I043a61a148757b127ff1123c8429ce23858bd13a
Reviewed-on: https://go-review.googlesource.com/c/157597
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-01-14 22:23:45 +00:00
Rebecca Stambler
fc1d57b08d cmd/golsp: add a debugging tool to connect with golsp on a port
This change allows golsp to be run on a port, with an intermediary
command passing the data through. This allows for improved logging.
Also, add necessary changes to VSCode integration to allow changing the
name of the command for golsp.

Change-Id: I20dca1a50296636e57e022342ee70f0610ad1531
Reviewed-on: https://go-review.googlesource.com/c/157497
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-01-11 21:44:48 +00:00
Yasuhiro Matsumoto
a2c791aa64 internal/lsp/cache: return error when no packages found
Change-Id: Ia11f0c428cffdd42eab5c4322e9ff6f0a38870fc
Reviewed-on: https://go-review.googlesource.com/c/156777
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-01-10 19:47:25 +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
Emil Hessman
d345f29b0d internal/lsp: fix typo
Change-Id: I04164ea5b57ebb828ecb837caa397c9e736f4d57
Reviewed-on: https://go-review.googlesource.com/c/156457
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-07 03:02:06 +00:00
Rebecca Stambler
d00ac6d273 internal/lsp: remove unnecessary packagestest.RangePosition type
Some cleanup of lsp_test.

Change-Id: I0cf4eb73f223845374c7f7f4939a461ff676bde8
Reviewed-on: https://go-review.googlesource.com/c/155579
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Libor K <aschrak1978@gmail.com>
2018-12-21 23:52:34 +00:00
Rebecca Stambler
62138107df internal/lsp: fix diagnostics range computation
Diagnostics were failing because of
https://go-review.googlesource.com/c/tools/+/154742, where I was using
the wrong *token.File for the position calculations. This should fix the
problem.

Change-Id: Ic44e7799da56010b5014d56029fb4e0a8a6bb0e8
Reviewed-on: https://go-review.googlesource.com/c/155479
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-21 20:18:27 +00:00
Rebecca Stambler
85a09cd5ed internal/lsp: set file contents through the source.View, not File
Refactor code as a follow-up to
https://go-review.googlesource.com/c/tools/+/154742.
Also, change every instance of "source.URI()" to "fromProtocolURI", so
that we can add a better implementation of that later on (for Windows
support).

Change-Id: Ifa24ffd7e1aebf1f7d05df6f65742769ead0922f
Reviewed-on: https://go-review.googlesource.com/c/154741
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-12-21 19:33:31 +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
Peter Weinberger
3ad2d988d5 cmd/golsp: log elapsed times in milliseconds rather than microseconds.
Language servers provided by Microsoft seem to use Date.Now()
for calculating elapsed times. In javascript and typescript Date.Now()
reports milliseconds.

Change-Id: Ic12fc4a1d31f2548d8808b8b22aba80c44f000c3
Reviewed-on: https://go-review.googlesource.com/c/155018
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-12-21 15:44:17 +00:00
Rebecca Stambler
f344c7530c internal/lsp: add ranges to some diagnostics messages
Added a View interface to the source package, which allows for reading
of other files (in the same package or in other packages). We were
already reading files in jump to definition (to handle the lack of
column information in export data), but now we can also read files in
diagnostics, which allows us to determine the end of an identifier so
that we can report ranges in diagnostic messages.

Updates golang/go#29150

Change-Id: I7958d860dea8f41f2df88a467b5e2946bba4d1c5
Reviewed-on: https://go-review.googlesource.com/c/154742
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-20 19:13:07 +00:00
Rebecca Stambler
6e267b5cc7 internal/lsp: add additional tests for completion
New tests include cases for anonymous structs, composite literals,
ranking of results in binary expressions, and import cycles.

Change-Id: Ic02e84e09101bb9873fc1705bba2594d655bb45b
Reviewed-on: https://go-review.googlesource.com/c/153443
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-19 22:27:14 +00:00
Ian Cottrell
a072e66104 internal/lsp: refactor the command line handling
This switched the golsp binary to support a sub-command model so it can grow
some guru like command line query capabilites

Change-Id: I1a7a49bb17701e62004bba636d6bee9de2481ffd
Reviewed-on: https://go-review.googlesource.com/c/154559
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-12-17 23:08:30 +00:00
Rebecca Stambler
57eff0d8ac internal/lsp: add support for running goimports as a code action
This change adds support for goimports as a code action that can be run
on save. However, there do appear to be issues with the propagation of
the context.Only field of the CodeActionParams, so we treat every
codeAction as an organizeImports action - this should be fixed in the
next vscode-languageclient release
(https://github.com/Microsoft/vscode-languageserver-node/issues/442).

Change-Id: I64ca0034c393762248fde6521aba86ed9d41bf70
Reviewed-on: https://go-review.googlesource.com/c/154338
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-17 20:01:16 +00:00
Rebecca Stambler
17661a9724 internal/lsp/source: avoid having build tagged files for uri
Create helper functions for the exported URI functions to test
the logic that isn't OS-specific (filepath.{To,From}Slash is the OS-specific part).
Also add helpers to determine is a file or URI path is Windows-specific.

Change-Id: I6ba5119424ad5edcd59b946276e4268b2525505f
Reviewed-on: https://go-review.googlesource.com/c/153867
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-17 19:55:17 +00:00
Yasuhiro Matsumoto
49db546f37 internal/lsp/source: Use file:///C:/ on Windows file system
URI should be started with file:/// always.

Change-Id: I123e577d421de3e85dfec00596fbdb63c2231938
Reviewed-on: https://go-review.googlesource.com/c/153618
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-12-12 20:00:58 +00:00
Rebecca Stambler
b620e9ecbe internal/lsp: use rootURI as config.Dir in packages.Load
This change was inspired by https://golang.org/cl/153777.

Fixes golang/go#29174

Change-Id: I9d9a8b95e984c8e70160d199cd1efc5aa2964ef7
Reviewed-on: https://go-review.googlesource.com/c/153863
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-12 19:28:52 +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
8634b1ecd3 internal/lsp: improve handling of code completion snippets
A few minor fixes: check that the insert text has the expected prefix
before removing it, use a bytes.Buffer to build up snippets, and check
that functions have parentheses in their insert text before trimming
them.

Change-Id: Iaeaf6fda25d6b0a375460b975188486685be1061
Reviewed-on: https://go-review.googlesource.com/c/152978
Reviewed-by: Ingo Oeser <nightlyone@googlemail.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-07 19:59:48 +00:00
Rebecca Stambler
3576414c54 internal/lsp: refactor source package to use an interface
This change separates a cache package out of the
golang.org/x/tools/internal/lsp/source package. The source package now
uses an interface instead a File struct, which will allow it be reused
more easily. The cache package contains the View and File structs now.

Change-Id: Ia2114e9dafc5214c8b21bceba3adae1c36b9799d
Reviewed-on: https://go-review.googlesource.com/c/152798
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-05 22:49:35 +00:00
Rebecca Stambler
62e1d13d53 internal/lsp: add basic support for hover
This change adds a very simple implementation of hovering. It doesn't
show any documentation, just the object string for the given object.

Also, this change sets the prefix for composite literals, making sure we
don't insert duplicate text.

Change-Id: Ib706ec821a9e459a6c61c10f5dd28d1798944fa3
Reviewed-on: https://go-review.googlesource.com/c/152599
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-05 22:25:06 +00:00
Rebecca Stambler
3832e276fb internal/lsp: implement type definitions
Extend definition tests to add typdef test.

Change-Id: Ibad988ae68f91d18f2c6b4739d758a536172fb35
Reviewed-on: https://go-review.googlesource.com/c/152239
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-04 18:51:09 +00:00
Rebecca Stambler
36a8f0a386 internal/lsp: sort completions according to rank
The LSP specification doesn't have a Score field, so we must provide
sortText to the protocol in order to maintain the correct order.

Change-Id: I075849f520c21a0465dfb2060c598d8bae5f876b
Reviewed-on: https://go-review.googlesource.com/c/151237
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-27 19:33:00 +00:00
Rebecca Stambler
b5f2cae84d internal/lsp: fix a bug stopped package names from being printed
Also, trigger signature help on completion of a function (the "(" as a
trigger character doesn't work if it's part of a completion).

Change-Id: I952cb875fa72a741d7952178f85e20f9efa3ebff
Reviewed-on: https://go-review.googlesource.com/c/150638
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-20 23:48:46 +00:00
Rebecca Stambler
d5eafb537d internal/lsp: add InsertText to completions
If signature help is enabled, we should not offer parameter suggestions.
If signature help is not enabled, the user should be able to tab
through parameter completions.

Change-Id: I10990ef4aefb306ddbf51ed14cc1110065eba655
Reviewed-on: https://go-review.googlesource.com/c/150637
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-20 22:45:09 +00:00
Rebecca Stambler
b6bf295893 internal/lsp: fix formatting bug that keeps adding extra newlines
If a file ends with an empty newline, go/token treats the newline as the
final character of the previous line. VSCode, however, treats this as a
final line with no characters. We handle this by determining if the file
we are formatting ends with a newline character and updating the
protocol ranges accordingly.

Change-Id: Id8be0fd776ae65c8f0f937f3e718825e407cb217
Reviewed-on: https://go-review.googlesource.com/c/150338
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-11-20 17:38:33 +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
6dfe7efaa9 internal/lsp: add definition tests from godef
This makes our internal version of go to definition be tested with the
same test data that godef now uses

Change-Id: I04e488b6b9b2d891181f202ea1125b823a079c50
Reviewed-on: https://go-review.googlesource.com/c/150045
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-19 18:17:22 +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
3d801af142 internal/lsp: use subtests for all lsp categories
This makes it possible to run just one type of test if needed
Also add some verification that the right number of tests is being run
And finally collect all the expectations up front, including the completions.

Change-Id: Iee6045a8ad89fa399fefd03bc0712770701ec6f8
Reviewed-on: https://go-review.googlesource.com/c/149737
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:56:05 +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
Rebecca Stambler
f87c222f14 internal/lsp: fix and add tests for formatting
The go/format.Node function fails silently on malformed ASTs, even
though it writes out an invalid tree containing the strings "BadExpr"
and "BadStmt". We fix this by checking for *ast.Bad{Expr,Decl,Stmt}
before running the function. Ultimately, this should be fixed upstream
and just return an error from format.Node.

Change-Id: I2ba25551f0e97c0321d8e757de67360af44044d7
Reviewed-on: https://go-review.googlesource.com/c/149613
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-15 19:42:43 +00:00
Ian Cottrell
fc2e60c3c3 internal/lsp: make Definition handle embedded fields
This change allows it to jump to the type if you are directly on the
embedded field when you trigger go to definition.

Change-Id: I48825a5a683e69c0714978c76b1d188d40b38c5d
Reviewed-on: https://go-review.googlesource.com/c/149615
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-15 19:04:06 +00:00
Ian Cottrell
1a405fd27e internal/lsp: better handling of .in files
This walks the list produced by the MustCopyFileTree call instead of
scanning the file system
It also removes the .in file from the copies, so only the trimmed
version will be present in the exported data set.

Change-Id: I95b0298ab49021a09f6b26e08158ce162b5a99e6
Reviewed-on: https://go-review.googlesource.com/c/149614
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-15 17:55:04 +00:00
Ian Cottrell
2a3f5192be internal/lsp: handle $GOROOT in file paths
This happens whenever we load standard library information from export
data, and prevents the editor from understanding the file names

Change-Id: If5c04176a3e669ba396f322275993616e51ec097
Reviewed-on: https://go-review.googlesource.com/c/149612
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-11-15 01:11:54 +00:00
Ian Cottrell
6778892796 internal/lsp: use the new marker support
We use the custom marker support to allow us to simplify the
annotations, making it much easier to understand the tests.

Change-Id: Id818a286e4e85f48cfe505f14ec82a80498e494c
Reviewed-on: https://go-review.googlesource.com/c/149611
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-11-15 01:11:27 +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
7e59e591a2 internal/lsp: implement signature help
Add SignatureHelp functionality to source package. Tests will be added
in a subsequent change.

Change-Id: Ia43280946d96a984c5741273a00c12255d637b2a
Reviewed-on: https://go-review.googlesource.com/c/149177
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2018-11-13 20:09:34 +00:00
Rebecca Stambler
a8570e12b6 internal/lsp: use bytes.Buffer instead of strings.Builder
x/tools only supports Go 1.10 and Go 1.11, but it's such a simple fix to
support 1.9, so change from strings.Builder to bytes.Buffer.

Change-Id: Ie37d6c7da7ce7dbbd4e9ec933e1eff3304142a59
Reviewed-on: https://go-review.googlesource.com/c/149178
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-11-13 03:38:37 +00:00
Rebecca Stambler
7f27c5d70a internal/lsp: move diagnostics logic to source directory
Change-Id: I6bea7a76501e852bbf381eb5dbc79217e1ad10ac
Reviewed-on: https://go-review.googlesource.com/c/148889
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-12 22:54:56 +00:00
Ian Cottrell
4b1f3b6b16 internal/lsp: make format work on the ast not the source
This makes the format code use the AST that is already cached on the file to do
the formatting. It also moves the core format code into the source directory.

Change-Id: Iaa79169708e92525cce326ea094ab98144fe1011
Reviewed-on: https://go-review.googlesource.com/c/148198
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-12 21:02:38 +00:00
Rebecca Stambler
806e1cfd89 internal/lsp: add a preliminary test for completion
Use the packagestest framework to test completion. Add support for a
slice of token.Position to packagestest to support this.

Change-Id: Ie5ddece4446a3c74419727461a77faa3788cb040
Reviewed-on: https://go-review.googlesource.com/c/148197
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2018-11-12 19:56:38 +00:00
Rebecca Stambler
c26e340d2f internal/lsp: refactor completion and move into source directory
The completion function belongs in internal/lsp/source, so move it
there. Some small refactoring of completion, by moving each type of
completion into helper functions that append to the list of results.

Change-Id: I8599092906609591d499183657fe2d21d1f74df1
Reviewed-on: https://go-review.googlesource.com/c/148397
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-11-08 16:15:53 +00:00
Ian Cottrell
15ad1aa0cb internal/lsp: implement go to definition
This enables go to definition for the lsp.
It has one known non working case (where the filenames have $GOROOT in them)

Change-Id: I142c6e04b8691c5076dfcd55592ea710b4b361a4
Reviewed-on: https://go-review.googlesource.com/c/148158
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-07 18:43:41 +00:00
Ian Cottrell
d0600fd9f1 internal/lsp: make source independent of protocol
I realized this was a mistake, we should try to keep the source
directory independent of the LSP protocol itself, and adapt in
the outer layer.
This will keep us honest about capabilities, let us add the
caching and conversion layers easily, and also allow for a future
where we expose the source directory as a supported API for other
tools.
The outer lsp package then becomes the adapter from the core
features to the specifics of the LSP protocol.

Change-Id: I68fd089f1b9f2fd38decc1cbc13c6f0f86157b94
Reviewed-on: https://go-review.googlesource.com/c/148157
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-07 18:42:35 +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
e504f914a8 internal/lsp: make file a first class concept
A file is strongly associated with a view, and knows how to manage it's own
contents.
We can also now track files that are not "active"

Change-Id: Ib9474cd40e5caa3db6596548612a9f90168b8a19
Reviewed-on: https://go-review.googlesource.com/c/147204
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-05 21:38:40 +00:00
Ian Cottrell
9b5bafe36f internal/lsp: extract view to its own package
This allows us to write the lsp verbs in terms of a stable underlying source
management layer.
This should make it easier to refactor the underlying layer to add more powerful
caching and incremental modes as we go.

Change-Id: Iab97b061d80394a6fa6748a93a4c68f2deb46129
Reviewed-on: https://go-review.googlesource.com/c/147201
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-05 21:38:13 +00:00
Rebecca Stambler
c76e1ad98a internal/lsp: add copyright notices to files that were missing them
Change-Id: Ifb3bedeed7a38366da234b2329c4078931d1a208
Reviewed-on: https://go-review.googlesource.com/c/147441
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-05 19:56:57 +00:00
Rebecca Stambler
ebdbadb46e internal/lsp: fix LSP tests to be compatible with Go 1.10
Change golang/go#145697 added tests for diagnostics in the LSP implementation,
but these test did not work with Go 1.10. This change skips tests that
require Go 1.11.

Change-Id: I52bd2df484b5786395edac2c1c8592c83ac1aaa4
Reviewed-on: https://go-review.googlesource.com/c/147439
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-05 19:42:43 +00:00
Rebecca Stambler
f7a8a58e8d internal/lsp: use packagestest markers to test diagnostics
Add some basic tests for diagnostics using the new
go/packages/packagestest framework.

Change-Id: I6a7bfba6c392928a9eb123ab71ceb73785c12600
Reviewed-on: https://go-review.googlesource.com/c/145697
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-02 21:57:01 +00:00
Rebecca Stambler
9650c66da3 internal/lsp: add support for publishing diagnostics
Any time a file is changed, we compute diagnostics for its package and
return them to the client. No caching is implemented yet, so we parse
and type-check the package each time.

Change-Id: I7fb2f1d8975e7ce092938d903599188cc2132512
Reviewed-on: https://go-review.googlesource.com/c/143497
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-22 21:17:51 +00:00
Rebecca Stambler
8deeabbe2e internal/lsp: support range formatting
Refactor code a bit to support range formatting as well document
formatting. Also, separate view from server to clean up.

Change-Id: Ica397c7a0fb92a7708ea247c2d5de83e5528d8d4
Reviewed-on: https://go-review.googlesource.com/138275
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-10-01 16:29:50 +00:00
Rebecca Stambler
d457fc8054 cmd/golsp: support formatting in golsp
This commit adds support for some basic commands necessary for
integration with VSCode. It also adds support for the
"textDocument/format" method.

Change-Id: I8fd0e33ca544ab65d3233efe2fef9716446ad4ff
Reviewed-on: https://go-review.googlesource.com/138135
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-09-27 17:02:42 +00:00
Ian Cottrell
ef04bbebd8 cmd/golsp: An empty shell of an lsp server for the go language
Change-Id: I51ef556048c2d10537ad90fa5284939e09bc31fd
Reviewed-on: https://go-review.googlesource.com/137097
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-09-27 15:24:00 +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