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

7283 Коммитов

Автор SHA1 Сообщение Дата
Gopher Robot d0863f03da go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.
Once this CL is submitted, and post-submit testing succeeds on all
first-class ports across all supported Go versions, this repository
will be tagged with its next minor version.

Change-Id: I4837788c74cc58a98186c4517be6231efec17a8c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/466735
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-08 22:43:44 +00:00
Robert Findley 545ca87cb5 gopls/internal/regtest/marker: require go/packages
Add a missing testenv condition to the marker test runner.

Fixes golang/go#58396

Change-Id: I69a7fe6dfab011ba789a066e2c7677c0315eed00
Reviewed-on: https://go-review.googlesource.com/c/tools/+/466715
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-02-08 22:24:52 +00:00
Suzy Mueller 1ace7dbcb0 go,gopls: remove license from package doc comments
Inspired by http://go.dev/cl/465995, add a blank line between
license and package statement to avoid the license appearing
in the package doc comment.

Change-Id: I867e0729ca1fdc1bcee34964954549e5c92f2b31
Reviewed-on: https://go-review.googlesource.com/c/tools/+/466215
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
2023-02-07 23:22:09 +00:00
Dan Kortschak ebad375bab gopls/internal/lsp/protocol: prevent license rendering in godoc
Change-Id: I6de75a869ee1b210c692ef47e3c672589f76337c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/465995
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-07 20:55:54 +00:00
Robert Findley 10a39ef32d gopls/internal/lsp/regtest: address additional comments on marker.go
This CL addresses code review comments from earlier CLs that were easier
to to in a follow-up.

Change-Id: Ib4bb4cd828377727bdc6dae606fb03d4e06024a6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/466143
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-02-07 20:50:53 +00:00
Robert Findley 69920f2e63 gopls/internal/regtest/marker: add missing tests for hover
Add additional tests for hover behavior. These tests would have failed
in earlier patchsets of the subsequent CL rewriting hover.

Also, add support for the special "env" file to the marker framework.

Change-Id: Iecbd4994a6c1261f87163d50793fbbc5f26ea1ba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/466135
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-02-07 20:33:41 +00:00
Robert Findley 24a13c6fad gopls/internal/regtest: fill out features of the new marker tests
Add missing features to the new marker test implementation, implement a
few new markers, and port some tests to demonstrate the new structure.

Additionally, improve UX following some experience working with these
tests.

Specifically:
- Add support for settings.json. This was necessary for standard library
  hover, since full documentation was too verbose and varied across Go
  versions.
- Ensure that the ordering of ordinary archive files is preserved. I
  kept having go.mod sorted below go files, which harms readability.
- Add a helper to provide a nice location summary for test output,
  formatting both local and global (=archive-wide) positions.
- Add support for both regexp and string locations conversion.
- Add the loc marker, which is pre-processed to make named locations
  available to other markers.
- Add the diag marker, which defines a 1:1 pairing between observed and
  expected diagnostics.
- Add the def marker, which runs textDocument/definition.
- Port around half of the godef tests, which include both def and hover
  markers. While doing so, try to extract related assertions into
  separate tests, to improve organization and documentation and reduce
  test size. Remaining tests will have to wait, as this CL was getting
  too big.

For golang/go#54845

Change-Id: Id9fe22c00ebd1b3a96eeacc5c0e82fca9c95c680
Reviewed-on: https://go-review.googlesource.com/c/tools/+/465895
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-02-07 20:33:20 +00:00
Robert Findley 2b149ce94b gopls/internal/regtest: add a regtest-based version of the marker tests
Add a new implementation of the gopls marker tests that shares the same
testing environment as the regression tests. Along the way, revisit the
semantics of the marker framework, to address some problems we've
identified over the years.

Specifically:
- Split tests into self-contained txtar encoded files. Each file
  determines an isolated set of markers, and is executed in a separate
  session.
- Change the mechanisms for golden content, so that it is joined by
  identifiers, and passed to the test method as an argument. This makes
  it more apparent where golden content is used, and makes the identity
  of golden content stable under manipulations of the source (as opposed
  to some arbitrary munging of the note position)
- Allow custom argument conversion that may be convenient for LSP-based
  test functions, by avoiding the packagestest framework and instead
  building directly on top of the x/tools/go/expect package. As an
  initial proof of concept, this allowed using a protocol.Location as a
  test method argument.
