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

8805 Коммитов

Автор SHA1 Сообщение Дата
Rob Findley b5bfa9cc3f gopls/internal/fuzzy: move the fuzzy package to gopls
While reviewing CL 592519, I had to pause to confirm that the fuzzy
matcher is only used by gopls, and so we are therefore free to change
its matching heuristics.

Move the library to the gopls module to make this relationship more
apparent.

Change-Id: I2d097fe68cfb6c83d82a09c63eddd8b7462f6ec7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/595115
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-06-26 14:45:46 +00:00
Rob Findley 02912f74a5 gopls/internal/cache: lift package caching to forEachPackage
For some reason this solution didn't occur to me in CL 512636. By
lifting this handling out of forEachPackageInternal, we simplify the
logic of type checking.

Change-Id: Ie8738d04aa5e1e4811f978f2ebe2d1cfc3b839b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591918
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-06-26 14:39:32 +00:00
Muir Manders e7f294d257 gopls/matcher: don't give bonus to case insensitive match
Previously the user given pattern "A" would match "Ant" and "ant"
equally well. Now it will match "Ant" better than "ant".

There already was a case sensitive match bonus, but it was combined
with a "head" character bonus, so "Ant" got the case sensitive bonus,
and "ant" got the head match bonus (and they tied).

Tweak the head match bonus to not apply if the pattern is case
sensitive. In other words, if the user is explicitly putting capital
letters in the pattern, don't give a bonus if the pattern char's case
differs from that of the candidate char.

For example, if the pattern is "Foo", the "F" no longer gets a bonus
for matching the "f" in "fooBar".

I tweaked the test to test strict relative ranking. Previously it
allowed adjacent test inputs to have the same score, but I wanted to
test that "N" matches "Name" strictly better than "name".

Fixes golang/go#64224

Change-Id: Ibce21985d5c904167cec239d62a4f53e814a9b08
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592519
Reviewed-by: 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-06-26 14:21:10 +00:00
Muir Manders 480a22df04 gopls/completion: don't take address of interfaces for "%p" values
When completing printf calls, we previously only preferred
pointers and slices. This meant to make an interface object acceptable
for "%p", we would take its address to turn it into a pointer.

Change "%p" to also prefer interface types in addition to chan, map, and
func, which all have pointer semantics. Note that interface types
don't necessarily contain pointers, but they might, so tacking on "&"
automatically is annoying.

Fixes golang/go#65609

Change-Id: Idf2ba9cf27fa4ea8e721396cded5a7743d79807b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593575
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-06-26 14:07:16 +00:00
Chiawen Chen 315127076e gopls/internal: add code action "extract declarations to new file"
This code action moves selected code sections to a newly created file within the same package. The created filename is chosen as the first {function, type, const, var} name encountered. In addition, import declarations are added or removed as needed.

Fixes golang/go#65707

Change-Id: I3fd45afd3569e4e0cee17798a48bde6916eb57b8
GitHub-Last-Rev: e551a8a24f
GitHub-Pull-Request: golang/tools#479
Reviewed-on: https://go-review.googlesource.com/c/tools/+/565895
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-06-26 14:07:01 +00:00
Rob Findley 850c7c3070 gopls: skip failing tests on wasm/wasip1
Add skips as appropriate to TestFreeRefs and TestDriverConformance.

Also add a skip for a preexisting failure on wasip1: golang/go#64725.

Fixes golang/go#68163
Updates golang/go#64725

Change-Id: I2827160bad6627755f213e4b8b54d53333d2d98d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/594895
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-06-25 18:01:28 +00:00
Rob Findley dc341221fd gopls/internal/golang: fix hovering from the builtin file
The builtin file represents a psuedo package for builtin documentation.
When hovering over a builtin declared in the builtin file, its
corresponding hover content should be the same as hovering at the call
site.

Fix this by intercepting hover requests originating from the builtin
file. Along the way, fix a bug that jumping to a definition in the
builtin file went to the declaring node, not declaring identifier.

For golang/go#68026

Change-Id: I070ec701cb7e067dd1cbb14a968c063169bb541c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/594795
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-06-25 17:24:37 +00:00
Alan Donovan 1028e3027a gopls/internal/settings: remove fieldalignment analyzer
Since it doesn't find likely mistakes, it is a poor fit for the
gopls analyzer suite: even when off-by-default, its diagnostics
can be confusing.

