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

536 Commits

Author SHA1 Message Date
Suzy Mueller
d308a98e2e internal/lsp: prefer inserting imports into existing blocks
Insert imports into existing multiline import declarations when
possible.

Logic for choosing where to insert taken from
golang.org/x/tools/go/ast/astutil.

Change-Id: Ie5ad96d5e3d5db2e92a2c05a6104d14a4a192ed3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190598
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-19 17:23:55 +00:00
Rebecca Stambler
6889da9d54 internal/lsp: separate out getMapper function
This is a super minimal change that will simplify the diffs for when I
actually delete the getMapper function.

Change-Id: I16984b344c87b3645fd451668b6ea747c5be12ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190557
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-16 20:05:58 +00:00
Suzy Mueller
caa95bb40b internal/lsp: add completions of unimported std lib pkgs
Unimported packages may be suggested as completion items. Since these
are not yet imported, they should be ranked lower than other candidates.

They also require an additional import statement to be valid, which is
provided as an AdditionalTextEdit.

Adding this import does not use astutil.AddNamedImport, to avoid
editing the current ast and work even if there are errors. Additionally,
it can be hard to determine what changes need to be made to the source
document from the ast, as astutil.AddNamedImport includes a merging
pass. Instead, the completion item simply adds another import
declaration.

Change-Id: Icbde226d843bd49ee3713cafcbd5299d51530695
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190338
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-16 18:32:40 +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
Suzy Mueller
d5940c88eb internal/lsp: return rename errors for one package only
Rename checks all of the packages that may be affected for conflicts. An
error in any of them leads to renaming error. Returning errors from
multiple packages may be confusing (for example, when there is a test
variant of a package and the same error appears twice). This change
stops after an error is found and returns that error instead of
continuing to search.

Change-Id: Ifba1feddbf8829d3aad30309154d578967e05a36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190416
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-16 17:04:40 +00:00
Suzy Mueller
d0b4265052 internal/imports: get candidate imports
This exposes the candidate imports that are discovered, even if there is
not a particular reference that requires it to be imported. Currently,
this only produces results for standard library packages.

This is useful for autocompletion on unimported packages.

Change-Id: Iafd883153d451a0ef1dae29b24d4d48530c855f7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189999
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-16 16:26:37 +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
Rebecca Stambler
2562441715 internal/lsp: propagate hoverKind to completion documentation
Fixes golang/go#33653

Change-Id: Ia45e4f4b7377681619303a6d414d9b9de3143c01
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190400
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-15 23:26:00 +00:00
Rebecca Stambler
3100af0b0e internal/lsp: label context cancellation errors
This change will just make it a bit easier to debug the context
cancellation errors.

Change-Id: I580751ac04e3357031678eb31914828029c96e4b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190412
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-15 23:24:24 +00:00
Ian Cottrell
922a4ee32d internal/telemetry: extract units to their own package
This makes the code read slightly better, and more closely
aligns with the open telemetry code.

Change-Id: I87eaf7d08b802f7862f896f2654456ee6a7681e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190404
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-15 21:28:32 +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
Sander van Harmelen
d87e9bbada internal/lsp: limit concurrent file reads
We need to limit the concurrent file reads to prevent `too many open
file` errors. The first attempt to solve this was done in change 189437,
but this change turned out to be incorrect.

So this change reverts the changes made in change 189437 and instead
adds an new semaphore around the `nativeFileHandle.Read` method.

The limit is currently set to half of the lowest open file system limit
of *nix, Windows and MacOS system (their respective limits are 1024, 16384,
and 256).

Change-Id: I27d741e3a3c36eb11bfa7457575f5d5831c06ad7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190417
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-15 21:27:41 +00:00
Suzy Mueller
9065c182e3 internal/lsp: fix bug renaming local vars with test files present
This fix adds all packages to the renamer packages map.

Renaming performs checks on each package to make sure there are no
conflicts. If there are multiple packages, each package needs to be
checked. The packages were being incorrectly added to the map and were
all being put under a single key.

Fixes golang/go#33664

Change-Id: I68466ce34ac49b700ce6d14ce0b53e2795926fa9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190399
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-15 14:43:58 +00:00
Suzy Mueller
ea4142463b internal/imports: merge import declarations
When an import is added to the ast, the import declarations are merged
together into the first import declaration. Since this is a part of
the formatting functionality of goimports, do this during formatting
regardless.

The merging pass was added to astutil.AddNamedImport in order to address
issue golang/go#14075. This joined imports from other blocks into the first
import declaration, so that a single block of imports isn't split across
multiple blocks.

This functionality is more of a formatting change than a fix imports
change, in line with sorting the imports, which occurs even when
FormatOnly. The formatting was only applied when an import was added
(not renamed or deleted). This change makes formatting by goimports
more consistent across runs and is not dependent on the exact fixes
that need to be applied.

Change-Id: Icb90bf694ff35e2d6405a3d477cf82fcd3e697e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189941
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-14 23:54:02 +00:00
Suzy Mueller
578fe56564 internal/imports: use the resolver to load exports
Have the imports resolvers load the exports for packages. This allows
each resolver to provide its own implementation of loading exports,
beyond reading from the directory.

Change-Id: I813f2ca59271a1698874556e8771243ac008f46f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188759
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-14 23:51:36 +00:00
Suzy Mueller
4cb0cfd181 internal/imports: test exported functions with nil args
Test the api of the internal imports package to make sure that it does
not crash when given nil as opts or Env.