- Add significant documentation and examples.
- Deprecate the @hover marker in the old marker tests
  (gopls/internal/lsp).

I believe that this lays the foundation to address the remaining
concerns enumerated in golang/go#54845, as this new design solves the
isolation problem, the problem of golden file naming, and the lack of
clarity around the definition and construction of test annotations.

For golang/go#54845

Change-Id: I796f35c14370b9651316baa1f86c21c63cec25c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/465255
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-02-07 20:32:51 +00:00
Alan Donovan edddc5fc32 go/packages: don't discard errors loading export data
In the course of debugging something unrelated, I noticed
that loadFromExportData's error result was always discarded.
This change appends it to the set of package errors.

Change-Id: I32a7cbceb7cffd29cedac19eeff8b092663813f0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/466075
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2023-02-07 14:59:06 +00:00
Tim King a762c82c1b go/ssa: add MultiConvert instruction
Adds a new MultiConvert instruction. MultiConvert instructions
are a catch all for conversions involving a typeparameter that
would result in multiple different types of conversion
instruction [sequences].

Updates golang/go#56849

Change-Id: I6c2f53ccef1b933406096d6ca2867f1007a13bd3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/457436
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Tim King <taking@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-06 19:10:06 +00:00
Oleksandr Redko f124b50345 cmd/stringer: streamline test subprocesses
- Execute the test binary itself as cmd/stringer instead of invoking (and
cleaning up after) 'go build'.
- Replace os.MkdirTemp with T.TempDir

Changes are similar to https://go.dev/cl/377836.

Change-Id: I5f9fca20e0f1f045826c385d556257fc5982ed53
GitHub-Last-Rev: f6c6b7735c
GitHub-Pull-Request: golang/tools#425
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464350
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
2023-02-06 18:58:38 +00:00
Oleksandr Redko 6b6857acbe gopls: fix typos in comments and doc
Change-Id: Ia71c87a4f0180869aa10fe31e6c2cf19d1ac713d
GitHub-Last-Rev: ebb377550c
GitHub-Pull-Request: golang/tools#427
Reviewed-on: https://go-review.googlesource.com/c/tools/+/465315
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-06 17:56:06 +00:00
Tim King 8111118043 go/analysis/internal/facts: fix cycle in importMap.
This change resolves two interrelated outstanding bugs in handling Named
types and type declarations in importMap().
1) Named types did not visit their Underlying() types.
2) Whether Named types were fully visited was order dependent.
   Previously a Named type was not fully visited (methods visited, etc)
   when the type declaration was visited by addObj() before the Named
   type was visited by addType().

Fixes golang/go#49469

Change-Id: Ibf9c6d9afd4958d474149edf2749d994199f14b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/362414
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tim King <taking@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-02-02 23:42:27 +00:00
Robert Findley dd1c468586 gopls/internal/lsp/source: simplify extracting object hover doc
Add a new helper HoverDocForObject, which finds the relevant object
documentation without needing to type-check. This eliminates the last
use of FindPackageFromPos.

For golang/go#57987

Change-Id: Ic9deec78d68156e9ead3831a8247f8c30259a3c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464455
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-02 19:22:17 +00:00
Robert Findley 66f8f71991 gopls/internal/lsp/source: use syntax alone in FormatVarType
FormatVarType re-formats a variable type using syntax, in order to get
accurate presentation of aliases and ellipses. However, as a result it
required typed syntax trees for the type declaration, which may exist in
a distinct package from the current package.

In the near future we may not have typed syntax trees for these
packages. We could type-check on demand, but (1) that could be costly
and (2) it may break qualification using the go/types qualifier.

Instead, perform this operation using a qualifier based on syntax
and metadata, so that we only need a fully parsed file rather than a
fully type-checked package. The resulting expressions may be inaccurate
due to built-ins, "." imported packages, or missing metadata, but that
seems acceptable for the current use-cases of this function, which are
in completion and signature help.

While doing this, add a FormatNodeWithFile helper that allows formatting
a node from a *token.File, rather than *token.FileSet. This can help us
avoid relying on a global fileset. To facilitate this, move the GetLines
helper from internal/gcimporter into a shared tokeninternal package.

For golang/go#57987

Change-Id: I3b8a5256bc2261be8b5175ee360b9336228928ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464301
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-02-02 19:21:44 +00:00
Gopher Robot 30f191f36d internal/imports: update stdlib index for Go 1.20
For golang/go#38706.

