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

4120 Commits

Author SHA1 Message Date
Lars Lehtonen
61f5e7d299 blog: fix swallowed error
A function created for filepath.Walk in the blog package accepts an error
as its third argument, but then does nothing with it. This change picks up
the dropped error and returns it should it be non-nil.

Change-Id: I68786f7f1f2accbe527994e2d3e7b2f3da257a2d
GitHub-Last-Rev: d740e91601833d1033a6b9709a6c333f9dc3c1bc
GitHub-Pull-Request: golang/tools#183
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203884
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-12-18 19:17:56 +00:00
Rebecca Stambler
d270ebf96e internal/lsp/cache: move overlay and debug handling into separate files
This change has no code modifications. Just move the handling for
overlays and debugging into separate files to make them easier to find.
Also, add some missing copyrights.

Change-Id: I7256f704c017457fa3418818d03f89f061af6fc9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211757
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-18 19:17:43 +00:00
Heschi Kreinick
bc4a8d3946 internal/lsp/cache: don't invalidate dependents' metadata
Rerun of CL 210458. Only invalidate metadata for packages directly
involving the changed file.

Change-Id: Id28647851254a9bdcb3dbe7a762194bb025da913
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211779
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-18 18:41:16 +00:00
Billie Cleek
6f9e13bbec internal/lsp/debug: print the debug port
Print the debug port to stderr when the debug server listens on a
dynamic port so that clients can determine which port to use when
launching a browser to the debug view.

Change-Id: I92f5e334df5cefdf54f7242ac2328b026852c70e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211798
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-12-18 04:04:34 +00:00
Rohan Challa
62a9628863 internal/lsp: use the -modfile flag to update a different go.mod file
In the upcoming Go 1.14 release, there is an introduction of the -modfile
flag which allows a user to run a go command but choose where to direct the
go.mod file updates. The information about this can be found here: golang/go#34506.

This change starts setting up the infrastructure to handle the seperate modfile
rather than keep changing a user's go.mod file. To support versions of Go that are
not 1.14, we run a modified "go list" command that checks the release tags to see
if 1.14 is contained.

Updates golang/go#31999

Change-Id: Icb71b6402ec4fa07e5f6f1a63954c25520e860b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211538
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-17 22:15:16 +00:00
Jay Conrod
210e553fe1 cmd/fiximports: fix 'go list' error formatting
Error positions should be printed, when specified.

Also, made main_test less picky about whitespace before and after
error output.

After this change, the test for cmd/fiximports should pass before and
after CL 210938.

Updates golang/go#36087

Change-Id: I681d1ee07f7f19a0d9716b88678e2737f4c691de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211337
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-12-17 20:38:50 +00:00
Rebecca Stambler
38570b7665 internal/lsp: fix links for interface methods
This change handles fixes the link behavior for interface methods.
For example, before this change, hovering on "Name"  would point to an
incorrect link: https://pkg.go.dev/go/types?tab=doc#object.Name.
The correct link is
https://pkg.go.dev/go/types?tab=doc#TypeName.Name.

var typ *types.Named
typ.Obj().Name()

Change-Id: If28bff6069239d487e5d86cacafc20800493ebe8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211585
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-17 19:37:44 +00:00
Muir Manders
640059499b internal/lsp: kill some dead code
Clear out a few things I noticed aren't really used anymore.

Change-Id: I03f955015632197b56230ae0443cfb3871b54db2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211717
Run-TryBot: Muir Manders <muir@mnd.rs>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-17 19:30:50 +00:00
Rebecca Stambler
f2a421a9e5 internal/lsp: change completionBudget to milliseconds
Change-Id: Ic12f6325bc8307056481edff61da06cfc4f232b3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211677
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
2019-12-17 18:37:38 +00:00
Bryan C. Mills
01c78d57fd internal/imports: set the Dir field on the build.Context (instead of WorkingDir) if present
Updates golang/go#36168

