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

112 Commits

Author SHA1 Message Date
Ian Cottrell
c7cf430b80 internal/lsp: lift the test loops out into the testing framework
The loops are common to all the testing layers, so lift them.
This prepares for more test improvements, without any funcitonal changes.

Change-Id: Ib750c8a7bb4c424a185cb0bd841674a69db1385b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197717
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-09-27 18:07:07 +00:00
Paul Jolly
a8d5d34286 internal/lsp: provide option for case sensitive completion
In CL 192137 deep fuzzy matching was enabled by default. We also have
options independent options "deepCompletion" and "fuzzyMatching" to
control this. When fuzzy matching is disabled, case insensitive prefix
matching is used.

Provide an option, "caseSensitiveCompletion", which allows for case
sensitive prefix matching when fuzzy matching is disabled.

Change-Id: I17c8fa310b2ef79e36cc2f7303e98870690b5903
Reviewed-on: https://go-review.googlesource.com/c/tools/+/194757
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-09-26 16:59:42 +00:00
Ian Cottrell
ae58c0ff6b internal/lsp: remove filename print from rename output
This prevents piping back to the file, a common pattern.
Multi file forms should use the unified diff.

Change-Id: I1ea140c59de24feb74a64b0cb41890536f23cd3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197157
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-09-25 16:47:12 +00:00
Ian Cottrell
92496828d1 internal/lsp: fix regeneration of golden files
Suggested fixes was totally broken (invalid command) and many others were not in
correct sorted order.
There were lots of golden entries that were no longer used.
The regeneration script itself was broken
The definition tests are skipped, so the entries were not regenerated.

Files must have been hand edited, we probably need to document how to generate
them somewhere.

Change-Id: I1c021aeadd81f08f4572c2124f0c61912a3cd89e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196987
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-09-25 13:16:59 +00:00
Rebecca Stambler
22afafe332 internal/lsp/protocol: update to protocol version 3.15
I was messing around with the new diagnostic tags feature and
had to update to get it to work.

Change-Id: I4294513b460ec4806d23af20bf908cee8673f7c8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197117
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2019-09-25 02:06:47 +00:00
Rebecca Stambler
c006dc79eb internal/lsp: reorganize completion tests
Our completion tests check for a lot of different behaviors. It may be
easier to develop if we have separate tests for things like deep
completion and completion snippets.

Change-Id: I7f4b0c0e52670f2a6c00247199933fd1ffa0096f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196021
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-24 17:09:08 +00:00
Ian Cottrell
6816ec868d gopls: refactor the cmd tests
This allows them to be run from the gopls module as well to test
the code with the hooks installed.

Change-Id: I3079a04ffe3bd221ccc2523e746cbed384e05e2f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196321
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-09-23 22:12:42 +00:00
hartzell
5eefd052ad tools/gopls: add command line support for rename
This commit adds support for calling rename from the gopls command
line, e.g.

$ gopls rename -w ~/tmp/foo/main.go:8:6
$ gopls rename -w ~/tmp/foo/main.go:#53

Optional arguments are:

- -w, which writes the changes back to the original file; and
- -d, which prints a unified diff to stdout

With no arguments, the changed files are printed to stdout.

It:

- adds internal/lsp/cmd/rename.go, which implements the command;
- adds "rename" to the list of commands in internal/lsp/cmd/cmd.go;
- removes the dummy test from internal/lsp/cmd/cmd_test.go; and
- adds internal/lsp/cmd/rename_test.go, which uses the existing
  "golden" data to implement its tests.

Updates #32875

Change-Id: I5cab5a40b4aa26357b26b0caf4ed54dbd2284d0f
GitHub-Last-Rev: fe853d325ef91f8f911987790fcba7a5a777b6ce
GitHub-Pull-Request: golang/tools#157
Reviewed-on: https://go-review.googlesource.com/c/tools/+/194878
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-20 22:57:31 +00:00
hartzell
5adc211bf7 tools/internal/tool: refactor tool.Main() for testabilty
In it previous implementation, tool.Main was meant to be called from
an applications main().  If it encountered an error it would print the
error to standard error and exit with a non-zero status (2).

It is also called recursively and in various test functions.

Exiting on an error makes testing difficult, unnecessarily.

This change breaks the functionality into to parts: an outer
tool.MustMain() that is intended to be called by main() functions and
an inner Main that is used by MustMain() and by test functions.