Change-Id: Iefd858ec1848481a26d6bb88076ff8a3c2f8a818
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464875
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Gopher Robot <gobot@golang.org>
2023-02-02 17:00:30 +00:00
Dmitri Shuralyov 4e98188bf6 internal/imports: use go/packages instead of cmd/api to compute symbols
The API of syscall/js package is generated by reusing cmd/api. That has
stopped being a runnable command after an internal refactor in Go 1.20.
Since cmd/api was never really supported or meant to be used outside of
GOROOT, switch to using go/packages and compute the API more directly
ourselves.

Also use the same approach to generate the API of package unsafe (whose
API is also not present in GOROOT/api files at this time) instead of a
fixed list that needs manual maintenance. This adds Add and Slice that
were added to package unsafe in Go 1.17. It also removes ArbitraryType,
since that symbol isn't a part of package unsafe's API but used in its
documentation—it seems like an oversight that it was added in CL 24463.

This CL intentionally leaves out unsafe's SliceData, String, StringData
that were added in Go 1.20, so I can test out the new relui workflow to
send a CL that regenerates this package.

Fixes golang/go#58245.
For golang/go#38706.

Change-Id: Ibe0d89bf0469691bd16e0d0f501e3762256f2239
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464715
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
2023-02-02 15:31:42 +00:00
Brad Fitzpatrick 4e8ff892ae internal/imports: update stdlib index for 1.20
Change-Id: Ia4f847652ca17f38d83214d8211be99365d9eca3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464342
Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2023-02-01 23:31:58 +00:00
Viktor Blomqvist 6bd0d00485 gopls/internal/lsp: go to definition from linkname directive
Enables jump to definition on the second argument in
//go:linkname localname importpath.name
if importpath is a transitive (possibly reverse) dependency
of the package where the directive is located.

Updates golang/go#57312

Change-Id: I59fa5821ffd44449cf49045a88b429f21e22febc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463755
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2023-02-01 22:03:46 +00:00
Cuong Manh Le 0cfddb3c3d gopls/internal/lsp: enable clear builtin completion test
For golang/go#56351

Change-Id: I3a6e3ef58285d46fe239e900d98fdb5617a1733c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464240
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-02-01 20:15:37 +00:00
Robert Findley 41adf8d4f9 gopls/internal/lsp/tests: remove StripSubscripts
Type parameter strings have not had subscripts for a long time.

Change-Id: If43c443720335ae98d6b032f23b02639c639af6b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464475
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2023-02-01 19:46:23 +00:00
Alan Donovan 86fdadc60b gopls/internal/lsp/safetoken: delete safetoken.Range
Now that its scope has been substantially reduced, there's
no need for this type, so this change expands it out to
a triple (or pair in some cases).
The defensive check in NewRange is never needed.

Alsoo, rename RangeToTokenRange to RangePos, following the convention.

Also, fix incorrect uses of the term "wire format".

Change-Id: I5bfc5bf8ce6c9504166cc928cad1df2df000737a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464056
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
2023-02-01 19:17:58 +00:00
Robert Findley c276ee52bc internal/robustio: fix signature of getFileID on plan9
Also fix the failing new gopls command integration tests, which observe
a different exit code on plan9.

Change-Id: I5d0c11549deb3d3643f4d7772f0659dfda3600ea
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464297
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-02-01 18:41:57 +00:00
Cuong Manh Le e170d456ff gopls/internal/lsp: add clear builtin
For golang/go#56351

Change-Id: I5948b776cf7fde275a329d02a4f5728579f13ee9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463055
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-02-01 14:09:29 +00:00
Tim King 2ea4b81bfc go/ast/inspector: skip ranges that do not contain a node type
Skips inspecting a range of nodes that do not contain any nodes
of a given type. Computes a bitmask of type nodes between push
and pop events. Skips forward to pop if nodes in between cannot
match the type mask.

Benchmarking against previous implementation on "net":
- Preorder filtered by *ast.FuncDecl and *ast.FuncLit
  traversal is faster by 11x.
- Preorder filtered by *ast.CallExpr is faster by 10%.
- Unfiltered traveral is 5% slower.
- Constructing events 3% slower.
- Break even for additional computation is 5 *CallExpr
  filtered traversals or 1 *Func{Decl,Lit} filtered
  traversal.

Change-Id: If4cb566474b84186ff42fb80ed7e1ebb0f692cc2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/458075
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tim King <taking@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-01-31 21:38:46 +00:00
Tim King 407bbed8c5 go/analysis: improve error message on duplicate fixes
Improves the error message on conflicting overlapping fix suggestions.

