1
0
mirror of https://github.com/golang/go synced 2024-09-30 20:18:33 -06:00
Commit Graph

3825 Commits

Author SHA1 Message Date
Suzy Mueller
71f556f074 internal/lsp: use the explicit import spec name as ident
When there is an explicit name for an import spec, treat it as its own
identifier, separate from the import path.

Example:
	import h "hello"

The name h is defined in that import spec, not in the package hello
it contains its own references. If asked about a position within the
import path, continue treating that as referencing the imported package.
If the position is within the name, use the identifier there that is
local to that file.

This change allows for go to definition of the explicit name to point to
itself, find all references from the import spec, and rename the
explicit name from the import spec.

Change-Id: Ia1d927a26e73f2dc450d256d71909c006bdf4c37
Reviewed-on: https://go-review.googlesource.com/c/tools/+/191164
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-22 17:46:33 +00:00
Suzy Mueller
fc82fb2afd internal/lsp: return error when renaming within an import spec
Since renaming an identifier within an import spec is not yet supported,
return an error when this is encountered. These idents from the import
spec have a nil declaration object.

Import paths that contain '.' or '/' are caught by the valid identifier check
avoiding the crash, but import paths such as "fmt" are not as fmt is a
valid identifier. This change checks if i.decl.obj is nil and returns an error
if it is to avoid the crash.

Fixes golang/go#33768

Change-Id: I4e757b42bedffd648fc821590e4a383826200dc3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/191163
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-22 00:03:11 +00:00
Ian Cottrell
65e3620a7a internal/telemetry: add the ability to flush telemetry data
Change-Id: I5de33edc352a5202fdf9e38538a224dd6adafedb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190799
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:56 +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
Rebecca Stambler
3aeeb25976 internal/lsp: unlabel context, log errors when canceled
Updates golang/go#33678

Change-Id: I844d6599a3e0ae9594dda1abaebe938402b65822
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190601
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-20 20:39:21 +00:00
Suzy Mueller
324b35332a internal/imports: save information about the module cache
The module cache can only be added to, so any information discovered
about directories that are within a module in the module cache will
not change. Store the information we have discovered about the module
cache.

Updates #32750

Change-Id: I56c88f03f6a364221198fb032b139208497cd0e5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188762
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-20 18:54:49 +00:00
Muir Manders
f0be937dca internal/lsp: speed up deep completion search
Optimize a few things to speed up deep completions:

- item() is slow, so don't call it unless the candidate's name matches
  the input.
- We only end up returning the top 3 deep candidates, so skip deep
  candidates early if they are not in the top 3 scores we have seen so
  far. This greatly reduces calls to item(), but also avoids a
  humongous sort in lsp/completion.go.
- Get rid of error return value from found(). Nothing checked for this
  error, and we spent a lot of time allocating the only possible error
  "this candidate is not accessible", which is not unexpected to begin
  with.
- Cache the call to types.NewMethodSet in methodsAndFields(). This is
  relatively expensive and can be called many times for the same type
  when searching for deep completions.
- Avoid calling deepState.chainString() twice by calling it once and
  storing the result on the candidate.

These optimizations sped up my slow completion from 1.5s to
0.5s. There were around 200k deep candidates examined for this one
completion. The remaining time is dominated by the fuzzy
matcher. Obviously 500ms is still unacceptable under any
circumstances, so there will be subsequent improvements to limit the
deep completion search scope to make sure we always return completions
in a reasonable amount of time.

I also made it so there is always a "matcher" set on the
completer. This makes the matching logic a bit simpler.

Change-Id: Id48ef7031ee1d4ea04515c828277384562b988a8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190522
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-20 18:51:39 +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
Ian Cottrell
d9ab56aa29 internal/telemetry: change concurrency model
This changes to use a mutex and directly execute the less performance
sensitive telemetry calls (tracing and logging) and then uses a submission
queue only for stats adjustments as those are much more sensitive (but it
should also be easier to keep up with them in bursts)

Fixes golang/go#33692