Change-Id: Ibdb277176a28da72d85a4c7c8ed7c903c278125e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211599
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-12-17 14:41:53 +00:00
Jorge L. Fatta
0b43622770 fix: using section links to IDE specific doc
Fix the link to the IDE specific usage documentation (now under /doc/ folder).

Change-Id: Ib0efb8a107195317c7a4a535fc9f624fe277840e
GitHub-Last-Rev: 66f771f799c1e93fd9337040f0b1166061f6419e
GitHub-Pull-Request: golang/tools#192
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211561
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-12-17 14:12:49 +00:00
Ian Cottrell
bbbf87ae26 gopls: add status and roadmap to the main readme.
Change-Id: I5794d1afd0bcddbe3c1a4e2546133df4ce044e2f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211577
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-17 03:36:36 +00:00
Rebecca Stambler
42268a1f04 internal/lsp: fix link anchors for struct fields
This change fixes the link anchors for fields within a struct or
composite literal by getting the enclosing types.Type.

Fixes golang/go#36138

Change-Id: I534a900fad6fa6fa1b1acaa5a63ca264c5d34c39
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211582
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-17 02:48:38 +00:00
Rebecca Stambler
c39ce2148d internal/lsp: expose option to disable timeouts for completion
This is useful for integration testing.

Fixes golang/go#36142

Change-Id: I175510df19f384a0a027267337925ebae15ef827
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211584
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-17 01:14:48 +00:00
Heschi Kreinick
621d4eef75 imports: pass more of the environment
goimports now wants various module flags, but I forgot to set them up in
the many places we create environments. Do so.

Change-Id: Ic3817caeb8fc4d564b49006ef6ca6842b2498eaf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211581
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-17 00:36:01 +00:00
Heschi Kreinick
846828e8ce internal/lsp/source: fix crash on conflict markers in imports
Generally speaking, if the imports package can operate on a file, we can
assume that it's in good enough shape for the rest of our work. That
means it's important we run imports first. On one code path, we weren't.

Fixes golang/go#36162.

Change-Id: I750aff31e0c3706aeb798ceb60c35ea17ba95943
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211580
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-16 23:08:29 +00:00
Rebecca Stambler
1d943b0903 internal/lsp: change CompletionItem.{Command,TextEdit} to pointers
This is a continuation of the discussion on
https://github.com/microsoft/vscode-go/issues/2920. Add corresponding
checks to internal/lsp/cmd/capabilities_test.go.

Change-Id: I51af05dee9e7ecea0e40733dd4c5ca3dfb8f4dd8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209859
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-16 22:14:42 +00:00
Heschi Kreinick
4981f6b3ad internal/lsp/cache: consolidate snapshot cloning
Cloning is complicated enough without worrying about concurrency, so
hold the snapshot's lock during the entire process.

Consolidate everything into one function. I don't think that the split
was making it easier to understand, and I was able to see and clean up
some extra complexity once it was all in one place. Let's discuss
options if you think the result is too long.

I don't intend any semantic changes in this CL.

Updates golang/go#35638.

Change-Id: I05c4b28875976293f5fcd56248d9c9e468f85cc6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211537
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-16 21:51:44 +00:00
Arda Güçlü
99b39703f4 internal/gopathwalk/walk: add missing function descriptions and renaming
Missing function descriptions are added. init is renamed setIgnoredDirs.

Change-Id: I56b5a7c3e4fcc27991b33aef16d506948ce4b36b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208358
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-12-16 21:45:07 +00:00
Arda Güçlü
bcb65d52f1 benchmark/parse: add unit test for String function
Unit test function is added for benchmark's String function.

Change-Id: I60c678d2df4022191e1d5c28c0adf996867dbaf7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208578
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-16 21:43:19 +00:00
Muir Manders
a6aac22fcd internal/lsp: fix find-implementation for promoted methods
We weren't returning promoted methods as implementations when the
promoted method was defined in a different package than the type
implementing the interface.

