Instead of using the entire import node as the range for the
link, use only the link text in the path node itself. This looks
better when using a _ or named import, as well as constraining
the link to inside the quotes.
Fixesgolang/go#35565
Change-Id: Ie93d9df993fbd8e0106ca6c3b40e0885355be66b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207137
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
This change is the first step in centralizing control of modifications
to different files, either within the workspace or outside of it. We add
a source.FileAction type to pass into the internal/lsp/cache package and
handle the difference between opening and creating a file.
Now that we load all packages in a workspace by default, we no longer
need to re-load a file on open. This CL should enable CL 206883 to work
correctly.
Change-Id: I2ddb21ca2dd33720d668066e73283f5629d02867
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206888
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Test function is added for formatNs function in the benchcmp package.
Change-Id: I9a1050be9fba3b5e217741d3faadbf5d913d1d4d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206857
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This change propagates the versions sent by the client to the overlay
so that they can be used when sending text edits for code actions and
renames.
Fixesgolang/go#35243
Change-Id: I8d1eb86fe9f666f7aa287be5026b176b46712c97
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205863
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This will allow us to use the public API to generate the events.
This avoids creating the structs by hand.
It also helps tests the other API.
Change-Id: Ic90cbbaf6fc97c2a3e6a5ff64dccdff0d65ec865
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206885
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This checks against the json form rather than the wire structs
This will allow the encoding method to change without the test changing.
Change-Id: Iefe84cc03bc6e82627acd031e0991c31b4fed315
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206884
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
The purpose and value of packagestest is easy to understand. However,
the current API may not be easy to get started with. It includes
identifiers such as Exporter, Exported, Export, whose names may not
make it very clear in what order they are to be used, and whether
the Exporter interfaces needs to be implemented by the caller.
There are fairly common patterns of usage spread out across various
packages that use packagestest. Add an example of basic usage to the
documentation of this package that connects all of the pieces together,
so that users don't have to look for it elsewhere.
I would've preferred to add the example as example code¹, but it
doesn't seem viable to write example code for test helper packages.
There isn't a way to get a functional *testing.T in a func Example.
¹ https://golang.org/pkg/testing/#hdr-Examples
Updates golang/go#33655
Change-Id: I0b15ff7974be25a71dfd4b68f470441ce7331d18
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196980
Reviewed-by: Michael Matloob <matloob@golang.org>
Add more detailed instructions for installing and running node
and the typescript compiler on Linux and MacOS.
Change-Id: Id549760dd186d88cfa9b137e6f46dfd4d60d6322
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206887
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This change makes sure that we only return files that contain the given
position. There are a few instances of needing to look up files by URI
in the internal/lsp/cache package, so use an unexported package for
that. This allows us to remove some code in the implementations code.
Change-Id: Ifa7a62c67271826e6c632e4c88667d60f8b760c4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206880
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This change adds support for returning versions along with file URIs, so
that the client can know when to apply changes. The version is not yet
propagated along to the internal/lsp/cache package, so this change will
have no effect (VS Code ignores a version of 0 and still applies the
changes).
A few minor changes made in the rename code (to remove the view
parameter). Some minor staticcheck fixes.
Updates golang/go#35243
Change-Id: Icc26bd9d9e5703c699f555424b94034c97b01d6f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206882
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
If a user is typing fast, they will quickly invalidate many snapshots.
We don't want to stack up a bunch of stale type check and analysis
operations, so we should propagate cancellation through the cache.
Handles are long-lived, so we may cancel an operation only to
restart it again later. Also, there may be multiple operations waiting on
the same computation, and just because one is cancelled doesn't mean we
should necessarily stop. The easiest way to support all that was to add
an explicit state to each handle, and track the number of waiters.
See the code for more details on Handle life cycles.
As far as I can tell, the rest of gopls is prepared for this behavior.
I added an explicit check to the type checking code, where I was worried
it might get overly confused. But long-term it would probably be good to
return an error from Get.
Change-Id: I3ea6e141b52b94300a41248d3f2e039b023709d0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206879
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
We used to need our own copy of astutil.AddNamedImport to use during
completion for a variety of reasons, but I think the major one was
needing to not format the whole file. The same problem applied to using
the imports package.
Happily, that was resolved in CL 205678. Now we can use the same
implementation on both paths. In addition to removing a bunch of code,
that means that unimported completions now add their imports in the
right place, respecting goimports grouping and the local configuration
setting.
Fixesgolang/go#35519.
Change-Id: I693c2e8b5ced9bac62b1febf1e2db23c770e5a7a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206881
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Look in all packages the snapshot knows of (through a new method on snapshot called
KnownPackages) and see if any of those packages contain implementations. Before,
the Implementation call only looked in the current package.
Much of the new complexity in implementation.go is routing through the Type to
Package data in the implementsResult.pkg field so the identifier can be looked up
in its correct package.
Fixesgolang/go#32973
Change-Id: Ifa7115b300f52fb4fb55cc00db2e7f339e8c2582
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206518
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
It looks like the package paths for adhoc package on Windows now keep
the file path's original backslashes, rather than switching to forward
slashes. Remove the filepath.ToSlash call to handle this.
Also, a small change to fix something suggested by staticcheck.
Change-Id: I56bd57ed2448dbc724acb9730673fc9d17f16d06
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206677
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
It uses it to update the config of all active views cleanly
Fixesgolang/go#32258
Change-Id: I7a849941d5022499d48ad640c5b7bc9cf79eb9b9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206148
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
It attempts to detect changes that would invalidate the view and replace itself
with a new view when that happens
Change-Id: I0f1a8cd3bd6ddcef115fedc6c57ae0398b16d3b6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206147
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This change adds command line support for foldingRange.
Provided with a file, it will display a list of folding
ranges within that file, with 1-indexed positions using
the format
{startingLine}:{startingChar}-{endingLine}:{endingChar}
Example:
$ gopls folding_ranges ~/tmp/foo/main.go
$
$ 3:9-6:0
$ 10:22-11:32
$ 12:10-12:9
$ 12:20-30:0
Updates golang/go#32875
Change-Id: Ib35cf26088736e7c35612d783c80be7ae41b6a70
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206158
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
We don't want to return an error for the whole package when we are just
building out error positions.
Change-Id: I56b5b88ff2b4b44da8a372ade81cd9b1534235c4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206597
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Many tests in x/tools invoke the 'go' command found from $PATH.
If that command does not match the 'go' command used to invoke 'go test',
the result will be misleading.
Instead of silently accepting the mismatched result, check the 'go'
tool's self-reported GOROOT and reject it if it doesn't match the 'go'
tool used to invoke 'go test'.
That rejection will cause the x/tools tests to fail if x/tools is the main module.
Updates golang/go#35505
Change-Id: I581906468ef736fad42a0164376a07f876907621
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206517
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Even if the packages.Load of the directory the NewView is being created for
fails, create and add the view. But also return the error from NewView, just
after the new view has been added.
Fixesgolang/go#35468
Change-Id: I76c2d3cbe1a508ad0794a6fcd3bc67cd48c97e22
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206497
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Add `erroras` analysis to the `unitchecker` example that mimics go vet.
The unitchecker according to its comments is an example of replicating
the analysis performed by go vet using the unitchecker. The example is
missing the erroras analysis that was added to go vet in
golang/go@9f76566. This change brings the example back inline with the
analysis performed by go vet.
Closegolang/go#35486
Change-Id: I630146b60c1e62b4685fb173c8c4736d9d713168
GitHub-Last-Rev: 7c3fd4ac8e2465514720238d2c3c1ffb22a6278f
GitHub-Pull-Request: golang/tools#185
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206238
Reviewed-by: Michael Matloob <matloob@golang.org>
This change copies the code in guru's implements implementation
that finds implementations of methods over to gopls, and uses
the information determined to resolve implements requests on
methods. Implements still only works only within packages.
Updates golang/go#32973
Change-Id: I0bd7849a9224fbef7ab8385070b18fbb30703e2b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206150
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Change tsprotocol.go so that the types are in alphabetical order, which
will make it simpler to see what has changed. (In this version only the
git hash and date have changed. The Go code has only been rearranged.)
The typescript code with this tiny change will be submitted in
another CL.
Change-Id: I7055b31075c7b3cda6e23b467205683423529c33
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205499
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Add a special case for append() arguments so we infer the expected
type from the append() context. For example:
var foo []int
foo = append(<>)
We now infer the expected type at <> to be []int. We also support the
variadicity of append().
Change-Id: Ie0ef0007907fcb7992f9697cb90970ce4d9a66b8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205606
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
I assumed that f.Pos() would be the first byte of the file, but it's the
position of the package declaration. This kills the file. Just use 0.
Fixesgolang/go#35458.
Change-Id: Ic77c93344c71435ef8e5624c2f2defb619139a15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206145
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Treat it as okay if no packages are found when loading all the packages in a
workspace. Users may open workspaces that don't have any Go files, either because
they are workspaces for other languages, or because no Go files have been created
yet.
Fixesgolang/go#35455
Change-Id: I60912472ec8930649996edc150d1d19cd74a0a2e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206140
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Previously, if we failed to find an item's documentation, we would not
return the item at all. It seems better to do a best-effort approach,
i.e. return the item without documentation.
Fixesgolang/go#35406
Change-Id: I896ffda2fc79b9210f0d83311808114d0e686820
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205862
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Add a source.Scope type that can be used to refer to directories or
files, and modify (*snapshot).load to take source.Scope.
Then call load in NewView.
Change-Id: I8f03c7b271d700b162100d2890d23219ef9578c2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/204822
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
We want people to add imports as they need them. That means we probably
don't want adding an import to reformat your whole file while you're in
the middle of editing it.
Unfortunately, the AST package doesn't offer any help with this --
there's no good way to get a diff out of it. Instead, we apply the
changes, then diff a subset of the file. Picking that subset is tricky,
see the code for details.
Also delete a dead function, Imports, which should have been unused but
was still being called in tests.
Fixesgolang/go#30843.
Change-Id: I09a5344e910f65510003c4006ea5b11657922315
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205678
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Previously we were erroneously suggesting a "func() {}" literal in
cases like:
http.Handle("/", <>)
This was happening because saw that the http.HandlerFunc type
satisfied the http.Handler interface, and that http.HandlerFunc is a
function type. However, of course, you can't pass a function literal
to http.Handle().
Make a few tweaks to address the problem:
1. Don't suggest literal "func () {}" candidates if the expected type
is an interface type.
2. Suggest named function types that implement an interface. This
causes us to suggest "http.HandlerFunc()" in the above example.
3. Suggest a func literal candidate inside named function type
conversions. This will suggest "func() {}" when completing
"http.HandlerFunc(<>)".
This way the false positive func literal is gone, and you still get
literal candidates that help you use an http.HandlerFunc as an
http.Handler. Note that this particular example is not very compelling
in light of http.HandleFunc() which can take a func literal directly,
but such a convenience function may not exist in other analogous
situations.
Change-Id: Ia68097b9a5b8351921349340d18acd8876554691
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205137
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Improve candidate ranking when completing the variadic parameter of
function calls.
Using the example:
func foo(strs ...string) {}
- When completing foo(<>), we prefer candidates of type []string or
string (previously we only preferred []string).
- When completing foo("hi", <>), we prefer candidates of type
string (previously we preferred []string).
- When completing foo(<>), we use a snippet to add on the "..."
automatically to candidates of type []string.
I also fixed completion tests to work properly when you have multiple
notes referring to the same position. For example:
foo() //@rank(")", a, b),rank(")", a, c)
Previously the second "rank" was silently overwriting the first
because they both refer to the same ")".
Fixesgolang/go#34334.
Change-Id: I4f64be44a4ccbb533fb7682738c759cbca3a93cd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205117
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This change implements initial support for viewing Go package
documentation with godoc in module mode. There are no UI changes.
When running the godoc binary in a directory where module mode
is active (i.e., go env GOMOD reports a non-empty path), the
documentation will be shown for packages provided by modules
rather than from the GOPATH workspace.
The mode can be controlled in the same way as the go command, by
changing the GO111MODULE environment variable¹ value. For example,
'GO111MODULE=on godoc' will force godoc to run in module mode, and
'GO111MODULE=off godoc' will force godoc to run in GOPATH mode.
It is implemented by reusing the existing virtual filesystem
abstraction. The main module and all of its dependencies (in
other words, the build list²) are determined by invoking the
go list -m all command in the same directory. An attempt is
made to fill the module cache with any selected module versions
that are not already in the local module cache.
This behavior can be controlled in the same way as the go command,
by setting the GOPROXY environment variable. For example, setting
GOPROXY=off disables downloading of any modules. If any of the
modules could not be fetched, it is printed to stderr and
documentation is shown for all other available packages.
¹ https://golang.org/cmd/go/#hdr-Module_support
² https://golang.org/cmd/go/#hdr-The_main_module_and_the_build_listFixesgolang/go#33655
Change-Id: I86f795537b65acae3771afd19d2e7cb360425467
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196983
Reviewed-by: Andrew Bonventre <andybons@golang.org>
A general mechanism for modifying the features in command line tests
Use it to turn of go-diff for now
Fixesgolang/go#35392
Change-Id: Ie79723e94fb14fcde1e98709a63f44046e101bc4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205739
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
In CL 205501 I thoughtlessly set import name to package name, but really
we only want to name imports when goimports would do it. For now, it's
better to not name them and let the usual imports code add a name if
necessary.
Fixesgolang/go#35397.
Change-Id: Id0df866f95e5e86ed72b25fbd1a7224c79ee8084
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205657
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Provide more information to help users when the go list command intended to determine
the GOARCH and Go compiler fails. This usually happens because there's an issue in
the main module.
Fixesgolang/go#30355
Change-Id: I0ce1cfc55cb0ee793bdd1e6fd261a4f98a44abd8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/204357
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
I forgot to set .Name on completion candidates. That meant that if the
package name didn't match the import path, you'd first get an import
without a name, then it would be added when you organized imports.
Change-Id: Ic374de872324effa6bc04c1440c659d7a182d17f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205503
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Add a new "verboseOutput" config flag (defaults to "false") to enable
verbose go/packages and imports output. Previously this output was
always present.
The go/packages output would dump out the entire (humongous) "go list"
JSON response which would lock up my editor for a second whenever
something triggered a go/packages call.
The imports output would produce a bunch of "gopathwalk" debug
messages that aren't useful in general and in particular add noisy
output to tests.
Change-Id: Ie4693d074cb84f1397e0e51d7346dc9391bd1278
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205138
Reviewed-by: Koichi Shiraishi <zchee.io@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Unimported completions now try to pull Packages from everywhere, not
just the transitive dependencies of the current package. That confused
the import formatting code, which only looked at deps. Pass the Package
along with the import suggestion, and use it when it's present.
Also change some error messages to be different for diagnostic purposes.
Fixesgolang/go#35359.
Change-Id: Ia8ca923e46723e855ddd2da7611e6eb13c02bb4f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205501
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
The special handler was dropped in cl/191963 which moved the logging functionality, but
was still needed for the rpc metrics
Change-Id: I494ef47646fe0d705709694378dbc981b549622a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205164
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
There was a dealock introduced in cl/190737 on all the internal structure
debug pages.
The object getters all protect with the mutex already, it should not also
be done in the outer Render function
Change-Id: I5c85dc8e2ec489e59ca5a80128f2649dd7753983
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205165
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Loading completion suggestions can be slow, especially in GOPATH mode
where basically anything can change at any time. As a compromise, cache
everything for 30 seconds. Specifically, after a completion operation
finishes, if the cache is more than 30 seconds old, refresh it
asynchronously. That keeps user-facing latency consistent, without
chewing up CPU when the editor isn't in use. It does mean that if you
walk away for an hour and come back, the first completion may be stale.
In module mode this is relatively benign. The only things the
longer caching affects are the main module and replace targets, and
relevant packages in those will generally be loaded by gopls, so they'll
have full, up-to-date type information regardless.
In GOPATH mode this may be more troublesome, since it affects
everything. In particular, go get -u of a package that isn't imported
yet won't be reflected until the cache period expires. I think that's a
rare enough case not to worry about.
Change-Id: Iaadfd0ff647cda2b1dcdead9254b5492b397e86e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205163
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
We intend to use the GOPATH resolver's results during LSP
autocompletion. That means we have to be able to cache its data, same as
we do for modules. Convert it to use a dirInfoCache.
Cache exports in the dirInfoCache. Along the way, store exports as slices
rather than maps. We don't need the extra structure the vast majority of
the time, and the memory overhead is nontrivial.
Change-Id: If267d6b00da2163a960b93b2cf2088ec2538f73d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205162
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Packages that aren't imported in the current file will often have been
used elsewhere, which means that gopls will have their type information
available. Expose loaded packages in the Snapshot, and try to use that
information when possible for unimported packages.
Change-Id: Icb672618a9f9ec31b9796f0c5da56ed3d2b38aa7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/204824
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
When a user completes rand.<>, propose rand.Seed (from math/rand) and
rand.Prime (from crypto/rand), etc.
Because we don't necessarily have type checking information for
unimported packages, I had to add shortcut cases to a number of
functions around the completion code. Better suggestions welcome.
Change-Id: I7822dc75c86b24156963e7bdd959443f4f2748b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/204819
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Muir Manders <muir@mnd.rs>