Change-Id: Ia59a8975f21dfbfcf115be1f1d11b097be8dd9c8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190737
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-20 03:27:56 +00:00
Suzy Mueller
15fda70baf internal/lsp: test adding imports for package statements with comments
Test that having a comment at the start of a file allows imports
to be added correctly.

Updates golang/go#33721

Change-Id: Id1673c2509537413710b73261ad2a59afe06b93f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190800
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-19 17:43:41 +00:00
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
Michael Matloob
9fae7b2cd5 go/packages: work around another case where go list doesn't respect -e
When there's an error running the C compiler for cgo, go list will produce
output, but will also complain in stderr, and return a nonzero exit status.
But it sholudn't return a non-zero exit status in that case when run with
-e. Check for and suppress this case.

Fixes golang/go#33462

Change-Id: Idae0970000a0cb134386f5e66d2b63b348ec8576
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190339
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-14 22:11:13 +00:00
Rebecca Stambler
f60b6e7d83 go/packages: add test case for golang/go#33462
Updates golang/go#33462

Change-Id: I66e0ff1a87eab1958eed87a30e0e09b47a62d43c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190177
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-08-14 21:40:36 +00:00
Michael Matloob
5b18234b3a go/packages: set -mod=readonly when processing overlays in module mode
To prevent us from adding additional module dependencies to modules, especially
if the file is in a different module. Sometimes adding additional dependencies
would be the right behavior, but sometimes we run go list to determine
information about files in other modules, and modifying modules outside the one
the user is operating in is bad  behavior.

Fixes golang/go#32499

Change-Id: I2a12e0a64dc6cd34fa98931cbacc30707e5ba494
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190179
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-14 17:19:36 +00:00
Dominik Honnef
597f577694 go/packages: handle more errors that 'go list' prints to stderr
This change adds special handling for two more errors that 'go list'
prints to stderr:

1. when trying to construct an ad-hoc package from files in multiple
   directories
2. the "unexpected directory layout" error (#24854)

Change-Id: Icbd14bcc02c2ca9676dc0449e155ff817da038cb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190077
Run-TryBot: Dominik Honnef <dominik@honnef.co>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-08-14 16:41:31 +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
Michael Matloob
97f12d7376 go/analysis: add a "-fix" flag to checker to apply suggested fixes
Fix will rewrite all the files in place given that there were no
overlapping or invalid suggested fixes. It's intended to be used
with analyses that generate refactorings.

Change-Id: I7ef3c872b58fdd4913fc34b725188e1846969849
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189997
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-13 14:23:22 +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
Rebecca Stambler
afc3694995 go/packages: add a test case for golang/go#32499
Updates golang/go#32499

Change-Id: Ib9daf7c0dc8c6052f84230e54e181ab60166349b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190037
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-12 23:30:24 +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
Jean de Klerk
6d4652c779 digraph: add transpose
Change-Id: Idd6299fd7397840000139ce4fbea43a95ee76b1e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186797
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-09 14:56:39 +00:00
Jean de Klerk
a4e10e6d0e digraph: refactor somepath to print an adjacency list
Refactors somepath to print an adjacency list from "from" to "to", instead of
just the nodes. This allows other tools like modgraphviz to print the subgraph.

This is a breaking change. The previous behavior returned vertices; now it
returns edges. If you relied on the previous behavior, use:

    my-application | digraph somepath <from> <to> | digraph nodes

Change-Id: Id5e77e19eea79849ec6f25018f627c8dc4e2a831
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184338
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2019-08-09 14:56:25 +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
Michael Matloob
a804cf87ae go/packages: handle ad-hoc overlays with sources outside modules
If a user runs a file= query for a source that doesn't exist,
and they are outside of a module, fill in the GoSources for the
empty package that go list returns, so the overlay can be applied.

Also add a hack for the case where go list can't determine the compiler
(gc or gccgo) a user is using because
    go list -f "{{context.Compiler}}" -- unsafe
doesn't work. If go list complains that a user is outside a module,
we'll give ourselves flexibility to guess things because there's
no right answer. So we'll guess that the compiler is gc.

Fixes golang/go#33482

Change-Id: I6a8aa0c617c4d803558389fb4272854245f59c5a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189322
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-08 19:06:35 +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