Example output:
```
conflicting edits from other and rename on /path/example/foo.go

first edits:
--- base
+++ other
@@ -1,8 +1,8 @@
 package other

 func Foo() {
-       bar := 12
+       bbaz := 12
-       _ = bar
+       _ = bbaz
 }

 // the end

second edits:
--- base
+++ rename
@@ -1,8 +1,8 @@
 package other

 func Foo() {
-       bar := 12
+       baz := 12
-       _ = bar
+       _ = baz
 }

 // the end
```

Rewrite of applyFixes to no longer use trees and to consolidate edits by file uniqueness.

Fixes golang/go#56535

Change-Id: Ia683888c51a97a357715796b434c2d6ef92c4fef
Reviewed-on: https://go-review.googlesource.com/c/tools/+/457615
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-01-31 21:23:58 +00:00
cui fliter bd5dfbb418 all: fix some comments
Change-Id: I44a562ec6d71dcf638333a855083f46201ef9a5e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464236
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-01-31 16:03:41 +00:00
Peter Weinberger 072fca58f7 gopls/protocol: use the current definition of the lsp
There are no changes to main line gopls code.

The type of ParamInitialize.Trace changes from string to a string
type TraceValues. This only affects fake/editor.go

Four messages were changed to go from the server to the client,
necessitating changes to the various test clients.

Some copied comments in tsprotocol.go have changed.

Finally, the parse completeness test found a new field, Deprecated,
in metaModel.json. It duplicates information already in
the Documentation field.

Change-Id: I14bbc63e8b1a1aebb7cd2d55ce282fe42568ecc2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464095
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-31 15:22:40 +00:00
Peter Weinbergr aa633e7edc tools/gopls: provide markdown for completion and signature help
If the client prefers markdown, provide markdown.

There is a change to the LSP stubs, with Documentation fields becoming
Or-types (string|MarkupContent). If the client prefers, the returned
Documentation is markdown.

Fixes: golang/go#57300
Change-Id: I57300146333552da3849c1b6bfb97793042faee2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463377
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-31 13:44:44 +00:00
Tim King 684a1c0d5e go/analysis/internal/analysisflags: use os.Executable for program path
For -V=full, use the os.Executable for the program path instead of os.Args[0].

Fixes golang/go#57716

Change-Id: Ia571f922aef037a16ffc78f8c2c32ae4c70918c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/461496
Run-TryBot: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-01-31 01:06:35 +00:00
Alan Donovan bd5e595bef gopls/internal/lsp/cache: add missing mutex
Change-Id: Ie12588961a3f2ceba3a0c9d33eccbc83cf1f4871
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464057
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-01-31 00:11:29 +00:00
Hana (Hyang-Ah) Kim 26831282ac gopls/internal/lsp: differentiate govulncheck/vulncheck imports diags
Use different diagnostic source names for diagnostics from govulncheck
run ("govulncheck") and diagnostics from gopls's imports analysis
("vulncheck imports").

Fixes golang/vscode-go#2575

Change-Id: Ic79418146e4793bfc35fbf68d7539c7f0df1a636
Reviewed-on: https://go-review.googlesource.com/c/tools/+/461556
Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
2023-01-30 20:57:17 +00:00
Hana (Hyang-Ah) Kim d1e92d6aba gopls/internal/lsp/mod: reorder vulncheck quick fixes
Nudge developers towards recommended actions by listing them first.
More specifically,
  0) Other diagnostics if any (e.g. errors in go.mod)
  1) Run govulncheck
  2) Upgrade to a specific version
  3) Upgrade to latest
  4) Reset govulncheck result

Fixes golang/vscode-go#2576

Change-Id: Ib83f8dab5a1c5bea600fe1ec61701218c7a65ac1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/461555
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-01-30 20:48:47 +00:00
Robert Findley 87d00e630f gopls/internal/lsp: separate some requests from source.Identifier
Start to unwind source.Identifier by unrolling definition, type
definition, and call hierarchy handlers.

Along the way, introduce a couple primitive helper functions, which may
be made obsolete in the future but allowed preserving source.Identifier
behavior:
- referencedObject returns the object referenced by the cursor position,
  as defined by source.Identifier.
- mapPosition is a helper to map token.Pos to MappedRange in the narrow
  context of a package fileset.