Fix by properly mapping the implementer types.Object to its containing
source.Package.

I generalized the implementations() result to just contain the
implementer objects and their containing package. This allowed me to
get rid of some result prep code in Implementation().

Fixes golang/go#35972.

Change-Id: I867f2114c34e2ad39515ee3c8b6354c1cd35f7af
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210280
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-16 21:36:29 +00:00
Dmitri Shuralyov
53d48bfcf5 go/analysis: gofmt snippets in package documentation
Tab widths may vary, making tabs suitable for indentation but
not alignment. Use spaces for alignment instead, as gofmt does.

This improves the readability of the package comment on pkg.go.dev.

While here, also make use of blank lines more consistent: two blank
lines before a heading, and a single blank line everywhere else.

Change-Id: I6b6a67b413d02066e2ce233f09d49c1ccdf28a84
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209457
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-12-16 21:03:07 +00:00
Jędrzej Szczepaniak
a0e659d513 internal/lsp, internal/tool: clean up command line of gopls
Descriptions of certain commands were changed to not start with capital
letter.

All of the commands were splitted into so called main
commands and feature commands.

Package tool did have a limitation that revealed itself when command
was invoked only with `-h`, i.e. `gopls -h`. Limitation was that in
above mentioned case, FlagSet.Parse() was intercepting `-h` flag and
printing just default usage.

Updates golang/go#35855

Change-Id: I9bd27fc72e8fb8d18025d95ebcae974dd5583e91
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210359
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-12-16 17:36:52 +00:00
Muir Manders
49a3e744a4 internal/lsp: remove useless signature cast completion candidate
In a previous change I inadvertently added completion candidates like:

var f func(int)
f = <> // useless candidate "func(int)(<>)"

Ignoring the fact it is a syntax error without more parens around the
signature, it isn't a useful candidate because you don't need to cast
when assigning a named signature type to an unnamed type.

Change-Id: Ic261817af344ee47193240a11dca5d3a32cbd293
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211319
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-16 05:27:35 +00:00
Rohan Challa
04c2e8eff9 internal/lsp: skip return highlighting if cursor is in arglist of func
If the cursor is within an argument that is within a callExpr which is
in a return statement, we only want it to highlight the ident that the cursor
is in. We do not want it to highlight the entire function.

Updates golang/go#34496

Change-Id: If4025660a99fd5df90098e0560a5e9e7260e33c8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211338
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-13 22:12:58 +00:00
Rohan Challa
56463cc14b internal/lsp: create parseModHandle for storing go.mod data
Created an analogous data structure for go.mod files when we parse them
using the golang.org/x/mod package. Gopls can now access the data
within a go.mod file using a parseModHandle and the corresponding
parseModData object. This will help down the road when it is time
to implement the lsp functions for go.mod files.

Updates golang/go#31999

Change-Id: Ibd4d64569bbe3df61b203490b63399d479e7d794
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211303
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-13 22:03:54 +00:00
Rohan Challa
7ebc6af015 internal/lsp: add diagnostic on import causing import cycle
After the addition of golang/go#35964, the import cycle error now
has the import stack attached in the message. This CL parses that
stack and attached the import cycle diagnostic to the import versus
just adding it to the first character of the .go file.

Fixes golang/go#33085

Change-Id: I6f5f067c338879b898829951236f816aa63d9dfa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210942
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-13 19:54:01 +00:00
Rebecca Stambler
74e303f875 internal/lsp/source: fix error message for multiple GOPATHs
The current handling of error messages did not address the case that a
user may have multiple directories listed in their GOPATH.

Fixes golang/go#36120

Change-Id: I8e68a45d3dd902975a0ccf4177ec2698accdf69d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211304
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-13 19:21:09 +00:00
Iskander Sharipov
27b81bef4a internal/lsp/tests: add error handling for @item()
If there are less than 3 args for @item, it does an early
return without recording it for a given pos.
This leads to a panic when tests runner can't lookup
a non-nil item for a pos.