None of the existing test functions use Main()'s error value, but the
failure case tests for the command line invocation of rename (#194878)
require it.

Fixes #34291

Change-Id: Id0d80fc4670d56c87398b86b1ad9fdf7a676c95b
GitHub-Last-Rev: cd64995c91c94b997754c8d8b1004afc488bf8b7
GitHub-Pull-Request: golang/tools#159
Reviewed-on: https://go-review.googlesource.com/c/tools/+/195338
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-19 22:27:22 +00:00
Rebecca Stambler
11affa06ff internal/lsp: show errors when the user is in the wrong directory
If we encounter `go list` errors when loading a user's package, we
should try to see if they've encountered any of our common error cases.
They are: 1) a user has GO111MODULE=off, but is outside of their GOPATH,
and 2) a user is in module mode but doesn't have a go.mod file.

Fortunately, go/packages does a great job handling edge cases so gopls
will work well for most of them. The main issue will be unresolved
imports. These show up in DepErrors in `go list`, so go/packages doesn't
propagate them through to the list of errors. This will require changes
to go/packages.

Updates golang/go#31668

Change-Id: Ibd5253b33b38caffeaad54a403c74c0b861fcc14
Reviewed-on: https://go-review.googlesource.com/c/tools/+/194018
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-17 21:41:55 +00:00
Rebecca Stambler
5edc6aefed internal/lsp: reduce usage of column mapper
A mapper is always uniquely tied to a file at a specific version, so
just build it when we get a new *ast.File. We build the mapper using the
*token.File associated with the particular *ast.File, which is why there
is one per ParseGoHandle instead of FileHandle.

Change-Id: Ida40981ef91f6133cdd07e9793337fcd67510fba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/194517
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-16 22:00:07 +00:00
Rebecca Stambler
b13fa046aa internal/lsp: merge session and view options into one
This fixes the issue of config options not being applied.
Also, handle config errors and deprecation by showing a message to the
user.

Change-Id: I850d5303a7a1e301c97324060a87929710ee6700
Reviewed-on: https://go-review.googlesource.com/c/tools/+/194682
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-11 19:36:49 +00:00
Michael Matloob
75be6cdcda internal/lsp: enable suggested fixes by default
Remove the wantSuggestedFixes flag, and run the flagged code
by default.

