Граф коммитов

8594 Коммитов

Автор SHA1 Сообщение Дата
Alan Donovan 4794229b8c gopls/internal/golang: RenderPkgDoc: add <title> element
...following pkg.go.dev.

Change-Id: Ibf55871a4f7b4f160c1f83de5e3bec07b287ad9f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576915
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2024-04-05 15:37:04 +00:00
Alan Donovan 2db5a34c05 gopls/internal/golang: RenderPkgDoc: navigational <select>
This CL adds a <select> element with an index of all
sections in the page, following the design of pkg.go.dev.

Change-Id: I41b6719e85d0ace7edb864c5b20ae1f5b8e39d1b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576596
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-05 14:38:06 +00:00
Alan Donovan 11c692eb24 gopls/internal/test/marker/testdata: skip hover size tests on 32-bit arm
Fixes golang/go#66686

Change-Id: I74388fa8788ff6893146e3ca0cdfccfd28275625
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576657
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2024-04-04 21:32:40 +00:00
Gopher Robot fc660e510f go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: Ibb4c78e3b460f607474ae0433392c85bc2e60511
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576616
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
2024-04-04 20:44:12 +00:00
Alan Donovan 6590f47255 internal/gcimporter: renable tests of issue50259.go
Now that the compiler support for gotypesalias=1 is
fixed (by CL 574737), we can reenable these tests.

Updates golang/go#66550
Updates golang/go#65294

Change-Id: I70b187c561d2eeb3f7a4cc078107b7bcce5ced01
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576139
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2024-04-04 19:28:08 +00:00
Alan Donovan f1d5252456 gopls/internal/golang: Hover: show wasted % of struct space
This change causes Hover to reveal the percentage of a struct
type's size that is wasted due to suboptimal field ordering,
if >=20%.

+ test, release note

Fixes golang/go#66582

Change-Id: I618f68d8a277eb21c27a320c7a62cca09d8eef0a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575375
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2024-04-04 16:56:32 +00:00
Alan Donovan 951bb4069c gopls/internal/test/integration/misc: fix flaky test
The random base64 strings in gopls URLs caused occasional
spurious matches for the substring t1. This change uses
a non-base64 letter to eliminate this source of
nondeterminism.

Change-Id: I1db1dca8d93cc299b13b591567fa72b2227ac436
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576140
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-04-04 13:59:32 +00:00
Alan Donovan c9b0c65fdb gopls/internal/analysis/fillreturns: skip test if gotypesalias=1
It changes (improves) the behavior of the test; we will reenable
it once the default has changed.

Updates golang/go#65294

Change-Id: I716da405a9f0c03c303c4c0be8b738dd7c5ebdcd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576137
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-03 23:06:45 +00:00
Robert Findley c623a2817b gopls/internal/cache: fix crash in snapshot.Analyze with patch versions
Fix the same crash as golang/go#66195, this time in Analyze: don't set
invalid Go versions on the types.Config.

The largest part of this change was writing a realistic test, since the
lack of a test for golang/go#66195 caused us to miss this additional
location. It was possible to create a test that worked, by using a flag
to select a go1.21 binary location.

For this test, it was required to move a couple additional integration
test preconditions into integration.Main (otherwise, the test would be
skipped due to the modified environment).

Fixes golang/go#66636

Change-Id: I24385474d4a6ebf6b7e9ae8f20948564bad3f55e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576135
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-03 19:36:59 +00:00
Robert Findley f345449c09 gopls/internal/server: filter diagnostics to "best" views
Filter diagnostics only to the "best" view for a file. This reduces the
likelihood that we show spurious import diagnostics due to module graph
pruning, as reported by golang/go#66425.

Absent a reproducer this is hard to test, yet the change makes intuitive
sense (arguably): it is confusing if diagnostics are inconsistent with
other operations like jump-to-definition that find the "best" view.

Fixes golang/go#66425

Change-Id: Iadb1a01518a30cc3dad2d412b1ded612ab35d6cc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/574718
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-03 18:28:02 +00:00
Robert Findley 42d590c9cf gopls/internal/test/integration: add a WriteGoSum run option
Working with go.sum files in integration tests was cumbersome, involving
temporarily modifying the test to call env.DumpGoSum(...), then copying
its output into the static go.sum file.

For some tests, we may actually want to check in a fixed go.sum file,
but the majority of the tests just want to avoid go.sum errors. To
support this use case, add a new RunOption that writes the go.sum file
before starting the test. Use this option in a test to illustrate its
usage.

Also, update DumpGoSum to use the faster "./..." pattern to create the
go.sum output. "..." matches all modules, but we only care about the
main module.