Since other collect* methods seem to use t.Fatal for error
handling, do the same in collectCompletionItems().

Change-Id: I21960731f532b93029e6e06800e0484dc7d599df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211257
Run-TryBot: Iskander Sharipov <quasilyte@gmail.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-13 18:39:29 +00:00
Jeff Hodges
7093a17b04 go/packages: correct logging of driver stderr
This moves the GOPACKAGESPRINTDRIVERERRORS and stderr.Bytes() checks to after
the driver command is run. Before, these were checked before the driver command
was run and so stderr was always empty.

Change-Id: I8fb3d45eab5dacee3871d454038fbcc1b6351cb6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207581
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-13 03:22:37 +00:00
Muir Manders
0f69de236b internal/lsp: offer basic type conversion candidates
When the expected type is a basic type, we will now offer a
corresponding type conversion candidate. For example:

var foo int64
foo = // offer "int64(<>)" as a candidate

The type conversion candidate will be ranked below matching concrete
candidates but above the sea of non-matching candidates.

This change broke almost every completion test. I added a new
completion option for literal candidates so tests can selectively ask
for literal completions.

Updates golang/go#36015.

Change-Id: I63fbdb33436d662a666c1ffd3b2d918d840dccc7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210288
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-12 22:41:01 +00:00
Rebecca Stambler
cfcbc7796e internal/lsp: improve link in documentation on hover
This change refactors some of the logic that builds a link anchor for
a given symbol, pushing the actual Link into the HoverInformation struct.
This is necessary because type information is needed to build up that
link in certain cases, like methods.

The last step will be to correctly display struct fields.

Updates golang/go#34240
Fixes golang/go#36031

Change-Id: I7f989faddbaa07f91838a870b4477bf78ce8ddf7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210201
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-12 22:39:21 +00:00
Rebecca Stambler
8facea2ecf go/packages: disable -mod=readonly behavior in overlays
This was preventing mod files from being updated when dependencies were
added to overlays. This prevents gopls from accurately modifying a user's
mod file when a dependency is added, which poses problems for usability.
To handle the issues that this was (supposedly) solving, we can require
that files from multiple modules are never added in an overlay.

For some reason, this doesn't break TestOverlayModFileChanges.

Change-Id: I24d6c30754c2bebc440802f7cf2931d98e450ebf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211058
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-12-12 20:31:36 +00:00
Muir Manders
825cb06263 internal/lsp: downrank "nil" completion candidate
Having nil ranked normally causes it to show up as the top candidate
in cases like:

context.WithCancel(<>) // "nil" shows up before "context.Background()"

"context.Background()" gets a slight score penalty since it is a deep
completion, so "nil" is ranked highest.

Sometimes you do want "nil", but it's such a short identifier you
probably aren't leaning too heavily on autocompletion. I think it
makes sense to optimize for the case when you want something non-nil.

Change-Id: I537927db2b573535e751380c4cba5c9873dfe524
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210539
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-12 05:12:00 +00:00
Rebecca Stambler
56eb7d2c19 internal/lsp: don't resend diagnostics if they are unchanged
Cache delivered diagnostics on the server so that we can determine if
they should be resent. To be careful about this, we only reuse cached
diagnostics if they are for a greater version, or if we don't know
the file's version and it is unchanged.

Fixes golang/go#32443

Change-Id: I4ba22d85e5b21a8ad6cc62f74cd83c07d3c220cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208261
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-12 04:27:51 +00:00
Rebecca Stambler
4403f79810 internal/lsp: move DidModifyFile into internal/lsp/cache
This change is the next step in unification of text synchronization
methods. The logic really belongs in the internal/lsp/cache package
rather than the internal/lsp package.

Pulled out a function to run diagnostics on a file (diagnostics are still
run async).