Instead, its docs now advise users who come across it to run
it using a standalone singlechecker as desired.

+ release note

Also, we issue a deprecated warning if the user's configuration
enables the deleted analyzer, with a reference to the 0.17
release so that users can find the release note.

Fixes golang/go#67762

Change-Id: I7e2eafc3216df84eb62de132ac2f04e0bf444f92
Reviewed-on: https://go-review.googlesource.com/c/tools/+/590375
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-06-25 17:18:35 +00:00
Lasse Folger 5fefc65607 go/analysis/passes/stringintconv: do not generate empty edits
In case the import already exists the edit was be empty.

Fixes #68173

Change-Id: If0697775023ce76bc70db66a8ee9268c2b5cdd09
Reviewed-on: https://go-review.googlesource.com/c/tools/+/594258
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-25 14:23:44 +00:00
Alan Donovan 1e6c1e2be2 gopls/internal/golang: strip @v1.2.3 suffix from pkgdoc URLs
The  package path in a /pkg URL does not want a module
version suffix: the view specifies the versions of all packages.
Remove them.

Fixes golang/go#68116

Change-Id: Icbe7a6e7346d12456724d005fe8f755872657055
Reviewed-on: https://go-review.googlesource.com/c/tools/+/594556
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-06-24 19:46:22 +00:00
Alan Donovan 7de8d0a169 gopls/internal/analysis/simplifyrange: reenable on range-over-func
This reverts the functional change of commit 3629652 (CL 588056) that caused
range-over-func to differ from other range operands; but we keep some tests
and tidy up the logic.

It was decided at the 11th hour to permit redundant blanks in range-over-func
statements in the go1.23 spec; see
https://github.com/golang/go/issues/65236#issuecomment-2187122281.

Fixes golang/go#67239
Updates golang/go#65236

Change-Id: Ib3c1c535a1107a05f18732e07d7c8844bbac4d1e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/594555
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-24 19:31:57 +00:00
Alan Donovan c9675c27f7 internal/refactor/inline: avoid unnecessary import renames
When an inline eliminates the last use of an import,
that name is available for re-use. Don't choose a worse
name when adding imports for the callee.

Fixes golang/go#67281

Change-Id: Idb731e0d3073292c639697819236448f99b7602a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592575
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-24 18:53:09 +00:00
Alan Donovan f06ed92a26 gopls/internal/settings: define InlayHints enum
This allows us to simplify both the declaration of the enum
(particularly its doc comments) and the generator logic,
which no longer treats it as a special case.

Now that "analyses" is the only remaining special case
of map[string]bool, consolidate the two generator
hacks for it.

Change-Id: I49d4e3ca41e96d02d8444925cc013e2b19cf2305
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593616
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-24 14:56:03 +00:00
Alan Donovan 833def65e8 gopls/internal/settings: move CodeActionKind values from protocol
Like CodeLensSource, these enum values are gopls extensions (and
their configuration interface) and not part of LSP.

No change to generated files.

Change-Id: I2413fd23acc92450f1f0712f0f77a1c83674505a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593816
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-24 14:55:40 +00:00
Ethan Reesor 47bd819ea9 gopls/internal/server: fix CSS typo
Change-Id: I391dbba608b24220f4af37f620e5f33acbad1578
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593637
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
2024-06-24 03:50:26 +00:00
Alan Donovan df4e86209a gopls/internal/settings: minor cleanups
This change causes the "env" setting to require
that its JSON value is a mapping from strings to
strings, or int for legacy compatibility; but other
values (float, array, object, null, bool) are now
rejected.

Also, group all the deprecated settings together with
a comment to resist the temptation to delete them.

Change-Id: I7eb2f017e9cda4a3821370034b8e95809a3d8e11
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593075
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-06-21 20:57:32 +00:00
Vladislav Valkov 4a264773f4 internal/refactor/inline: allow duplicable type conversions
The current implementation does not consider type conversions to be
duplicable operations; this change resolves it by handling *ast.CallExpr.
All type conversions except []byte(string) and []rune(string) are now
considered to be duplicable.

The change also removes redundant type conversions when typed constants
are passed to inlined functions.

Fixes golang/go#67589