Change-Id: I32cca005e10411033422cf8fee64cbd56e83f64c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575700
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-04-03 15:32:40 +00:00
Alan Donovan 53d35a51d3 gopls/internal/golang: RenderPackageDoc: fix doc links
Previously, a variety of links generated by the go/doc/comment
package were not valid. This CL configures the parser and printer
hooks to query the cache.Package representation, and now
generates valid crosslinks for all references.

Tested interactively on a wide variety of cross links.

Change-Id: Iaf1fffe52ea96e3be5df78227cf8395006caa59a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575377
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-03 14:07:30 +00:00
Alan Donovan 222cddee50 internal/analysisinternal: ZeroValue: support materialized aliases
My previous audit of this file contained a mistake in the order
in which constructors were tested; it was revealed by testing
with gotypesalias=1.

Updates golang/go#65294

Change-Id: I80f6f0bb24bceb2c69b9919e9c482b780c0d546a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575699
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2024-04-02 20:54:20 +00:00
Alan Donovan 0a4fc723d7 internal/gcimporter: support materialized aliases
This CL adds support for preserving materialized aliases
while types transit export data (indexed or unified).

(This CL depends on CL 574737 to the compiler and
go/types.)

Updates golang/go#65294
Updates golang/go#64581

Change-Id: I1a0a08357e4f6a480ba6250fbea327922e455873
Reviewed-on: https://go-review.googlesource.com/c/tools/+/574717
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-04-02 20:54:11 +00:00
Alan Donovan 85b65275a6 gopls/internal/test: temporarily disable staticcheck with gotypesalias=1
staticcheck will need work to accommodate gotypesalias=1.
In the meantime we disable this test in that mode; we plan
to reenable it before the next gopls release.

Updates golang/go#65294

Change-Id: I857edb758f83f180a4d92b7100e99c3401b1d957
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575698
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-02 20:54:01 +00:00
Alan Donovan 118b98be87 gopls/internal/golang: RenderPackageDoc: emit anchors for var/const
This CL causes the package rendering to emit an <a id=...> anchor
for each name defined by a var or const declaration.

Also, choose the initial fragment id (e.g. "#Buffer.Len") based
on the selection.

+ Test that anchors are emitted.

Change-Id: Idb4838a6d2741a26cd9dbb5ad31a76d6f811ff26
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575697
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-04-02 20:45:46 +00:00
Alan Donovan 1e68fee9c2 gopls/internal/server: "view package doc" of package under test
When "View package documentation" is invoked in a _test.go file,
this change ensures that the documentation for the package under
test is displayed, instead of a 404 Not Found.

Change-Id: I9c9f2205d6ec72cbe5acea1480acdbf2bd3b8b53
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575695
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-04-02 20:23:42 +00:00
Alan Donovan b303e13db8 gopls/internal/golang: view pkg doc: display when "disconnected"
This CL causes the "View package doc" pages to display a
banner when the gopls server dies, at which point the page
is no longer operative. (A new server will have a different
port.)

Change-Id: Icde10a7b4c25a28177d043c573dfdab4ce7c7964
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575536
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-02 20:23:35 +00:00
Tim King 41a9213ce5 go/packages: report type errors unconditionally
Ensure that when types.Checker.Files returns an error some
error is always reported and the package is illTyped.

Adds an additional hint to recompile the tool when types returns
an error "package requires newer Go version 1.22" or similar.

Updates golang/go#65608
Updates golang/go#66525

Change-Id: I131ee3e668815f88d16a18c6e92f002220284a03
Reviewed-on: https://go-review.googlesource.com/c/tools/+/574255
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-04-02 19:54:57 +00:00
Alan Donovan 7204363f23 gopls/doc/release/v0.16.0.md: augment notes for "view pkg doc"
Change-Id: Ieaef6c74b7fe1f7d736c1fb23c13c7569193ff3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575376
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-01 14:40:43 +00:00
Alan Donovan 904c6baa6e gopls/internal/settings: enable "unusedwrite" analyzer
This analyzer shows a very high rate of true positives,
indicating that code is (at best) unnecessarily complex
and confusing but, often, not working as intended.

+ release note

Fixes golang/go#44461

Change-Id: I1c86e7305a8d512d7e4d1bbec3b2b44ce3a9c9ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575061
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-03-29 17:16:18 +00:00
Alan Donovan 96639992ee gopls/internal/golang: hover: show size/offset info
This change causes Hover to report size information for
types and struct fields when hovering over
the declaring identifier, plus offset information for
struct fields.

Some tests needed tweaks to make them CPU-independent,
or to disable them on 32-bit machines.