Add test cases for suggested fixes.
Generate a suggested fix to the assign analysis that suggests removing redundant assignments.
Fix the propagation of suggested fixes (using rstambler's code).

Change-Id: I342c8e0b75790518f228b00ebd2979d24338be3b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/193265
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-09-09 19:40:07 +00:00
pjw
fef9eaa9e4 x/tools/gopls: convert to the august, 2019 version of the LSP protocol
The latest version of the LSP protocol introduces a number of changes.
It is now possible to indicate partial results and progress. request.ts
had to construct some new types (at the end of tsclient.go and tsserver,go)
to avoid using a struct for a formal parameter type.  Also,
instead of using the same type for many RPCs, most RPCs now have their own
types.

Change-Id: I095a3e872f42a9f851c01ca4e3c6ac6e32446042
Reviewed-on: https://go-review.googlesource.com/c/tools/+/194177
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-08 13:59:31 +00:00
Rebecca Stambler
bb4ee55d3d internal/lsp: change to protocol.TextEdit for formatting
The next in the sequence of CLs to convert to using protocol positions.

Change-Id: Ib3421bfc73af1b546b60c328ca66528cb9031e19
Reviewed-on: https://go-review.googlesource.com/c/tools/+/193719
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-06 17:54:09 +00:00
Bryan C. Mills
311ec0312e all: skip more memory-intensive tests on linux-arm
Updates golang/go#32834

Change-Id: I9844dc09d9a6eb2e79a0b28a1e69ed018bfa1bff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/192578
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-30 17:05:41 +00:00
Bryan C. Mills
5d7988b71d go/packages,internal/lsp: skip memory-intensive tests on the linux-arm builder
Updates golang/go#32834
Updates golang/go#30309

Change-Id: I75edb84776216523d00fadfb2e2d94ae08533c03
Reviewed-on: https://go-review.googlesource.com/c/tools/+/192336
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-08-29 20:36:57 +00:00
Suzy Mueller
c9403068c1 internal/lsp: add prepare rename support
Prepare rename gets the range of the identifier to rename. Returns an
error when there is no identifier to rename.

Change-Id: I5e5865bc9ff97e6a95ac4f0c48edddcfd0f9ed67
Reviewed-on: https://go-review.googlesource.com/c/tools/+/191170
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-29 20:19:46 +00:00
Suzy Mueller
114c575556 internal/lsp: add foldingRange support
Support textDocument/foldingRange request. Provide folding ranges for
multiline comment blocks, declarations, block statements, field lists,
case clauses, and call expressions.

Fixes golang/go#32987

Change-Id: I9c76e850ffa0e5bb65bee273d8ee40577c342f92
Reviewed-on: https://go-review.googlesource.com/c/tools/+/192257
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-29 20:17:30 +00:00
Peter Weinberger
d151469ab0 x/tools/gopls: reimplement rpc logging at a lower level
Over time the existing implementation became buggy. This implementation
logs close to where data is read or written from the stream connected
to the client. As is required, the log records are from the point of view
of the client.

Fixes golang/go#33755

Change-Id: I91150c697dc2cdb6d3eecbbed7a8d1805a7c476d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/191963
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-29 16:05:15 +00:00
Ian Cottrell
fa80cb575d internal/telemetry: pass the http.Client to the ocagent
This will allow us to configure the connection at need.
It will also allow us to intercept the content for tests.

Change-Id: Id7d34f2d56f233eae112bea97cccab1f2a88de55
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190798
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-21 16:29:14 +00:00
Rebecca Stambler
547ecf7b1e internal/lsp: use protocol.Range in completion items
This change switches Completion to use protocol positions instead of
token.Pos.

Change-Id: I012ce03c9316d8363938dd0156f485982b7e04fe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190600
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-20 20:57:17 +00:00
Ian Cottrell
85edb9ef32 internal/lsp: abstract the diff library so it can be substituted
this moves the actual diff algorithm into a different package and then provides hooks so it can be easily replaced with an alternate algorithm.

Change-Id: Ia0359f58878493599ea0e0fda8920f21100e16f1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190898
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-20 03:37:07 +00:00
Rebecca Stambler
a857023c21 internal/lsp: use protocol.Range for diagnostics instead of span.Span
This is the first in a series of many changes that will change the API
of the source package to use different types for positions. Using
token.Pos is particularly fragile, since the pos has to refer to the
specific *ast.File from which it was derived.

Change-Id: I70c9b806f7dd45b2e229954ebdcdd86e2cf3bbbb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190340
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-16 17:06:24 +00:00
Ian Cottrell
5b08f89bfc internal/telemetry: clean up the exporter api
this shuffles things so there a single exporter API rather than an observer
It also removes most of the globals.
per telemetry type.

Change-Id: Iaa82abe2ded1fff9df8e067ed4a55bcbd9d9591f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190405
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-15 23:56:12 +00:00
Ian Cottrell
156eb2ae29 internal/lsp: split the telemetry library out
This is a straight move of some code with no changes.
It splits the part of the telemetry code that will become a standalone library from the bit that belongs in the lsp.

Change-Id: Icedb6bf1f3711da9251450531729984df6df7787
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190403
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-15 21:28:02 +00:00
Ian Cottrell
528a2984e2 internal/lsp: fix data race in cmd tests
fixes golang/go#33392

Change-Id: I442bf8c04d793e06631a1a9d6c905cb2dcd284b8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189944
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-13 03:47:49 +00:00
Jan Steinke
be5259f298 internal/lsp: use x/xerrors to create new errors
This relates to https://github.com/golang/go/issues/31374 and should switch all instances within `gopls` to use `x/errors` instead of `fmt` to create new errors.

Change-Id: I18339b75d12418d852e0dcc2ba0ed6c2970783b3
GitHub-Last-Rev: f4a55d9b79e7458ef1f1e06cb5eabbabd884f321
GitHub-Pull-Request: golang/tools#108
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179880
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-06 19:46:56 +00:00
Rebecca Stambler
249e2b9b6d internal/lsp/cmd: handle errors when adding a file
Change-Id: Iaed5c92fe777e5b9b588614b5c1696851e3f6c93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188597
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-06 19:33:29 +00:00
Rebecca Stambler
73d708539c internal/lsp/cmd: remove unused isRace global variable in cmd
Change-Id: I9a71df9012fe7477b9e28b8665806d2ecc18f659
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188359
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-06 19:31:56 +00:00
Albert Teoh
773fe550c1 gopls: return file error if file open fails
The bug manifests itself when a non-existent file is passed in as an
argument to gopls, causing a nil pointer dereference panic. This is due
to an attempt to reference the "mapper" attribute, which is not set if
the file is not found.

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

Testing:
--------

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

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

Fixes golang/go#33445

Change-Id: Ib56d8a4b7f23f4882b75cf684c5d18a49d27b824
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188857
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-05 16:01:13 +00:00
Ian Cottrell
c001e47e7f internal/lsp: extra telemetry tagging of files and packages
Change-Id: Ia9a8fb5dcfb74e86b9366849810dd3edc1f898dd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186918
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-31 19:44:43 +00:00
Ian Cottrell
e377ae9d63 internal/lsp: add an ocagent exporter for the telemetry system
Metrics will be added once the agent supports the json form.

Change-Id: I40f6790970311b020a7cab72474b71f4e2aa32e9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186679
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-19 00:56:02 +00:00
Ian Cottrell
625c92e46d internal/lsp: have tests report a different application name to the main gopls binary
Change-Id: I246dc9c468ee35586a8332ebdf41f23521adbc6c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186677
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-18 23:01:26 +00:00
Ian Cottrell
128ec6dfca internal/lsp: fixed broken tracing
I dropped the line that added the stats to the context when merging the recent changes.

Change-Id: I66ab2958b0737360896b40bf30c5ca3c2cebbae5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186300
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-17 19:45:35 +00:00
Ian Cottrell
b0712d6011 internal/lsp: fix the incomplete and broken commit
https://go-review.googlesource.com/c/tools/+/186297 was the wrong commit, this
adds the changes that were supposed to be part of it.

Change-Id: I0c4783195c2670f89c3213dce2511d98f21f1cf4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186379
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-16 20:34:22 +00:00
Ian Cottrell
502543d2ed internal/jsonrpc2: move stats and logging across to gopls
Change-Id: I718ad6075028e922a1a046b22fd01a1315421be1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186297
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-16 19:44:06 +00:00
Ian Cottrell
c8ecc7589e interal/lsp: add context based version of xlog
this is a temporary migration solution

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

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

Change-Id: I2582ae307d1ca062f37b4683907cdbcfdfc61809
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184160
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-12 19:25:23 +00:00
Ian Cottrell
5f9351755f internal/lsp: stop making background contexts everywhere
For all uses inside the lsp we use the detatch logic instead
For tests we build it in the test harness instead
This is in preparation for things on the context becomming important

Change-Id: I7e6910e0d3581b82abbeeb09f9c22a99efb73142
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185677
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-11 16:38:52 +00:00
Jonathan Amsterdam
063514c48b internal/lsp/cmd: replace time.Tick with time.After
time.Tick produces multiple ticks (and leaks a Ticker); time.After
produces a single tick, which is what is called for here.

Change-Id: I922b11e1263a8367afec76c10831b7284f3559ec
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184938
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-03 17:54:00 +00:00
Rebecca Stambler
3cbd95df51 internal/lsp: support a file belonging to multiple packages
This change adds supports for a package belonging to multiple files.
It requires additional packages.Loads for all of the packages to which a
file belongs (for example, if a non-test file also belongs to a package's
test variant).

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

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

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

Change-Id: I0a5870a05825fc16cc46d405ef50c775094b0fbb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183628
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-26 17:56:19 +00:00
Suzy Mueller
4adf7a708c internal/lsp: add identifier renaming
This change provides support to rename identifiers within a single
package.

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

Editing an import spec is not supported.

Fixes #27571

Change-Id: I0881b65a1b3c72d7c53d7d6ab1ea386160dc00fb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182585
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-19 21:54:42 +00:00
Henry Wong
bf5f34bf87 internal/lsp: remove the redundant Server.Run() call.
`go s.Run(ctx)` repeats `h(s)`.

Change-Id: I03ae6df64ad34194b8f46aabd0cf67e5a9e8c777
GitHub-Last-Rev: 3669875d72a196a8c84fb1709a7cf9f84fdbb688
GitHub-Pull-Request: golang/tools#105
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179297
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-19 15:21:02 +00:00
Ian Cottrell
e88138204b internal/span: change URI.Filename so it just returns the filename
We panic if the uri was not a valid file uri instead
They always are a valid file URI, and we would fail miserably to cope if they were
not anyway, and there are lots of places where we need to be able to get the filename
and don't want to cope with an error that cannot occur.
If we ever have not file uri's, you will have to check if it is a file before calling
.Filename, which seems reasonable anyway.

Change-Id: Ifb26a165bd43c2d310378314550b5749b09e2ebd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181017
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-10 21:39:43 +00:00
Suzy Mueller
bca362e842 internal/lsp: add find all references
This change implements the find all references feature by finding all of
the uses and definitions of the identifier within the current package.

Testing for references is done using "refs" in the testdata files and
marking the references in the package.

Change-Id: Ieb44b68608e940df5f65c3052eb9ec974f6fae6c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181122
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-10 19:06:22 +00:00
Rebecca Stambler
8aaa1484dc internal/lsp: add some basic tests for imports
This change adds a few simple tests for the goimports behavior of gopls.
There are still missing cases for non-standard library, but this is a
good start.

Change-Id: I2f9bc2cc876dcabf81413384b83fa3508517adf0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179918
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-03 23:13:51 +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