Change-Id: I524dbff1ae09466f56459e0bf3b6425be38d157c
GitHub-Last-Rev: 580a00aa8b
GitHub-Pull-Request: golang/tools#494
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588175
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-06-21 19:35:29 +00:00
Tim King db513b0915 go/ssa: wait for shared functions to finish building
Package.Build and Program.MethodValue can create and build
Functions that may be depended on by other calls to
Package.Build and Program.MethodValue. Both of these
APIs now wait for any Functions that are shared and depended
on to finish building before returning.

This fixes some data races observed when accessing the Blocks
field of shared functions.

Functions that are members of Packages (fn.Pkg != nil)
are still always built by fn.Pkg.Build().

These dependencies can be create cycles between public API
calls that both depend on Functions the other is building.
For example, both the "net/http" and "internal/trace/testtrace"
packages both depend on slices.Contains[[]string,string] and
slices.Index[[]string, string]. Under some schedules, building
both packages may need to wait for the other package to finish
building before finishing.

This introduces a new internal type task. tasks
allows for waiting on the transitive closure of builders iterating
to be marked as done before proceedind.

Also:
- Add a test that reliably reproduces the data race.
- Refactors creator.add calls to happen after the function is created.
- Merges creator into builder.
- Updates the builder to mark when it is done building and wait
  for dependencies.
- Define type unit = struct{} and clean up.

Fixes golang/go#67079

Change-Id: I34d2b8730b19609f5fbf6b55b3db33f59818a17b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591775
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-06-21 16:59:57 +00:00
Guoqi Chen 8a45e6cdbd go/analysis/passes/asmdecl: define register-ABI result registers for loong64
Fixes golang/go#68041

Change-Id: I04f4f0305e2b15a6fb89809a60a6d62c7176b2a9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593275
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-06-21 16:27:00 +00:00
Alan Donovan dfdfa49fac go/types/objectpath: support Signature.RecvTypeParams
Fixes golang/go#68055

Change-Id: I57c7641ab40521919053c1cb6492152e08b341c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593316
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-06-20 20:57:46 +00:00
Alan Donovan 2d104ec5d2 gopls/doc/generate: treat LinksInHover as an enum
This CL defines a type for the true|false|"gopls" type used
by linksInHover, and adds a special case to the doc+api generator
to treat it as an enum, so that VS Code will present a better
value-chooser UI for it.

Also, document the type grammar used in the docs.

Updates golang/go#68057

Change-Id: I9e334fbc94dcbdc70657d8e64f67fb807e69cbf8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593656
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2024-06-20 18:03:41 +00:00
Alan Donovan b994346592 gopls/doc/assets: create dummy submodule for image files
Contra the previous CL, we decided to store the PNG images
in git, but in a separate submodule so that we don't bloat
the gopls module download.

(These images will also be shared with forthcoming gopls
docs in CL 583316.)

Change-Id: I5bab6114ce10304725ba2ac58a8654c247171801
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593675
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-20 15:34:10 +00:00
Alan Donovan 18e694b54c gopls/doc/release: finalize v0.16.0 release notes
The images are intentionally missing; we don't want to
bloat the repo with PNG files, so I plan to set up
a process for storing images in a blob store later
today, at which point I will update the URLs to point
there. But we can proceed with the release before that.

(Many of these images will be shared with the gopls durable
documentation slowly coming together in CL 583316.)

Change-Id: I508b13ad2ae3b77f08dfeb895472db09542661b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593476
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-06-20 14:44:49 +00:00
Alan Donovan 99779e9a0c gopls/internal/settings: move CodeLensSource from protocol
This enum is properly a setting, not a protocol feature.

The .md and api.json generator script assumes that all enums
are in the settings package, and consequently emitted incorrect
names for this type.

Generator changes in detail:
- remove the package.Load of both "settings" and "protocol",
  reverting part of an early change.
- remove loadAPI special case for "codelenses" not being an
  enum-keyed map, as it is one. (As a consequence, the enum
  values appear in api.json in alphabetical, not declaration,
  order. Also, the title portion of the codelend doc string
  is no longer discarded.)
- add lots of missing commentary.

This may seem like a large change at the 11th hour, but note:
- the only change to the production code is a renaming;
- the effects of the generator changes are entirely confined
  to settings.md and api.json.

Fixes golang/go#68057

Change-Id: I097f0a9b2e34b8f9a3438112b55efb2081b4acb2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593615
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-20 14:20:31 +00:00
Alan Donovan 9bf0e215d0 gopls/internal/test/integration/misc: skip asm test unless a{rm,md}64
Fixes golang/go#68058