Also, add the first release notes using the new
git+gerrit workflow (and backfill a missing item for
"View package documentation").

Change-Id: Ibe8ac5937912c3802f3ad79e3d9f92ba24eb51de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/573076
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-03-29 16:14:30 +00:00
Alan Donovan 509ed1c81d gopls/internal/golang: work around bug in go/doc
The associated bug was a crash in package doc rendering due to
invalid ASTs resulting from mutation caused by doc.New, even
in PreserveAST mode. (This bug has been latent since 2018.)
The mutation occurs when filtering out unexported symbols.

This change is a workaround: we enable AllDecls mode to
suppress filtering, and perform the filtering ourselves.

Also, add a regression test for the panic, and check
the new filtering behavior. This required some test
refactoring.

Fixes golang/go#66449
Updates golang/go#66453

Change-Id: I434c97e08930728d4894b90c1c7e010e7a922209
Reviewed-on: https://go-review.googlesource.com/c/tools/+/573575
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2024-03-29 15:08:21 +00:00
Zvonimir Pavlinovic 9551398269 go/callgraph: keep instantiations in DeleteSyntheticNodes
DeleteSyntheticNodes currently removes instantiations of generics from
the call graph. This function is intended to remove synthetic functions
that don't have a counterpart in the source code. Instantiations of
generics do not fit that bill. This also caused problems in govulncheck
where a function call to instantiation was missing from a call stack.

The fix is to keep instantiations and improved the documentation of
DeleteSyntheticNodes.

Change-Id: I32392b7495a8c1a5f6b26f795d46c8f184983e67
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575095
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
Auto-Submit: Zvonimir Pavlinovic <zpavlinovic@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-28 22:49:04 +00:00
Alan Donovan 11b4b5e922 go/analysis/passes/nilness: add longer example to doc
Fixes Google Issue 331478795

Change-Id: I0258bdd6a50000effc66c4e1fe03f99e2720c0cc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/575056
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-28 20:16:23 +00:00
Peter Weinberger 9ed98faaba gopls/internal/test: option to suppress LSP logs on failure
Adds a RunOption NoLogsOnFailure() to suppress the printing of
the voluminous LSP logs when there is a test failure. While debugging
tests these logs can be a noisy distraction.

Change-Id: I41379fdcef8ba00f8b8a49ec89d8795274797888
Reviewed-on: https://go-review.googlesource.com/c/tools/+/574035
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-03-26 17:46:31 +00:00
Lasse Folger 867c912ea6 inline: make it possible to gob encode/decode inlineMeFacts
Before this change gob encoding of these facts was failing with:

  `gob: type analyzer.inlineMeFact has no exported fields`

gob encoding is required for all facts as analyzer drivers use it to
share facts between the analysis of different packages as stated in
the docs:

  A Fact type must be a pointer. Facts are encoded and decoded using
  encoding/gob. A Fact may implement the GobEncoder/GobDecoder
  interfaces to customize its encoding. Fact encoding should not fail.

Change-Id: Ifb0eb57b0f582ec228a21a0d17e3bbd33c560d3d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/574435
Auto-Submit: Lasse Folger <lassefolger@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-03-26 14:22:20 +00:00
Alan Donovan db5d12bad8 go/types/internal/play: display method receiver type
Change-Id: Ib42e91d90ecd6e3bda69dbfa6ae2489fd2a0185c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572476
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
2024-03-25 21:49:14 +00:00
Alan Donovan 2c8dd3ec05 gopls: add explicit Unalias operations
This CL does for the gopls module what CL 565035 did
for the x/tools module.

In particular, we don't yet address desired behavior
changes for materialized aliases, nor generic aliases.

Change-Id: Iace78c1f8466afe8a6a24e3da3d6f431bf5ebc3e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/565756
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
2024-03-25 21:28:01 +00:00
Alan Donovan 814f676cf4 internal/gcimporter: add tool to inspect export data
This CL adds an unexported command for inspecting "unified" export
data produced by the compiler, and checking that it can be
roundtripped through "indexed" format as used by gopls.

Change-Id: Idc8eea5c8d7287d7f10af7bd15c7a52e6987a4bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572795
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-25 20:14:41 +00:00
Alan Donovan 4fe2c29e13 refactor/rename: fix renaming of aliases
This change gets the renaming of aliases right when
they are materialized by GODEBUG=gotypesaliases=1.
(Obviously there's no way to get it right without
that feature.) And it adds a (conditional) test.

Updates golang/go#65294

Change-Id: Ie242e3a0a9d012218067bdc61a901f6618fecbb5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/567842
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-25 20:14:39 +00:00
Alan Donovan 71acab9a7f internal/typesparams: add Deref
This change defines Deref(T), which returns the type of
the variable pointed to by T if its core type is a pointer,
or T otherwise, and removes all the various other flavors
of 'deref' helper that exist across the repo.