After this change, the only remaining use of source.Identifier is for
Hover, but that is a sizeable refactoring and therefore left to a
subsequent CL.

Updates golang/go#57987

Change-Id: Iba4b0a574e6a6d3d54253f3b4bff8fe6e13a1b15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463955
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-30 20:26:59 +00:00
Robert Findley ae242ec327 gopls: fix windows file corruption
Fix the bug that gopls finds the wrong content when formatting an open
URI whose spelling does not match the spelling on disk (i.e. because of
case insensitivity).

Remove the whole View.filesByBase mechanism: it is problematic as we
can't generally know whether or not we want to associate two different
spellings of the same file: for the purposes of finding packages we may
want to treat Foo.go as foo.go, but we don't want to treat a symlink of
foo.go in another directory the same.

Instead, use robustio.FileID to de-duplicate content in the cache, and
otherwise treat URIs as we receive them. This fixes the formatting
corruption, but means that we don't find packages for the corresponding
file (because go/packages.Load("file=foo.go") fails).  A failing test is
added for the latter bug.

Also: use a seenFiles map in the view to satisfy the concern of tracking
relevant files, with a TODO to delete this problematic map.

Along the way, refactor somewhat to separate and normalize the
implementations of source.FileSource.

For golang/go#57081

Change-Id: I02971a1702f057b644fa18a873790e8f0d98a323
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462819
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-01-30 19:34:14 +00:00
Alan Donovan 6f652132c9 gopls/internal/lsp/protocol: Mapper.NodeMappedRange
This change adds a few missing convenience wrappers
in the {PGF,Mapper}.{Pos,Node}MappedRange() cross product.

Change-Id: I0187eae590757e32cd5cb402b3054bcc662e62d3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464096
Auto-Submit: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-01-30 18:23:39 +00:00
Peter Weinbergr e260368884 gopls/semantic: report type parameters in the type of a receiver
The code was misclassifying K, V in the reciever, as in
func (s *Foo[K, V]) Get(k K) (V, bool)...

Fixes: golang/go#57619
Change-Id: I77eae7929c4b9434c8c25bbc337151dcf90f8452
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463316
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
2023-01-28 19:53:28 +00:00
Bryan C. Mills b62cbb6b59 internal/lockedfile: fix build constraints on solaris
The version of this file in the main repo uses a "!unix" build
constraint, which had to be ported to a longer list for inclusion in
gopls (which still supports Go versions that predate the "unix" tag).

Solaris is a Unix derivative, and its implementation is provided in
the "fcntl" implementation.

Updates golang/go#57747.

Change-Id: Ibde8ce55dadc03ad3cb797b5320f5b75580f639f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463776
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
2023-01-27 23:34:20 +00:00
Alan Donovan 1aa7e72e72 gopls/internal/lsp/source: avoid qualifiedObjectsAtProtocolPos
This change to PrepareRename eliminates one of the last two
calls to qualifiedObjectsAtProtocolPos. All it needs is
the current file and the object name, so it was overkill.

The last use (from Rename) will be removed in a follow-up;
it is much more involved.

Change-Id: I64a06d95f7d2a88ace0f3c168bad7f0a8c0a7a04
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463896
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>
2023-01-27 18:39:24 +00:00
Alan Donovan 5ed33dffa5 gopls/internal/lsp/source: rename: prep for incrementality
This change moves into rename.go various declarations that,
thanks to recent work, are only used for renaming.
(The moved functions have not changed.)
It also extracts the lengthy "package name" special case
into a separate function, and adds a few comments.

The checkRenaming call has been pulled out of renameObj into
the callers. In one of these, it was not needed.

Change-Id: I4e2d354c098296980b6bcc2fe8ddc2e212e10aa8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463895
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-27 18:39:22 +00:00
Alan Donovan e0659d1f36 gopls/internal/lsp/source: simplify legacy 'references' func
The function used to accept three booleans, the middle of which
was always false. By simplifying under that invariant, the
other two booleans fall away, along with the 'implementations'
query that it used to make.

Small steps...

Change-Id: Ib520661b822afd85d6f0311253779a6202afd33d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463687
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-01-27 03:06:49 +00:00
Robert Findley 1edcfe78f9 gopls/internal/regtest/diagnostics: require cgo for TestGoListErrors
Fixes golang/go#58103