Change-Id: I8d2467474f39f1834137f5b4718cdbbca4ac0e81
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593416
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-20 12:54:18 +00:00
Dmitri Shuralyov f2d2ebe43e go/analysis/passes/buildtag: retire Go 1.15 support
Go 1.17 is long since out.

Furthermore, CL 516575 added a use of parser.SkipObjectResolution to
a file with a go1.16 build constraint. This used to be fine, but not
now that vet checks for this (see go.dev/issue/66092) since that API
is new to Go 1.17.

For golang/go#66092.

Change-Id: I749b2aa52e02308415c27028be15a436ee11d95c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593297
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-18 18:17:13 +00:00
Alan Donovan 1239d0475f gopls/internal/golang: Hover: use internal pkg doc viewer
This change changes the linksInHover option from bool to
a sum of false | true | "gopls".
The "gopls" setting causes Hover(SynopsisDocumentation)
to generate links to gopls' internal web-based doc viewer.

Thanks to Hana for the idea.

+ Test, release note

Fixes golang/go#67949

Change-Id: I384796780436b191a0711c60085d67363d00e5f6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/572037
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-06-18 16:54:22 +00:00
Alan Donovan 6ece8fbc64 gopls/internal/golang: improve ergonomics of "Browse documentation"
This change causes the 'Browse documentation...' code action
to offer different pages based on the current selection:
- in an ImportSpec, or a use of the PkgName,
  we display the imported package;
- in a reference to an imported symbol, we display that
  symbol (except for fields, or methods of nonexported types).

The logic that computed the fragment, now extracted to
golang.DocFragment, now also computes an appropriate title.
The various cases of this function are exercised by
a new integration test.

Also, rename s/Render/PkgDoc/ in the integration tests.

Updates golang/go#67949

Change-Id: I7f4b014beca8cfde9ca3540dd10b32e1eb8f95e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592577
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-06-18 16:21:21 +00:00
Alan Donovan 693d7febfe gopls/internal/settings: simplify SetOptions
This change simplifies the SetOptions machinery by
eliminating the (public) OptionsResult and Options
types and their methods, and using simpler standalone
functions of these forms:

   setT(dest *T, value any) error
   asT(value any) (T, error)

The code is clearer and significantly shorter.

Details:
- rename SetOptions to Options.Set.
- return only the errors, not the OptionsResults;
  server.handleOptionResult renamed handleOptionErrors.
- remove error result from server.handleOptionResult,
  per preexisting TODO.
- add missing doc comments.
- use JSON terminology in error messages.

Note, minor behavior changes:
- the buildFlags and directoryFilters flags now use
  asStringSlice (per the preexisting TODO), and also
  templateExtensions, but this replaces Sprint(x)
  with asString(x), which is strictly speaking an
  incompatible change.

Change-Id: Ib2169ba8e1db1a34e9bc269e6e8cef3a6763e6e6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592536
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-17 16:26:12 +00:00
Alan Donovan 977f6f7150 go/packages: move getSizesForArgs back
..and delete go/internal/packagesdriver.

Change-Id: I2283087ae08f9e39e45aae1d51e62919c3163ce8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592736
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2024-06-14 23:00:15 +00:00
Alan Donovan 6a8bc5fe21 gopls/internal/lsp/source: ignore lambdas in call hierarchy
Previously, anonymous functions were treated as nodes
in the call hierarchy view, but it doesn't make sense to
do so because we have no reliable way to find references
to them, except from within their enclosing function.

So, this change treats anonymous functions and their
enclosing functions as a single item.

Fixes golang/go#64451