Change-Id: I5e237411a02af210ad386b37a6c2aa62ef723567
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210784
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-12-12 03:49:59 +00:00
Muir Manders
dfebd2802a internal/lsp: fix find-references to search from all package variants
We previously searched the reverse dependencies of the "widest"
package that contained out starting identifier, but if our package has
tests then the widest package is the ".test" variant, and it has no
reverse dependencies. Fix by searching through all of the packages
that contain our starting identifier.

For example:

-- foo/foo.go --
package foo
func Foo() {}

-- foo/foo_test.go --
package foo
func TestFoo(t *testing.T) {}

-- bar/bar.go --
import "foo"
func _() {
  foo.Foo()
}

We would start searching from the foo.test variant, but we wouldn't
search package bar at all because bar does not import foo.test, it
imports plain foo. Now we search from both foo and foo.test (you still
need search foo.test to find references within foo_test.go).

Fixes golang/go#35936.

Change-Id: I5fd2f7bb130a421ed6fad92da11179995c99a2cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210537
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 23:36:49 +00:00
Rohan Challa
ad473c03aa internal/lsp: add handling for go.mod files in internal/lsp functions
When we are processing a go.mod file, we are calling go/packages.load
when we should not be. It will always return 0 packages since it is
not a .go file. This CL adds branching inside each internal/lsp protocol
function and also adds a check in snapshot.PackageHandles for the file type
and returns an error. This will prevent `go list` from running on go.mod files for now.

Updates golang/go#31999

Change-Id: Ic6d0e9b7c81e1f404342b98e10b9c5387adde2ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210757
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-11 23:24:34 +00:00
Muir Manders
4da4485a1c internal/lsp: invalidate metadata and type info more selectively
Say you have foo.go and foo_test.go yielding packages "foo" and
"foo.test". Previously when you changed foo_test.go we would
invalidate the foo.test and foo packages. Invalidating foo is not
necessary since it does not depend on any test files. Furthermore, it
caused problems because nothing would refetch foo's metadata until
foo.go changed, so various things (such as finding implementations in
packages that depend on "foo") would be broken.

Now we only invalidate metadata from packages that contain the
modified file. We only invalidate type info from packages that contain
the modified file, or from such packages' transitive reverse
dependencies.

Change-Id: I23d1af91bcdf22fad4faa1b048afe17ef4e403a1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210460
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 23:14:03 +00:00
Iskander Sharipov
ec14b29651 internal/lsp/source: fix all types in resolveInvalid
This CL teaches lsp to report `**T` instead of `**invalid type`,
`func (badParam) badResult` instead of `func (invalid type) invalid type`, etc.

To do that, we need to detect "invalid type" inside any part of a type.
I've added typeIsValid() function for that.

To simplify type formating code in resolveInvalid(), formatNode
function is added that can also format *ast.StarExpr (of any depth).
Since we already used AST printer in the same file, I
added formatNode function that is now used in both places.
While at it, replaced bytes.Buffer to strings.Builder there.

Change-Id: I3bb84c58c417b175cceefb410e238c48425f7cee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210357
Run-TryBot: Iskander Sharipov <quasilyte@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 23:00:51 +00:00
Rohan Challa
ac2db28e81 internal/lsp: invalidate workspace packages when go.mod file changes
When the go.mod file changes, we should invalidate all the files that are
contained in the package for the mod file. This will allow the files to recheck
their packages in case new packages were added in the go.mod file.
This still does not fix issue where changes to go.mod files do not trigger recalculation of diagnostics.

Updates golang/go#31999

Change-Id: I6d8f1531f5c28ed2dca7fb8ad4ee0317fada787b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210557
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 22:23:25 +00:00
Muir Manders
a27fdba277 internal/lsp: check all package variants in find-implementations
We previously only searched for implementations of the object we found
in the "widest" package variant. We instead need to search all
variants because each variant is type checked separately, and
implementations can be located in packages associated with different
variants.

For example, say you have:

-- foo/foo.go --
package foo
type Foo int
type Fooer interface { Foo() Foo }

-- foo/foo_test.go --
package foo
func TestFoo(t *testing.T) {}