Change-Id: I0127d550a49f63040efb16c07e8cff8b599bbe3c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190000
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-14 23:42:26 +00:00
Rebecca Stambler
60bb3025ec internal/lsp: fix race condition in caching
This change fixes a race condition in the metadata caching logic.
Also, some minor fixes to comments and invalidation logic (it's not
necessary to invalidate ASTs when a package is invalidated).

Change-Id: I927bf6fbc661a86ef0ba99b29a9ed979cd1eb95d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190317
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-14 16:34:44 +00:00
Muir Manders
2adf828841 internal/lsp: add fuzzy completion matching
Make use of the existing fuzzy matcher to perform server side fuzzy
completion matching. Previously the server did exact prefix matching
for completion candidates and left fancy filtering to the
client. Having the server do fuzzy matching has two main benefits:

- Deep completions now update as you type. The completion candidates
  returned to the client are marked "incomplete", causing the client
  to refresh the candidates after every keystroke. This lets the
  server pick the most relevant set of deep completion candidates.
- All editors get fuzzy matching for free. VSCode has fuzzy matching
  out of the box, but some editors either don't provide it, or it can
  be difficult to set up.

I modified the fuzzy matcher to allow matches where the input doesn't
match the final segment of the candidate. For example, previously "ab"
would not match "abc.def" because the "b" in "ab" did not match the
final segment "def". I can see how this is useful when the text
matching happens in a vacuum and candidate's final segment is the most
specific part. But, in our case, we have various other methods to
order candidates, so we don't want to exclude them just because the
final segment doesn't match. For example, if we know our candidate
needs to be type "context.Context" and "foo.ctx" is of the right type,
we want to suggest "foo.ctx" as soon as the user starts inputting
"foo", even though "foo" doesn't match "ctx" at all.

Note that fuzzy matching is behind the "useDeepCompletions" config
flag for the time being.

Change-Id: Ic7674f0cf885af770c30daef472f2e3c5ac4db78
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190099
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-14 16:13:50 +00:00
Rebecca Stambler
9dba7caff8 internal/lsp: show generated warning on didChange, not didOpen
Change-Id: I1c7346ab5265ed56d7142318b94028095e51f695
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190017
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-13 21:47:29 +00:00
Rebecca Stambler
62ee03427e internal/lsp: use memoize package to cache source.Packages
This change eliminates the need for the package cache map, and instead
stores package type information in the store. We still have to maintain
invalidation logic because the key is not computed correctly.

Change-Id: I1c2a7502b99491ef0ff68d68c9f439503d531ff1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185438
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-13 21:41:43 +00:00
Muir Manders
41f3357785 internal/lsp: don't deep complete struct field names
When it is certain we are completing a struct field name, we don't
want deep completions. The only possible completions are the remaining
field names.

I also silenced the log spam in tests by disabling the go/packages
logger and the lsp logger.

Fixes golang/go#33614

Change-Id: Icec8d92112b1674fa7a6a21145ab710d054919b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190097
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-13 21:38:55 +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
Suzy Mueller
2ad8dc80bc internal/imports: return initialized options
Whent the pointer is nil, changing its value does not fix the returned
options. Return the new pointer so it can be used.

Change-Id: Ie17fe5c47b48b4a77ffb17b974a5c90e3b44df5e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189998
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-12 22:09:39 +00:00
Rebecca Stambler
1e8b33d652 internal/lsp: ignore files that begin with underscores
Fixes golang/go#33540

Change-Id: I5b55c23ac8ff54db94387ed6b70ba39c61ba6108
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189940
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-08-12 22:06:16 +00:00
Rebecca Stambler
89a01ca1a8 internal/lsp: support an experimental structured hover format
Updates golang/go#33352

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

Updates golang/go#33352

Change-Id: I017baaabd0ee0c31cb13cb6abdda296782929823
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189943
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-12 21:11:28 +00:00
Suzy Mueller
4147ede4f8 internal/imports: fix setting default options
This fixes a nil pointer bug that occurs when opt is nil.

If nil is provide as opt to the internal/imports package, use the
default options settings.

Also check separately that Env is non-nil, as this would also cause
a crash.

Change-Id: I9a43b219b31ba80b7cb8111437f211cb72f1ca18
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189939
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-12 19:12:14 +00:00
Rebecca Stambler
f07d81a593 internal/lsp: fix documentation for completion items
This change fixes documentation for completion items by using cached
package and AST information to derive the documentation. We also add
testing for documentation in completion items.

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

Also add some documentation.

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

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

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

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

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

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

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

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

Fixes golang/go#33397

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

Updates golang/go#33157

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

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

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

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

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

Updates CL 186679

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

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

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

Testing:
--------

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

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

Fixes golang/go#33445

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

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

Change-Id: Ibcbfa703d21b6983d774d2010716da8c25525d4f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188059
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-01 20:53:47 +00:00
Suzy Mueller
1e85ed8060 internal/imports: fix typos in documentation
Fix typos and fix descriptions of methods where the behavior described
in the comment is not implemented by that method.

Change-Id: I2c34caff43399dcb4f0e5e41b67189d8d8404fd5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184697
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-07-31 21:41:59 +00:00
Jay Conrod
5a5cfefe1f x/tools/internal/imports: don't load package names for empty list
goimports should not attempt to load package names for an empty list
of packages. 'go list' interprets an empty argument list as '.', which
may or may not be a package.

Fixes golang/go#33175

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

Updates golang/go#31553

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

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

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

Change-Id: Ia5592ca1dedfc6f004ae6b61548890624ae98d59
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188097
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-31 19:33:23 +00:00