Change-Id: I378496e5ed791e33932c58d88cfb1f37ff125936
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463686
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-27 00:20:08 +00:00
Alan Donovan f052158799 gopls/internal/lsp/protocol: move TestBytesOffset
Change-Id: Ied6bbcc7a4da1a513e500f1e650ca9b1b51c6254
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463685
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-26 22:25:35 +00:00
Alan Donovan d093a1395b gopls/internal/lsp/protocol: LocationTextDocumentPositionParams
A helper function for populating LSP requests.

Change-Id: Id9cbca56f8e32321680ba8ee4d7073d097789784
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463683
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2023-01-26 22:19:54 +00:00
Alan Donovan bcb677e49c gopls/internal/regtest: make RegexpSearch return a Location
...along with various other Editor methods.

Do we need a more convenient way to say
  env.Sandbox.Workdir.URIToPath(loc.URI) ?

Change-Id: I452028db4b99843e07861909ad8cef87cf9fb118
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463655
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-26 22:17:31 +00:00
Robert Findley 60782e9bdb gopls/internal/lsp/source: eliminate a couple uses of posToMappedRange
Eliminate a couple uses of posToMappedRange, which potentially
type-checks, where it is clearly unnecessary.

Also improve test output for highlight.

Updates golang/go#57987
Updates golang/go#54845

Change-Id: I5580bf6431def0a6ee635e394932934ec7fe1afb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463556
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2023-01-26 21:09:40 +00:00
Robert Findley 031e6e6d06 gopls/internal/lsp/source: eliminate ResolveImportPath
Following up on CL 461944, eliminate uses of ResolveImportPath.

At two of the three callsites, we avoid type-checking. The one that
remains is in renaming.

For golang/go#57987

Change-Id: Ia974d39f2db72a1fe1373cff5faeb07ecb54effb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463376
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-01-26 21:09:30 +00:00
Robert Findley f2cd9ef6a3 gopls/internal/lsp/source: reduce usage of TypecheckWorkspace
Fix calls to TypeCheck using TypecheckWorkspace where we really want
TypecheckFull. Also, use NarrowestPackage where it suffices.

In approximate order of appearance:
- Code actions, semantic tokens, code lens, and document highlights are
  all scoped to a file; the narrowest package for that file should
  suffice.
- When completing at a position, we need the full package to find
  enclosing context. Furthermore, that file is open, and so will be
  fully type-checked by other operations.
- Ditto for suggested fixes, inlay hints, and signature help.

The current behavior leads to incorrect or missing functionality when
outside the workspace. I did not add comprehensive tests demonstrating
this in all cases, but added one for signature help.

For golang/go#57987

Change-Id: I8270d0f0a0787e36bd4103378176d150426d37f2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/463375
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2023-01-26 21:09:17 +00:00
Robert Findley f10e7d56a3 gopls/internal/lsp/cache: remove package dependence on packages.Config
The cache.pkg type was a mix of metadata-related information and type
checking information, resulting in unnecessary relationships between
type-checking results (which are shared) and loading results (which are
not shared). As a result, the experimentalPackageCacheKey was more or
less a hope that these relationships were valid.

Avoid this relationship altogether by separating the shared
type-checking result from other derived calculations. This makes the
experimentalPackageCacheKey obsolete and lays the groundwork for
type-checking from export data.

Additionally:
- revisit the package cache key to ensure it covers all inputs into
  type-checking, and make it more similar to the analysis key
- remove methods from the source.Package API that return source.Package:
  we can't have edges between packages if they are going to be
  standalone
- remove the experimentalPackageCacheKey setting
- add a test for go list errors
- use the proper types.Sizes when type-checking
- address a comment from an earlier CL in completion_test.go

Fixes golang/go#57853

Change-Id: I238913c7c8305cb534db77ebec5f062e96ed2503
Reviewed-on: https://go-review.googlesource.com/c/tools/+/461944
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-26 21:09:09 +00:00
Alan Donovan 827075753a gopls/internal/lsp/source: switch call hierarchy to references v2
This change removes the last use of the old referencesV1 function.
(Its 'references' helper function still has one remaining use,
from Server.rename.)

The IncomingCalls operation re-parses the files referenced by
the 'references' operation, rather than requesting a type-checked
package.

Also, inline toProtocolIncomingCalls into sole caller.

Change-Id: I33fbb210d42b7ca1a70cfebc4061275a153c3537
Reviewed-on: https://go-review.googlesource.com/c/tools/+/459515
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-01-25 23:57:28 +00:00