-- bar/bar.go --
package bar
import "foo"
type impl struct {}
func (impl) Foo() foo.Foo { return 0 }

When you run find-implementations on the Fooer interface, we
previously would start from the (widest) foo.test's Fooer named
type. Unfortunately bar imports foo, not foo.test, so bar.impl
does not implement foo.test.Fooer. The specific reason is that
bar.impl.Foo returns foo.Foo, whereas foo.test.Fooer.Foo returns
foo.test.Foo, which are distinct *types.Named objects.

Starting our search instead from foo.Fooer resolves this issue.
However, we also need to search from foo.test.Fooer so we match any
implementations in foo_test.go.

Change-Id: I0b0039c98925410751c8f643c8ebd185340e409f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210459
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 21:44:05 +00:00
Rohan Challa
3785370768 internal/lsp: fix circular import errors to account for import stack
Hotfix for broken tests after the import stack got added to the circular import
error statement.

Change-Id: I0179b9590cad38cf9cb903f9932d9bf8fb8dc6df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210939
Run-TryBot: Rohan Challa <rohan@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-11 19:05:55 +00:00
Michael Matloob
0d08730209 go/packages: add import stack to error messages when there's an import cycle
This amends the error message to add the import stack for import cycle
error messages. The information in structured in the go list error, but there's
no good place to put the information in the go/packages error.

One alternative is to add the import stack field to go/packages's error type,
but we can always do that later if necessary.

Change-Id: I5ea25e4cafd23d69d5589dd2430f39ece70173f7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210079
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 18:27:46 +00:00
Muir Manders
912f50adde internal/lsp: don't invalidate dependents' metadata
When a file is changed, we invalidate various cached data so we
re-type check and refetch metadata as needed. Previously when a file
changed we would delete the metadata for all transitive reverse
dependencies. This broke all-packages-in-workspace features since we
could no longer fetch the package handle for packages without
metadata.

Fix by only deleting metadata for the packages that the file being
changed belongs to. It doesn't seem like a package's metadata contains
anything that is sensitive to changes in the package's dependencies.

Change-Id: I6a2d5df49ecd4d627b37689e48ed48fe78ce658d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210458
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 18:25:29 +00:00
Clint J Edwards
98df123772 internal/lsp: add comment completions for exported vars
This should provide simple name completions for comments
above exported variables.

Can be activated with `ctrl+space` within a comment.

Pretty new, so all help is welcome.

Fixes #34010

Change-Id: I1c8f71baa3beaa22ec5fd9fd4a531284a8d125f3
GitHub-Last-Rev: a9868eb69dc587cb4579268b2c3ae46932702641
GitHub-Pull-Request: golang/tools#166
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197879
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-10 22:11:41 +00:00
Iskander Sharipov
fe93f4a7d4 internal/lsp: suggest "fallthrough" only inside switches
Change-Id: I3a6ddbc12e068da151699a1d0377670695dcf5aa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210358
Run-TryBot: Iskander Sharipov <quasilyte@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-10 22:10:49 +00:00
Peter Weinberger
1bcf67c9cb internal/lsp: Make Text in DidSave at *string rather than a string
Fix code.ts to match CL 210780.

Change-Id: Iaaa1f8b78d483e4281e6d513cf4d20ae44e46cb7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210783
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-10 20:07:04 +00:00
Rebecca Stambler
0bd90eac95 internal/lsp: make Text in DidSave request a pointer
Fixes golang/go#36063

Change-Id: I223ead138111239ae1894f5565414ac384c016e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210780
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2019-12-10 19:28:57 +00:00
Heschi Kreinick
22774f7dae internal/lsp/cache: invalidate metadata even without Create
When a new file is opened, the first time we learn about it will be a
didOpen event. We need to invalidate the package's metadata in that
case too.

Fixes golang/go#35638.

Change-Id: I36c6171e9c959c48ede9e125679e8dd1be7609f4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210559
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-09 22:52:34 +00:00