Also fix and test a generics bug in fillstruct.

Updates golang/go#65294

Change-Id: I14f6f35b58eefbad316391745745d662b061c013
Reviewed-on: https://go-review.googlesource.com/c/tools/+/565456
Reviewed-by: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-03-25 20:14:32 +00:00
Alan Donovan 63b3b5af27 internal/imports: fix two "nil pointer in interface" bugs
CL 559635 changed newModuleResolver so that it can return
(nil, err). That means it is no longer safe to unconditionally
convert the first result to a Resolver interface, but we
forgot to check in two places, causing a crash that was
reported by telemetry.

This change adds the two checks.

Fixes golang/go#66490

Change-Id: I3f2b84ed792b1eea179fc0d4d5ee9843281506fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/574136
Reviewed-by: Peter Weinberger <pjw@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-25 17:46:54 +00:00
Tim King 3f9badb7e4 go/ssa: types.Unalias() cleanup.
Removes a few instances of unneeded Unalias calls, and
adds additional documentation about aliases.

Change-Id: I02045ef74d6d9b80189caf6a9831bded2bae5ad4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/568176
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-03-21 20:17:18 +00:00
Alan Donovan e5cf370df9 internal/typeparams: factor 2 copies of isParameterized
The typeparams.Free.Has(T) method reports whether type T
has free type parameters. It factors two copies of this
algorithm, themselves copied from go/types.

Change-Id: I285e26ba82b28ca0a3ddbd956fa75e342a0dc22d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/573135
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
2024-03-21 18:24:44 +00:00
vitalmotif e0a95673cd all: fix some comments
Change-Id: Id4d3bcdcb663dccaf149ccadae1d0513c868a049
GitHub-Last-Rev: 4534649b01
GitHub-Pull-Request: golang/tools#486
Reviewed-on: https://go-review.googlesource.com/c/tools/+/573015
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tim King <taking@google.com>
2024-03-20 18:23:00 +00:00
Tim King c3544e2e53 go/analysis/passes/httpresponse: fix ReceiverNamed usage
Fixes a bug where ReceiverNamed returns a nil *types.Named if the type is
not a Named type.

Updates related documentation in httpmux.

Fixes golang/go#66259

Change-Id: I512feeb11473f2278edf4d9ef3312319d9dd1edf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/571057
Run-TryBot: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-20 16:54:27 +00:00
Hana (Hyang-Ah) Kim d0f7dcef44 gopls: update x/vuln to 1.0.4
x/vuln/cmd/govulncheck -json output format has changed to include
module level vulnerabilities. We knew this change would eventually
come and had handling in gopls/internal/mod/diagnostics.go
'foundVuln'. But we didn't update TestRunVulncheckWarning &
TestRunVulncheckInfo to get prepared. This is a test-only bug.

Fixes golang/go#65942

Change-Id: Ib7545279d07caf708c4f5392b51df273256432e6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/567155
Reviewed-by: Suzy Mueller <suzmue@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-19 20:46:25 +00:00
Alan Donovan dd5264629a go/ssa: create fewer goroutines
This CL limits the number of goroutines created by Program.Build
to the number of P's, since building is entirely CPU bound.
Creating more than this number of goroutines just increases
churn, and potentially increases cache and allocator contention,
and increases peak memory usage and GC.

The effect on TestStdlib's "build SSA" timing metric seems
to be a reduction of around 2-3%, but it's fairly noisy.