Change-Id: I3841adcbad4b13ab190fad58daf38c1bbc6f8baa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/546736
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-06-14 16:28:01 +00:00
Alan Donovan b5dbe8b770 gopls/internal/golang: s/View/Browse/ for browser-based features
We decided "browse" is better than "view" (or last week's "show")
for the UI description, since it connotes "web browser".

Thanks to Dominik Honnef for the idea.

Updates golang/go#67949

Change-Id: If32be800e5c2a0fc50028aad88a00467abe10421
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592496
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-06-13 20:38:10 +00:00
Rob Findley 2ca6abea0c gopls: expand on documentation about version support changes
Users unfamiliar with the subtleties of version support are rightly
confused by our current documentation. Try to clarify, by defining terms
more precisely and being sure to emphasize that language version support
is unchanged.

Also, add a section for the new stdversions analyzer, which is not
present in gopls@v0.15.x.

For golang/go#67936

Change-Id: Ia9f241da4a67dc0ca82532ae945751ad3c6b6f1f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592576
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-13 20:29:11 +00:00
Alan Donovan b59dd37647 go/analysis: document interpretation of multiple diagnostics
RunWithSuggestedFixes was written without a clear understanding
of what the semantics of multiple fixes should be. We believe
the only sensible interpretation is the one described here:
https://github.com/golang/go/issues/67049#issuecomment-2163687538

This change documents the interpretation at Diagnostics.SuggestedFixes,
and adds a TODO at RunWithSuggestedFixes to note that its
conflict resolution is problematic, plus a suggested workaround.

A later change will fix RunWithSuggestedFixes, or provide a
replacement if that should prove infeasible.

Updates golang/go#67049

Change-Id: I59d93d77f05e13e2458daa2d9897057ed9f82d06
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592495
Reviewed-by: Robert Findley <rfindley@google.com>
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-06-13 17:34:07 +00:00
Alan Donovan 4419f4f3fe go/analysis/passes/stringintconv: offer fix of fmt.Sprint(x)
Previously, the offered fix was string(x) -> string(rune(x)),
which is not the most commonly desired change. Now, the analyzer
offers both fixes, with informative descriptions.

The Sprint fix must take care to preserve the type when it's
not exactly string. Also, it may require adding an import
of "fmt", using the new AddImport refactoring helper.

The "did you mean?" hint in the diagnostic (added by CL 235797
for golang/go#39151) has been removed, since the descriptions
of the offered fixes capture the same information, and there
was a recent editorial decision made against such hints.

Also:
- split the tests into tests of diagnostics and tests of fixes,
  since the latter now need to use the clumsy golden-file-is-a-txtar
  mechanism. Reduce the regexp patterns to just the minimum.
- clarify RunWithSuggestedFixes' explanation of txtar mechanism.
- clarify SuggestedFix.Message and provide an example of the
  proper form.

Googlers: see b/346560254

Change-Id: I493cf675a4c71d4ee40632fc9ad47a8071eafa76
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592155
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Tim King <taking@google.com>
2024-06-13 17:34:00 +00:00
Alan Donovan a69d9a2ccd internal/analysisinternal: AddImport helper for inserting imports
This CL defines a new helper for inserting import declarations,
as needed, when a refactoring introduces a reference to an
imported symbol.

Also, a test.

Change-Id: Icba17e6f76e67d2dad8f68b312db7111f4df817a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592277
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>
2024-06-13 17:33:53 +00:00
Alan Donovan db99e8acdb gopls/internal/test/integration/misc: skip ASM assertions on risc64
It appears to be alone in using JAL instead of the CALL instruction.

Fixes golang/go#67960

Change-Id: Ic7002caf418d0ffcf8592f1e255e6c8ea260909b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592476
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-06-13 17:21:29 +00:00
Rob Findley a852b253a3 gopls/doc/release: update gopls release notes for language support
Update the v0.16.0 release notes to reflect 1.23 support and changes to
our support policy.

For golang/go#67936

Change-Id: I330b8a3897fc3b4b944eb695143042654556dbf1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592156
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-06-13 16:18:46 +00:00
Michael Stapelberg 03d712539b gopls/doc/emacs.md: use more precise before-save terminology
Change-Id: I7ce5818c2067ae687ce3258189701396a2eea8cb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/592335
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-13 14:36:11 +00:00
Zvonimir Pavlinovic e4b0a184d0 internal/checker: run despite all errors
Previously, we would run an analysis when RunDespiteErrors=true only
if all package errors were syntax or type errors. We should run the
analysis on all errors.

The previous design choice was motivated by a concern that list and
unknown errors might indicate something unexpectedly wrong about the
program. If RunDespiteErrors=true, then this would go under the users'
radar.

This design choice seems somewhat arbitrary and creates problems when a
list error is a duplicate of a type error; the analysis is not
executed despite a conceptually single type error. Further, package
errors are always printed to stderr, so they are visible to users.

Lastly, we return exit code 3 if there are any diagnostics. Otherwise,
we return 1 exit code, if there are any packages errors.

Fixes golang/go#67790

Change-Id: Ie3186a08ed3c8292033344aec35fc755a6d256f2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591117
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-06-12 09:20:43 +00:00
Rob Findley f45db9b4bb internal/protocol/command: regenerate commands to fix build
Change-Id: I4744170cc4dcbd4265361dbe3934f6f2080f6d94
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591917
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-06-11 19:05:41 +00:00
Rob Findley 568dea1d0b gopls: update x/telemetry dependency
Change-Id: I0ab009bd9142a2be987f042632bf57713d8b31f8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591416
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-11 19:02:34 +00:00
Rob Findley 82912d2dec internal/imports: fix starvation in external candidate search
CL 589975 triggered a latent starvation bug when the findImports
operation of internal/imports was cancelled. This CL first reproduces
the starvation conditions by refactoring to isolate the algorithm in a
unit test. Then the missing select statement is added to fix the bug.

addExternalCandidates is also simplified somewhat using x/sync/errgroup.

Many thanks to hyangah@gmail.com for finding the root cause of this
starvation.

Fixes golang/go#67923

Change-Id: Ib0a12a9a667af84150d84c3e988e460c9ae1d973
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591756
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-11 18:12:39 +00:00
Rob Findley 3e9483071c internal/imports: optimize package path filtering
As reported in golang/go#67889, a short unresolved identifier can cause
goimports fixes to be quite slow, because the substring match heuristic
used to filter import paths matches a large fraction of the module
cache.

Fix this by improving the precision of the matching heuristic used to
filter potential packages. We now match only full segments of the import
path (ignoring '.' and '-'), or subsegments delimited by '.' and '-'.

Add a gopls benchmark that reproduces this initial slowness, along with
a command to force a scan of the module cache. On my (overpowered) linux
development machine, with a 5GB module cache, this change reduces the
benchmark time ~90%, from 2s to 200ms. With a smaller machine, slower
operating system, or larger module cache, I imagine the starting
point could be significantly more than 2s.

Fixes golang/go#67889

Change-Id: Id8f7ea20040b059b42366333adeb4add684dee61
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591715
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-06-11 18:12:06 +00:00
Tim King dddd55df49 go/ssa: fixing Named type substitution
Reorganizes how type substitution is done for Named types.
This fixes several issues with Named types support for
parameterized types defined within parameterized functions.

Additionally supports recursive substitution of a type parameter
that is not a type parameter being substituted.

Fixes golang/go#66783

Change-Id: I31478e622e854d58620687c1964cf8b254bf419f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/581835
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-11 17:43:16 +00:00
ssd71 46928a5cfe gopls: fix StmtToInsertVarBefore for switch stmts
The function StmtToInsertVarBefore on getting a
variable declaration in switch stmt was returning
the variable declaration statement instead of the
switch statment.

Fixes golang/go#67905

Change-Id: Ied1f82061ae4d5bbe6b65e6897e8db44ef43d8c6
GitHub-Last-Rev: 11b8c6d043
GitHub-Pull-Request: golang/tools#498
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591496
Reviewed-by: Alan Donovan <adonovan@google.com>
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-06-11 16:30:37 +00:00
Alan Donovan 318adf2922 gopls/internal/protocol/command/gen: omit unnecessary MarshalArgs calls
...like we do for Unmarshal.

Change-Id: I2c7ee1f817002c747c429c3fbfb79df3a5cd1a4d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591955
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-11 16:19:59 +00:00
Alan Donovan bffeaaa266 gopls/internal/golang: s/Show/View/ for web-based reports
All three should be consistent, and "View" connotes a separate
surface more than "Show", which connotes adding annotations to
the current editor view.

Also, rephrase assembly template to encourage upvoting of
the relevant VS Code issue.

Change-Id: I99b07ba347e2023bd672e2b34b13faeece4108db
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591915
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-06-11 15:25:22 +00:00
Tim King a9021a544f go/ssa: export Defer.DeferStack field
Fixes golang/go#66601

Change-Id: I371541d470eb0d40abe9cf73f93d7718c700774d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/590975
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-10 22:20:57 +00:00
Alan Donovan ae524770c6 cmd/deadcode: fix nil panic in Edge.Site.Pos
Thanks to @ct16k for reporting the crash and suggesting the fix.

Also, a test.

Fixes golang/go#67915

Change-Id: I72472603e52831d5e571cb8a4e053fd15ff49b72
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591615
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-06-10 16:24:39 +00:00