Change-Id: Ie85e93b99c27ece245be05892818d52ae3b7fbc1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572796
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
2024-03-19 19:46:15 +00:00
Peter Weinberger 813e70a9e4 gopls/internal/server: redo completion counters
Rearrange the counters so that there is one set describing the
set of suggested completions (empty, short, long) and one set
describing what the user does (used, not used, can't tell).

A set of suggested completions is long if there are more than ten
of them, which is about how many clients show to users.

If a client sends back changes to file, gopls can decide if a
completion was used or not, but it does not try to tell if the client
sends back a new whole file.

These sets of counters correspond to two partitions.

Change-Id: I861a5743b16e488074fd2e58cb63c6a8aea52735
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572315
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-19 18:53:44 +00:00
Dmitri Shuralyov 2ba7cf9616 internal/imports: remove obsolete go:generate directive
CL 567837 deleted mkstdlib.go (a generator) and zstdlib.go (its output).

For golang/go#46136.
For golang/go#38706.

Change-Id: If5623e3ab014c2fee63b1d058c726ea5acb06aa2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/571276
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-03-19 16:30:57 +00:00
Zxilly 0fb9b7b709 gopls: use slices package for reverse slice
slices has been supported in go1.21 and go1.22

Fixes golang/go#66222

Change-Id: I7b319e649632a713200dcaabd1e68d1f01e1b2f2
GitHub-Last-Rev: fc1d59d86a
GitHub-Pull-Request: golang/tools#484
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572116
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-03-19 15:15:34 +00:00
Robert Findley c21ae4cabc gopls/internal/golang: don't suggest removeparam when there are errors
Update the canRemoveParameter logic to reflect that we don't try to
remove parameters when there are parse or type errors.

Change-Id: Ia8239a383b56763d100c69c9a3633c87025b81cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572297
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-03-18 20:56:23 +00:00
Robert Findley f3fcceee06 gopls/internal/golang: support removing unused parameters from methods
Make a minimal change to the removeparam algorithm to support removing
unused parameters of methods.

This doesn't address the problem of expanding the set of signatures or
calls based on interface satisfaction constraints: that is really a
separate concern, which also affects method renaming (golang/go#58461).
Were we to have a more general solution to that problem, it would be
relatively straightforward to also expand the change signature
algorithm.

For golang/go#38028

Change-Id: I296cb1f828f07d841c83b1fd33593ccd2fee3539
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572296
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-18 20:56:16 +00:00
Robert Findley 2d517d51b8 gopls/internal/golang: fix build breakage due to semantic conflict
Unbreak the x/tools build dashboard due to a semantic conflict between
CL 572475 and CL 571215.

Change-Id: I8ce1308ee99e75aa7cf8f7bd1d8b1dedcb845f4d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572515
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-18 20:31:43 +00:00
Alan Donovan 6af02955c9 go/analysis/passes/stdversion: publish
This CL moves the stdversion analyzer out of gopls,
into the exported analyzer tree, whence it will be
vendored into cmd/vet in a follow-up.

Updates golang/go#46136

Change-Id: I039ef78ecdcfd6bc64d5b089017a9b8635cf9aa5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572035
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-18 20:14:13 +00:00
Alan Donovan 8669bfccbe gopls/internal/server: add "View package documentation" code action
This CL adds a "View package documentation" code action to any
selection in a Go source file. Its command has two effects:

1) to start a web server associated with the current LSP
   server, with coupled lifetimes, and register a handler
   to serve the package documentation; and

2) to direct the client to open a browser page
   showing the package documentation for the selection.

The server is a minimal imitation of pkg.go.dev,
working off the cache.Package representation. This means
we can display doc markup even for unsaved editor buffers,
and show type-derived information such as method sets
of each type.

Clicking through to the source--which on pkg.go.dev goes
to cs.opensource.google--causes the client editor to
navigate directly to the source file, using the magic
of showDocument requests.

The web server is secure in that all its endpoint URLs contain
an unguessable secret, so a local process belonging to
a different user can't access source code by port scanning.

The CL includes a test that
(a) the webserver content reflects edits (even unsaved)
    in the source buffers, and
(b) that "clicking" through the source link causes
    the server to navigate the client editor to the
    correct source location.

A couple of tests that asserted "no code actions" needed
to be tweaked, as now there is always at least one
code action in any Go source file.

Change-Id: I2fe1f97e4e2b0b15cff6a4feb66501fce349b97d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/571215
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-03-18 19:36:00 +00:00
Dmitri Shuralyov 56284432e0 gopls/internal/test/marker: remove runtime.GOROOT from format.txt case
The runtime.GOROOT function is about to be marked as deprecated, which
will generate a diagnostic that isn't expected in format.txt test case.
Pick another hopefully somewhat future-proof identifier, since dealing
with this doesn't seem to be in scope of this test case.

For golang/go#51473.

Change-Id: I54d7ed0b43860bcd41938328211797a0cdd60e36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/564275
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-03-18 19:15:13 +00:00
Robert Findley 6d9ecf2227 gopls/internal/cache: rename methods on Package
Rename methods on cache.Package to eliminate unnecessary "Get" prefixes.
Also rename pkg.go to package.go.

Change-Id: I42f2fa7a18a5973a53af93c63b48c7db19cba3b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572475
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-03-18 17:50:33 +00:00
Alan Donovan 29d17a052c go/cfg: publish (*CFG).Dot method
The new method formats the graph in the syntax used by
the 'dot' command from https://graphviz.org/.

Fixes golang/go#65754

Change-Id: Icf696419070e19b2f2236ac1e4aaa09323c565de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572016
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
2024-03-16 22:28:19 +00:00