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

3118 Коммитов

Автор SHA1 Сообщение Дата
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
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
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
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
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
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
Peter Weinbergr 1faecd32c9 tools/internal/diff: fix off-by-one error in computing diffs
In the removed code
if endCol := end - 1 - strings.LastIndex(src[:end], "\n"); endCol > 0
the endCol test is off by one. It should have been endCol >= 0, otherwise
there are cases where extending the edit won't be considered.
But endCol is always >= 0, as LastIndex(src[:end], "\n") is <= end-1.
Another way of saying all this is the extending the edit doesn't need
endCol at all.

The effect of this was to fail to extend edits if the edit started
the line.

The tests were revised to check unified diffs by using the
patch command.

Fixes: golang/go#457256

Change-Id: Idb23f1a28d36f92a7b8712e9459df86a3d420d7e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/459236
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
2023-01-21 15:27:42 +00:00
Alan Donovan 271e621c97 internal/lockedfile/internal/filelock: fix aix build tag
aix uses the fnctl-based fallback implementation, not
flock, since its flock is susceptible to the problem
described at https://en.wikipedia.org/wiki/File_locking:
All fcntl locks associated with a file for a given
process are removed when any file descriptor for that file
is closed by that process.

Change-Id: I266bbf80c126765b302fbc713c47eb6000ec7be1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462657
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-01-20 01:36:11 +00:00
Russ Cox bcc7794c08 go/analysis/passes/directive: add directive analyzer
The directive analyzer is a generalized version of
the buildtag analyzer, meant to apply checks about
any directives (//go:... lines) found in source code.

For now it only checks the placement of //go:debug lines.

For golang/go#56986.

Change-Id: I2bd3d743c44554711ada90f6ee53b6195dc55bcb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462216
Run-TryBot: Russ Cox <rsc@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
2023-01-19 20:43:01 +00:00
Alan Donovan bb7c440efb gopls/internal/lsp/filecache: use file locking, not rename
After various dismal experiments, I'm not optimistic that
Windows provides any means to rename a file atomically.

This change causes filecache to use file locking, on
all platforms, to ensure that cache entries are updated
atomically.

The implementation of locking was plundered wholesale from
$GOROOT/src/cmd/go/internal/lockedfile, modified only as
needed to get it to compile outside GOROOT.

The change causes the (new) BenchmarkUncontendedGet to
increase to 32us, up from 16us, on macOS. Probably still
good enough, and preferable to two different implementations.

Fixes golang/go#57747

Change-Id: Icd373e99481789056d70c02cbcd554bd59eb3101
Reviewed-on: https://go-review.googlesource.com/c/tools/+/461800
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-01-18 21:52:08 +00:00
Alan Donovan f0e2d5c52e internal/gcimporter: discard position info for unneeded lines
This change implements an optimization in the size of the
shallow export data: instead of saving the entire line
start offset table of each file, it saves a sparse representation
of each file capable of restoring accurate position information
for the entirety of each line that contains an encoded token.Pos,
but no others.

This reduces the total size of export data for the standard library
to 665KB, down 31% from 957KB, and only 18% more than the original
baseline of 564KB.

The shallow_test asserts (for a couple of specific objects) that
the end positions may be derived from the start positions either
before or after converting token.Pos to token.Position.

Change-Id: I5c2a1648398d0bee979dc36ba6224072ea183bec
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462096
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-01-18 14:54:44 +00:00
kouler f3e53e5cc3 internal/jsonrpc2_v2: fix typos
Change-Id: I96ad3f8fdb675bdb249934d92fd5d01d28c7dd6b
GitHub-Last-Rev: 969dfc7945
GitHub-Pull-Request: golang/tools#421
Reviewed-on: https://go-review.googlesource.com/c/tools/+/461075
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-01-17 23:21:59 +00:00
Alan Donovan d958e85480 internal/gcimporter: use two-level file index
This change introduces a two-level index of files, as a
precursor to an optimization in which only the line number
information for the necessary positions is recorded.
The optimization naturally requires two passes over the
data, which means we can't emit the file information
in one gulp.

Change-Id: Ia8e015c8b19cbf6074661ec345c7360a325d1054
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462095
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-17 18:50:32 +00:00
Alan Donovan 8aba49bb5e internal/gcimporter: preserve column and line in shallow iexport
Historically, export data has discarded source position information.
Originally not even line numbers were available; at some point
line and column numbers were stored, up to some fixed limit, but
more recently column numbers were again discarded.
Offset information has always been incorrect.

gopls is moving toward greater reliance on incremental operation
using a file-based cache of export data and other serializable
records that are similar in character. It is critical that it
be able to accurately recover file position information for
dependencies.

This change causes the iexport function to encode each object's
token.Pos as a pair (file, offset), where file indicates the
token.File and offset is a byte offset within the file.
The token.File is serialized as a filename and a delta-encoded
line-offset table. (We discard the lineInfos table that supports
//line directives because gopls no longer uses it.)
The iimport function constructs a token.File and calls SetLines,
and then all token.Pos values work exactly as they would with
source.

This causes about a 74% increase in size of the shallow export
data for the standard library: was 564KB, now 982KB.

token.File has a SetLines method but no GetLines. This change
must therefore resort to... unorthodox methods to retrieve the
field. Suggestions welcome.

This alternative encoding is enabled by using "shallow" mode,
which is effectively a license for gopls to do whatever it wants.
Again, suggestions welcome.

Updates golang/go#57708

Change-Id: I028ed669161e38a9a4672dd8d9cadb268a0cdd07
Reviewed-on: https://go-review.googlesource.com/c/tools/+/461215
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-01-17 18:02:57 +00:00
Alan Donovan 5c176b1de4 internal/robustio: skip os.Link test on android
https://pkg.go.dev/internal/testenv#HasLink says:

	// From Android release M (Marshmallow), hard linking files is blocked
	// and an attempt to call link() on a file will return EACCES.
	// - https://code.google.com/p/android-developer-preview/issues/detail?id=3150
	return runtime.GOOS != "plan9" && runtime.GOOS != "android"

Fixes golang/go#57844

Change-Id: I92594daf99d3a0e74507f7f3ab806e3ed5af533f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462415
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-01-17 17:44:17 +00:00
Robert Findley 5b300bd649 gopls/internal/lsp/cache: clean up view workspace information
Tracking of workspace information in the View contained several
inconsistencies and redundancies. Clean this up, with the following
changes:

- eliminate the View.rootURI, opting to derive it instead
- eliminate the View.explicitGowork field, instead using the view.gowork
  field and checking if it is outside of the workspace.
- eliminate many places where directory filters were interpreted
  relative to the rootURI. This is wrong: directory filters are
  expressed relative to the workspace folder.
- remove special handling of GOMODCACHE, now that we're on Go 1.16+
- rewrite the locateTemplateFiles function to use view.filterFunc and
  filepath.WalkDir (now that we're on Go 1.16+).
- don't request goimports env vars when loading environment variables
  for the view. They weren't being propagated to goimports anyway, and
  goimports will load them as needed.

For golang/go#55331

Change-Id: I5e7f7e77e86d9ae425d2feaff31030278fed8240
Reviewed-on: https://go-review.googlesource.com/c/tools/+/459789
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-12 15:06:27 +00:00
Alan Donovan e345d46ec2 internal/gcimporter: fix export of invalid methods
The declaration "func () F()" used to cause the exporter to fail.
This change now exports it as "func F()" which is how the type
checker (mostly) repairs it.

Fixes golang/go#57729

Change-Id: I80958a75a57800ff8afc35e95e0c8e98191aac97
Reviewed-on: https://go-review.googlesource.com/c/tools/+/461575
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-01-11 21:11:29 +00:00
Alan Donovan 3856a5d80c internal/robustio: add Plan9 support to FileID
Fixes golang/go#57642

Change-Id: I269162017b78e9009d60aeca87255a57611fcd4b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/460855
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Bypass: Bryan Mills <bcmills@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-01-06 16:49:32 +00:00
Tim King 33071fbe1a internal/robustio: move robustio
Moves gopls/internal/robustio to internal/robustio.
Allows usage by packages in x/tools outside of gopls.

Change-Id: I71743c3a91458b77f12606b743b5de7e23cc5051
Reviewed-on: https://go-review.googlesource.com/c/tools/+/460116
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-02 23:56:08 +00:00
Alan Donovan 224a61b354 gopls/internal/lsp/source: delete Snapshot.WriteEnv method
This method is called once immediately after View construction.
It used to run 'go version', but with minor tweaks, the View
already has this information via wsInfo.

This change removes it from the Snapshot interface and
eliminates the unnecessary 'go version' subprocess.

Change-Id: I86e8dd37a7a237949c05820ca3e4fdb5035f90f7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/459782
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-12-29 17:48:08 +00:00
Alan Donovan 6df6eee463 internal/diff/lcs: optimize inner loop
The core operation of the diff algorithm is to advance
a cursor forwards or backwards over common substrings
of the two sequences. This change refactors the sequence
abstraction to express this, permitting faster and type-
specialized implementations of the common-prefix and
common-suffix operations.

This improves the running time on the new LargeFileSmallDiff
benchmark by 17%:

Before:
BenchmarkLargeFileSmallDiff/bytes-8         	    9838	    521006 ns/op
BenchmarkLargeFileSmallDiff/runes-8         	   10000	    522915 ns/op

After:
BenchmarkLargeFileSmallDiff/string-8         	   14545	    412497 ns/op
BenchmarkLargeFileSmallDiff/bytes-8          	   13868	    432577 ns/op (-17%)
BenchmarkLargeFileSmallDiff/runes-8          	   13744	    436548 ns/op (-17%)

Also, some cleanups:
- Compute is replaced by three Diff{Strings,Bytes,Runes} functions.
- The LCS result is now internal, as it is needed only by tests.
- The caller's maxDiff constant is moved into this package.
- Test{Forward,Backward,TwoSided} are factored together.
- Delete unused randlines().
- {append,prepend}lcs are now methods
- Diff declaration moved to more prominent location.
- A test of the three DiffT functions.

Future work:
- faster common-prefix implementations are possible: the two
  operations still account for about 5% of this benchmark.
- common-suffix for strings is about 50% faster than for bytes.
  Find out why.
- There appear to be opportunities for much bigger gains
  on the above benchmark by stripping the common prefix and
  suffix as a first step. See comments in benchmark.

Change-Id: I475b7fc731d628d54e652a4ace7ce67c6c2755c2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446575
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-12-19 23:49:02 +00:00
Alan Donovan 57b1265846 go/gcexportdata: drop support for go1.6 export data
The gcimporter.ImportData function and its parser
implementation for the old "$$" form have not been
needed in many years.

Change-Id: I35be3436207fad1d845d9cc8ab2f82c8dfbb15b8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/457655
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-12-19 23:48:42 +00:00
Alan Donovan 099260e6e7 gopls/internal/lsp: followups to dropping line directives
(This change was my independent effort to remove support
for line directives, which Peter already did in CL 439115.
The changes were substantially similar but this one also
made some follow-on simplifications.)

Also, NewMappedRange(token.File, ColumnMapper, ...) no
longer needs its first argument since it is redundant with
ColumnMapper.TokFile.

Also, inline away cache.parseGoSpan, and update various comments.

Fixes golang/go#55403

Change-Id: I951043c0ece9ee0a9ce65ae174d25057b0e1255a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/457656
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>
Reviewed-by: Peter Weinberger <pjw@google.com>
2022-12-19 23:43:01 +00:00
Alan Donovan df35cd84ea x/tools: drop support for Go toolchains older than go1.16
This change removes all testenv.NeedsGo1Point(16) and earlier
calls from tests, which assert that the go command used at run
time is at least go1.16; this is now assumed.

Also, we assume that a Go toolchain of at least go1.16 is used
to build the packages in this repo. This is asserted by the
introduction of a reference to io.Discard in go/packages.

Change-Id: Ie12d721b44e057ad9936042afb255fa90b2ac5a8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/457657
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-12-15 19:53:47 +00:00
Matthew Dempsky 3cba5a847f internal/gcimporter: port CL 424876 from std importer
This is a port of CL 424876, except it temporarily maintains a
fallback path for older cmd/compile behavior before CL 455279, to
avoid breaking users following Go tip.

Updates golang/go#57015.

Change-Id: I168d171153d96485e92be19645422fe65ab4b345
Reviewed-on: https://go-review.googlesource.com/c/tools/+/456376
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-12-09 16:49:23 +00:00
Bryan C. Mills bdcd082252 internal/gcimporter: skip tests earlier when 'go build' is not available
This fixes tests failing on the Android builders on Go 1.20 after CL
454499. Previously the tests were skipped in the 'compile' helper
function, but as of that CL they fail before reaching that point due
to missing export data for packages in std.

Updates golang/go#56967.
Updates golang/go#47257.

Change-Id: Ief953b6dbc54c8e0b1f71fc18a0d6ab212caf308
Reviewed-on: https://go-review.googlesource.com/c/tools/+/454500
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-12-02 22:09:34 +00:00
Bryan C. Mills f540ee6b17 internal/gcimporter: load cached export data for packages individually
In short tests, also avoid creating export data for all of std.

This change applies the same improvements made to the equivalent std
packages in CL 454497 and CL 454498. (It may even fix the reverse
builders that are currently timing out in x/tools, although I suspect
there is still a bit of work to do for those.)

For golang/go#56967.
Updates golang/go#47257.

Change-Id: I82e72557da5f917203637513122932c7942a98e9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/454499
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-12-02 18:23:46 +00:00
Alan Donovan e0b516bc0a gopls/internal/lsp/cache: invalidate metadata after vendor change
This change causes the snapshot to watch the vendor/modules.txt
file and to invalidate the metadata if it changes, since it
could cause modules to move.

Also, add a regression test for the bug in which running
go mod vendor causes a module to move, but the Definitions
operation reports the old location. (And the reverse case
of deleting the vendor tree.)

Also, add persistent.Map.String method, for debugging.

Fixes golang/go#55995

Change-Id: I48302416586c763b4a4de7d67aaa88fde52ea400
Reviewed-on: https://go-review.googlesource.com/c/tools/+/454315
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-12-02 15:45:07 +00:00
Michael Matloob 0379b73aef internal/gcimporter: fix TestImportStdLib
The test attempted to find all stdlib packages by scanning
pkg/$GOOS_$GOARCH for .a files and then tried to import all of them.
Now that .a files are no longer being placed there, the test is a
noop. Fix this by using go list std (and filtering out testonly
packages) and trying to import all of those to recreate what the test
intended to do.

This also removes a dependency on the pkg/$GOOS_$GOARCH directory
which will stop being produced by dist in CL 453496.

For golang/go#47257

Change-Id: Idfa0cbb21093776183ce193eb5363a9727bf77ef
Reviewed-on: https://go-review.googlesource.com/c/tools/+/454118
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-12-01 21:10:12 +00:00
Hana (Hyang-Ah) Kim 4c3cb1e658 internal/gocommand: add GoVersionString
Unlike the existing GoVersion that returns the minor version
number of the go command, GoVersionString returns the part that
indicates the major/minor/patch version from `go version`
output.

The full go version info is necessary when analyzing
vulnerabilities.

Change-Id: I5ea624e877e02009148ad906e6475cb1aba40b3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/453595
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-28 20:57:20 +00:00
Bryan C. Mills 2b56641c37 internal/gcimporter: adjust the number of expected packages in TestStdlib
CL 451995 omitted the 'x/tools/...' pattern on Android,
which allowed the packages to load successfully but left the count
lower than expected (not all packages in 'std' build on Android).

This is the only failure mode I continue to see regularly on the
android-amd64-emu builder.

Change-Id: I0b4fac647935c745a9894621a6ebcfb5f2b0620e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/452778
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-11-22 22:01:52 +00:00
Bryan C. Mills 3b9d20c521 internal/gcimporter: in TestStdlib, only check x/tools packages if we expect to have their source
The go_android_exec and go_ios_exec wrappers (found in
GOROOT/misc/android and GOROOT/misc/ios, respectively) only copy over
the source code for the package under test, its parent directories,
and the 'testdata' subdirectories of those parents.

That does not necessarily include the transitive closure of
packages imported by those packages.

This may fix the failing tests on the android-amd64-emu builder on
release-branch.go1.19. (I do not understand why the test is not
already being skipped due to the call to testenv.NeedsGoPackages, but
I do not intend to investigate further.)

Change-Id: I6bd32fd7e7e9f56e85b2e03baae59da5d9ba0ed9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/451995
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-11-21 20:41:39 +00:00
Bryan C. Mills 932ec22a59 internal/testenv: add a Command function that replaces exec.Command
The function is derived from the testenv.Command function in the main
repo as of CL 446875, with a couple of modifications to allow it to
build (with more limited functionality) with Go versions as old as
1.16 (currently needed in order to test gopls with such versions).

testenv.Command sets up an exec.Cmd with more useful termination
behavior in the context of a test: namely, it is terminated with
SIGQUIT (to get a goroutine dump from the subprocess) shortly before
the test would otherwise time out.

Assuming that the test logs the output from the command appropriately,
this should make deadlocks and unexpectedly slow operations easier to
diagnose in the builders.

For golang/go#50014.
Updates golang/go#50436.

Change-Id: I872d4b24e63951bf9b7811189e672973d366fb78
Reviewed-on: https://go-review.googlesource.com/c/tools/+/377835
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-21 16:54:26 +00:00
Alan Donovan 2592a854ec gopls/internal/lsp: simplify KnownPackages
This change simplifies the two functions called KnownPackages,
and renames one of them.

The first, source.KnownPackages, is a standalone function
called in exactly one place: ListKnownPackages.
It has been renamed KnownPackagePaths to distinguish
from the other and to make clear that it returns only
metadata. Its implementation could be greatly simplified
in a follow-up, as noted. In the meantime, one obviously
wrong use of ImportSpec.Path.Value (a quoted string literal!)
as an package (not import!) path was fixed, and the package
name was obtained directly, not via CompiledGoFiles.

The second, Snapshot.KnownPackagePaths, is called from two places.
This CL eliminates one of them: stubMethods used it apparently
only to populate a field of missingInterface (pkg) that was unused.
The other call (from 'implementations') is something that should
eventually go away as we incrementalize; in any case it doesn't
rely on the undocumented ordering invariant established by the
implementation. This change removes the ordering invariant,
documents the lack of order, and removes the ordering logic.

Change-Id: Ia515a62c2d78276b3344f2880c22746b2c06ff64
Reviewed-on: https://go-review.googlesource.com/c/tools/+/451675
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-18 17:22:07 +00:00
Bryan C. Mills dea100b118 internal/testenv: skip tests that need export data for std if 'go tool compile' does not exist
Now that .a files are no longer being preinstalled for
standard-library packages (#47257), tests that require the export data
from those files must have access to 'go list -export' in order to
generate and load export data from the Go build cache.

`go list -export` does not work without a Go compiler, so assume that
tests that need the 'go' command also need the compiler.

This may cause the tests currently failing on the android-.*-emu
builders to instead be skipped, since the test harness does not copy
the compiler to the execution environment.

For golang/go#47257.

Change-Id: Ie82ab09ac8165a01fc1d3a083b1e86226efc469d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/451597
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-17 20:46:33 +00:00
Alan Donovan ce26db4201 go/analysis: add Pass.TypeErrors field
The result of type checking is a package (types.Package), type
annotations on syntax trees (types.Info), and zero or more type
errors (types.Error).  Hitherto we had assumed that analyzers don't
need access to type errors, but in fact it turns out to be useful:
for example, analyzers can look at broken code and suggest quick
fixes to repair the mistakes.

This change adds a Pass.TypeErrors field that holds the errors
produced during type checking. It may be non-nil only when the
Analyzer.RunDespiteErrors flag was enabled. Similarly, it adds
a TypeErrors field to go/packages.Package.
(The existing Packages.Error field loses important details.)

Gopls was already using analyzers in this way, (ab)using its privileged
position in the x/tools repo. This change removes the need for such hacks.

We expect that all analysis drivers that support RunDespiteErrors will
in due course populate the Pass.TypesErrors field. This change updates
the go/packages-based driver to do so; no changes were needed to
unitchecker since it does not support RunDespiteErrors.
In the meantime, not populating this field is not expected to cause
any compatibility problems.

Fixes golang/go#54619

Change-Id: Ia7c72242e332782e8919a4c30b2107c37bcec9ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/425095
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Tim King <taking@google.com>
2022-11-16 21:35:14 +00:00
David Chase 6e8da3febb internal/pkgbits: port small optimization from compiler to tools
Tools version of https://go.dev/cl/435336
I believe this helped the compiler (though I don't see the benchmark).
We probably need benchmarks for tools, too.

Change-Id: I3450ecb82fcef7050f28a4cffcbc224972680f36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/450678
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-11-15 20:28:31 +00:00
David Chase 06fb723d2f internal/gcimporter: port memory reuse optimizations from Go tree
original CL was https://go.dev/cl/433037
"cmd/compile: introduce "temporary" readers for more storage reuse"

Change-Id: I8989ae45b17a84451d29c7dc95b8ab2a06b6f153
Reviewed-on: https://go-review.googlesource.com/c/tools/+/449499
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: David Chase <drchase@google.com>
2022-11-15 20:27:34 +00:00
Florian Zenker fc702c522d internal/gcimporter: fix performance regression for unified IR
flattenImports used to traverse the transitive closure of all imports by
recursively visiting all imported packages. This is a lot of redundant
work, because flattening happens for every package, the recursion is not
necessary and this change removes the recursion.

Change-Id: Id5a1b3b15ef3ce8e0fc6c945b5484b3dd06bd6b6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/450755
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Florian Zenker <floriank@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-15 19:01:52 +00:00
Robert Findley d66e9b4ac8 internal/typesinternal: update go/types error codes for 1.20
Change-Id: I4b1d4a7769e90801856cfa15e860b899a3bf62dc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/449496
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-11-10 22:27:59 +00:00
Bryan C. Mills bd04e329ae internal/jsonrpc2_v2: eliminate a potential Accept/Dial race in TestIdleTimeout
The only explanation I can think of for the failure in
https://go.dev/issue/49387#issuecomment-1303979877 is that maybe the
idle timeout started as soon as conn1 was closed, without waiting for
conn2 to be closed. That might be possible if the connection returned
by Dial was still in the server's accept queue, but never actually
accepted.

To eliminate that possibility, we can send an RPC on that connection
and wait for a response, as we already do with conn1. Since the conn1
RPC succeeded, we know that the connection is non-idle, conn2 should
be accepted, and the request on conn2 should succeed unconditionally.

Fixes golang/go#49387 (hopefully for real this time).

Change-Id: Ie3e74f91d322223d82c000fdf1f3a0ed08afd20d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448096
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-11-09 14:00:02 +00:00
Bryan C. Mills d41a43b94f internal/jsonrpc2_v2: fix a potential deadlock when (*Conn).Close is invoked during Bind
This fixes the goroutine leak reported in
https://build.golang.org/log/ae36d36843ca240e9e080886417a8798dd4c9618.

Fixes golang/go#46047 (hopefully for real this time).

Change-Id: I360e54d819849a35284c61d3a0655cc175d81f77
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448095
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-09 13:57:32 +00:00
Robert Findley ba92ae1711 internal/persistent: avoid incorrect map validation due to multiple keys
Fix the test failure demonstrated in the following failed builder:
https://build.golang.org/log/d0511c583201e8701e72066985ebf950d9f5511d

It should be OK to set multiple keys in the validated map. Support this
by keeping track of seen and deletion clock time. There are still
potential problems with this analysis (specifically, if a map is
constructed via SetAll), but we ignore those problems for now.

Change-Id: I5940d25f18afe31e13bc71f74d4eea7d737d593d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448696
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-08 21:01:57 +00:00
Alan Donovan 003fde144e internal/gcimporter: use nondeprecated go/packages mode bits
I meant to do this in the first CL, but was prevented by
a bug which I have since reported and linked to from the code.

Change-Id: I651e728c535cdeb0885eae4d510fda3c24518dcf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448376
Auto-Submit: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-07 21:25:05 +00:00
Alan Donovan 3c8152e28a internal/gcimporter: optimize dependency lookup
The old code based on packages.Visit traversed in a
deterministic order, and didn't stop when it found its
target (the 'return false' only prunes that subtree).
This CL replaces it with a precomputation of the
PkgPath-to-*Package mapping.

The performance difference is small for this test but
it nearly dominates on a larger input (e.g. k8s).
Example code shouldn't steer users into asymptotic traps.

Change-Id: I19f4fc2c25da3d2ae00090704df30a54d8516bf5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447958
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-05 17:57:31 +00:00
Alan Donovan 2b29c66d7e internal/gcimporter: API for shallow export data
This change adds an internal API for marshalling and
unmarshalling a types.Package to "shallow" export data,
which does not index packages other than the main one.
The import function accepts a function that loads symbols
on demand (e.g. by recursively reading export data for
indirect dependencies).

The CL includes a test that the entire standard
library can be type-checked using shallow data.

Also:
- break dependency on go/ast.
- narrow the name and type of qualifiedObject.
- add (test) dependency on errgroup, and tidy go.mod.

Change-Id: I92d31efd343cf5dd6fca6d7b918a23749e2d1e83
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447737
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-04 16:27:25 +00:00
Alan Donovan affa603132 internal/gcimporter: moved from go/internal/gcimporter
We plan to add experimental features to this package for
use by gopls, but the directory structure makes this
tricky using the "internal directory" mechanism.

Change-Id: Ib842c0b100b167f6978c6ff783ea0e5d0704b4a7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447955
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-04 15:23:56 +00:00
Robert Findley d5e9e3592c go/analysis/passes/loopclosure: enable analysis of parallel subtests
Remove the internal guard preventing the loopclosure analyzer from
checking parallel subtests.

Also, improve the accuracy of the parallel subtest check:
 - only consider statements after the final labeled statement in the
   subtest body
 - verify that the *testing.T value for which T.Parallel() is invoked
   matches the argument to the subtest literal

Fixes golang/go#55972

Change-Id: Ia2d9e08dfa88b5e31a9151872025272560d4b5e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447256
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-11-03 17:48:16 +00:00
Bryan C. Mills 039b24b625 internal/jsonrpc2_v2: initiate shutdown when the Writer breaks
Prior to this CL we already shut down a jsonrpc2_v2.Conn when its
Reader breaks, which we expect to be the common shutdown path.
However, with certain kinds of connections (notably those over
stdin+stdout), it is possible for the Writer side to fail while
the Reader remains working.

If the Writer has failed, we have no way to return the required
Response messages for incoming calls, nor to write new Request
messages of our own. Since we have no way to return a response,
we will now mark those incoming calls as canceled.

However, even if the Writer has failed we may still be able to read
the responses for any outgoing calls that are already in flight. When
our in-flight calls complete, we could in theory even continue to
process Notification messages from the Reader; however, those are
unlikely to be useful with half the connection broken. It seems more
helpful — and less surprising — to go ahead and shut down the
connection completely when it becomes idle.

This is a redo of CL 446315, with additional fixes for bugs exposed on
the -race builders and some extra code cleanup from the process of
diagnosing those bugs.

Updates golang/go#46520.
Updates golang/go#49387.

Change-Id: I746409a7aa2c22d5651448ed0135b5ac21a9808e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447035
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-11-02 21:32:11 +00:00
Bryan C. Mills 73fcd88827 Revert "internal/jsonrpc2_v2: initiate shutdown when the Writer breaks"
This reverts CL 446315 due to yet-undiagnosed bugs exposed on the
-race builders.

Fixes golang/go#56510.

Change-Id: I41084359b74580f65cc82db0a174194bd2102ff1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446859
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-11-01 16:02:58 +00:00
Bryan C. Mills 3e8da475a3 internal/jsonrpc2_v2: initiate shutdown when the Writer breaks
Prior to this CL we already shut down a jsonrpc2_v2.Conn when its
Reader breaks, which we expect to be the common shutdown path.
However, with certain kinds of connections (notably those over
stdin+stdout), it is possible for the Writer side to fail while
the Reader remains working.

If the Writer has failed, we have no way to return the required
Response messages for incoming calls, nor to write new Request
messages of our own. Since we have no way to return a response,
we will now mark those incoming calls as canceled.

However, even if the Writer has failed we may still be able to read
the responses for any outgoing calls that are already in flight. When
our in-flight calls complete, we could in theory even continue to
process Notification messages from the Reader; however, those are
unlikely to be useful with half the connection broken. It seems more
helpful — and less surprising — to go ahead and shut down the
connection completely when it becomes idle.

Updates golang/go#46520.
Updates golang/go#49387.

Change-Id: I713f172ca7031f4211da321560fe7eae57960a48
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446315
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-10-31 20:24:21 +00:00
Bryan C. Mills 7cdb0e7352 internal/jsonrpc2_v2: rename Serve to NewServer and eliminate its error return
Serve had a misleading name and signature: it did not actually block
on serving the connection, and never returned a non-nil error.

Updates golang/go#56281.

Change-Id: Ia6df0ba20066811b0551df3b3267dff2fffd7881
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443678
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-10-31 15:32:39 +00:00
Bryan C. Mills 28e9e509a6 internal/jsonrpc2_v2: eliminate error return from Bind
Also make (*Connection).Close safe to call from Bind.

A jsonrpc2_v2.Server has no good way to report an error from Bind.

If the Server saves the error to return from its own Wait method, that
might not ever actually happen: Wait waits for in-flight connections
to complete, but if some existing connection stays up then Wait will
not return.

If the Server goes ahead with establishing the connection and installs
its own Handler, that Handler needs to decide whether to serve the
error from Bind or something more opaque, and at that point Bind may
as well return a handler that makes that choice more precisely.

If the Server merely logs the error and closes the Connection, then
the Bind method itself may as well do that directly too.

It seems to me that the only winning move is not to play. Only Bind is
in a position to decide how to handle its errors appropriately, so it
should not return them to the Server.

Updates golang/go#56281.

Change-Id: I07dc43ddf31253ce23da21a92d2b6c0f8d4b3afe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443677
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-31 15:32:37 +00:00
Bryan C. Mills eabc3a08b7 internal/jsonrpc2_v2: eliminate isClosingErr
Also implement and use the Shutdown method, which was mentioned in a
doc comment in CL 292169 but not actually present at that time.

With proper synchronization, we don't need heuristics to determine
whether an error is due to a connection or listener being closed.
We know whether we have called Close (and why), and we can assume
that if we have called Close then that is probably the reason for
any returned error.

Fixes golang/go#56281.

Change-Id: I5e0ed7db0f736ca8df8cd8cf556b674e7a863a69
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443675
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-10-31 15:32:17 +00:00
Bryan C. Mills 4885f7c90f internal/jsonrpc2_v2: eliminate a temporary connection leak in (*Server).run
Prior to this CL, (*Server).run only filters out inactive connections
when it accepts a new connection. If existing connections complete,
their associated resources can't be garbage-collected until either the
next connection is accepted or the Listener is closed.

This change moves the open-connection accounting to an explicit hook
passed to newConnection, eliminating the need to call Wait entirely.

For golang/go#46047

Change-Id: I3732cb463fcea0c142f17f2b1510fdfd2dbc81da
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388774
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-31 15:32:14 +00:00
Bryan C. Mills 739f55d751 internal/jsonrpc2_v2: rework Connection concurrency
This change fixes the semantics of Close to actually wait for
in-flight requests before closing the ReadWriteCloser. (Previously,
the Close method closed the ReadWriteCloser immediately, which I
suspect is what led to many of the failures observed in
golang/go#49387 and golang/go#46520.)

It achieves this by explicitly tracking the number of in-flight
requests, including requests with pending async responses, and
explicitly rejecting new Call requests (while keeping the read loop
open!) once Close has begun.

To make it easier for me to reason about the request lifetimes, I
reduced the number of long-lived goroutines from three to just one
(the Read loop), with an additional Handler goroutine that runs only
while the Handler queue is non-empty. Now, it is clearer (I hope!)
that the number of in-flight async requests strictly decreases
after Close has begun, even though the Read goroutine continues
to read requests (and, importantly, responses) and to forward
Notifications to the preempter.

For golang/go#49387
For golang/go#46520

Change-Id: Idf5960f848108a7ced78c5382099c8692e9b181e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388134
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-10-31 15:02:00 +00:00
Michael Matloob e4bb34383f go/internal/gcimporter: update to anticipate missing targets and .as
This cl updates go/internal/gcimporter the to anticiapte missing
targets and .a files the same way CL 442303 updates the two other
versions of gcimporter to do the same. It also adds a couple of
helpers to create importcfg files for the compiler and list the
locations of cached stdlib .a files in internal/goroot and
internal/testenv, the analogues of their import paths in the go
distribution.

Change-Id: Ie207882c13df0e886a51d31e7957a1e508331f10
Reviewed-on: https://go-review.googlesource.com/c/tools/+/445455
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2022-10-26 20:17:01 +00:00
Alan Donovan d6511e5e9f internal/facts: share go/analysis/internal/facts with gopls
This change moves the facts package so that it can be reused by gopls.
It remains a tools-internal API.

A forthcoming reimplementation of gopls's analysis driver will
make use of the new packages and the features mentioned below.

Also:
- change parameter of read() callback from 'path string' to *Package.
- use NewDecoder().Decode() to amortize import-map computation across calls.

Change-Id: Id10cd02c0c241353524d568d5299d81457f571f8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444796
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
2022-10-25 15:31:58 +00:00
Peter Weinberger d67c3ada09 internal/imports: repair warnings from default analyzers
Some of the analyzers that are on by default in gopls produce many distracting
warnings. These are 'composites' and 'simplifycompositelit'.

This CL changes code to remove the 160 or so warnings.

An alternative would be to remove these from the default set of gopls analyzers.

Change-Id: Id5724a5aef260939dedd21a37e28f3d05bfa023d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443635
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-19 15:24:07 +00:00
Bryan C. Mills bc2e3aeaba internal/jsonrpc2_v2: add Func convenience wrappers for the Binder and Preempter interfaces
Change-Id: Ib21dabb908c13d9bbf50f053a342a8644d3ee68b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388596
Run-TryBot: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-10-18 21:38:33 +00:00
Bryan C. Mills b2efd4d155 internal/jsonrpc2_v2: eliminate most arbitrary timeouts in tests
For golang/go#46047
For golang/go#49387
For golang/go#46520

Change-Id: Ib72863a024d74f45c70a6cb53482cb606510f7e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388598
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-10-17 20:15:06 +00:00
Bryan C. Mills 371ef162f2 internal/jsonrpc2_v2: rework concurrency in idleListener
This eliminates a race between a successful Accept call and a
concurrent Close call, which previously could have shut down the
'run' goroutine before Accept sent to the newConns channel, causing
Accept to deadlock.

In fact, it eliminates the long-running 'run' goroutine entirely
(replacing it with a time.Timer), and in the process avoids leaking
O(N) closed connections when only the very first one is long-lived.

It also eliminates a potential double-Close bug: if the run method had
called l.wrapped.Close due to an idle timeout, a subsequent call to
Close would invoke l.wrapped.Close again. The io.Closer method
explicitly documents doubled Close calls as undefined behavior, and
many Closer implementations (especially test fakes) panic or deadlock
in that case.

It also eliminates a timer leak if the Listener rapidly oscillates
between active and idle: previously the implementation used
time.After, but it now uses an explicit time.Timer which can be
stopped (and garbage-collected) when the listener becomes active.

Idleness is now tracked based on the connection's Close method rather
than Read: we have no guarantee in general that a caller will ever
actually invoke Read (if, for example, they Close the connection as
soon as it is dialed), but we can reasonably expect a caller to at
least try to ensure that Close is always called.

We now also verify, using a finalizer on a best-effort basis, that the
Close method on each connection is called. We use the finalizer to
verify the Close call — rather than to close the connection implicitly
— because closing the connection in a finalizer would delay the start
of the idle timer by an arbitrary and unbounded duration after the
last connection is actually no longer in use.

Fixes golang/go#46047.
Fixes golang/go#51435.
For golang/go#46520.
For golang/go#49387.

Change-Id: If173a3ed7a44aff14734b72c8340122e8d020f26
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388597
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-17 20:15:04 +00:00
Bryan C. Mills 5935531253 internal/jsonrpc2_v2: remove “Box” suffix from channel field names
With the suffixes I end up a little lost in the “box” noise while I'm
reading — the channel ops alone suffice to make the storage mechanism
clear.

(To me, the mechanism of storing a value in a 1-buffered channel is
conceptually similar to storing it in a pointer, atomic.Pointer, or
similar — and we don't generally name those with a suffix either.)

For golang/go#46047.
For golang/go#46520.
For golang/go#49387.

Change-Id: I7f58a9ac532f597fe49ed70606d89bd8cbe33b55
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443355
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-17 20:13:30 +00:00
Bryan C. Mills fd32990e09 internal/jsonrpc2_v2: error out in-flight client calls when the reader breaks
Otherwise, the Await method on the corresponding AsyncCall will never
unblock, leading to a deadlock (detected by the test changes in
CL 388597).

For golang/go#46047
For golang/go#46520
For golang/go#49387

Change-Id: I7954f80786059772ddd7f8c98d8752d56d074919
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388775
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-17 19:48:19 +00:00
Bryan C. Mills 0e222f5c6f internal/jsonrpc2_v2: close the underlying connection if Wait is called instead of Close
(*Server).run calls Wait on all of its connections before returning,
but does not call Close explicitly. If Close is necessary to
release resources (as is often the case for a net.Conn),
the server ends up leaking resources.

For golang/go#46047

Change-Id: I4ad048c4f5e5d3f14f992eee6388acd42398c26b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388599
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-10-17 19:48:17 +00:00
Charlie Vieth f87c1ed972 internal/fastwalk: improve Darwin performance by ~3x
On darwin/cgo use readdir_r instead of syscall.ReadDirent() since the
later is simulated and slow (see: golang/go#30933).

Unlike CL 392094, this uses CGO instead of "//go:linkname" and assembly.

goos: darwin
goarch: arm64

FastWalk-10    68.9ms ±11%    20.7ms ± 2%  -69.89%  (p=0.008 n=5+5)

name         old alloc/op   new alloc/op   delta
FastWalk-10    1.49MB ± 0%    1.51MB ± 0%   +1.06%  (p=0.008 n=5+5)

name         old allocs/op  new allocs/op  delta
FastWalk-10     32.2k ± 0%     30.7k ± 0%   -4.61%  (p=0.016 n=5+4)

Fixes golang/go#51356

Change-Id: Ia3afd06c8f14bd2036b2a1ea6e3cafbef81d3530
Reviewed-on: https://go-review.googlesource.com/c/tools/+/436780
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-13 16:31:57 +00:00
Alan Donovan 29429f53af gopls/internal/lsp/source: sort protocol edits
The LSP protocol doesn't require edits to be sorted,
but some clients such as govim were relying on it,
as we learned when I recently removed the sort.
This change restores the sort behavior.

See also govim/govim#1171

Change-Id: I589b6cfde933ea6907859bf40acd33c1a7fcde02
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442256
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2022-10-11 18:07:12 +00:00
Robert Findley 150b5f8bb6 internal/imports: read entire API dir in mkstdlib.go
Read the entire API directory, so that we don't need to edit mkstdlib.go
when regenerating zstdlib.go for new go versions.

Joint with Dylan Le.

Co-Authored-By: dle8@u.rochester.edu.
Change-Id: If5c71bfcfd2104f923df10cf21d16b5280fed025
Reviewed-on: https://go-review.googlesource.com/c/tools/+/438504
Reviewed-by: Dylan Le <dungtuanle@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-10-10 18:26:39 +00:00
cui fliter f90d8ad46c all: fix a few function names on comments
Change-Id: I91eec68ebd9394685a6586c8d0cf01ecf3fd82e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441775
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-10-10 13:22:38 +00:00
Alan Donovan a410e98a82 internal/diff: ToUnified may fail
LineEdits has similar consistency preconditions to ApplyEdits.
Previously they were assumed, and bad input would create bad
output or crashes; now it uses the same validation logic
as ApplyEdits. Since it reports an error, computation of a
unified diff can also fail if the edits are inconsistent.

The ToUnified([]Edit) function now returns an error. For
convenience we also provide a wrapper (Unified) that cannot
fail since it calls Strings and ToUnified consistently.

LineEdits itself is now private.

Change-Id: I3780827f501d7d5c9665ec8be5656331c0dcda8e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/440175
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2022-10-07 15:16:55 +00:00
Alan Donovan 26a95e6901 gopls/internal/span: move internal/span into gopls
Spans are logically part of gopls, but could not be moved
into the gopls module because of a number of depenencies
from packagestest, analysis, and internal/diff.
Those edges are now broken.

Change-Id: Icba5ebec6b27974f832a1186120a4b87d5f87103
Reviewed-on: https://go-review.googlesource.com/c/tools/+/440176
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-07 14:50:44 +00:00
Alan Donovan f2c4579afe internal/diff: avoid unnecessary allocations
Previously, a diff of non-ASCII strings would incur
three complete copies of the buffers; this changes
reduces it to one.

Also:
- add diff.Bytes function, to avoid unnecessary conversions.
- remove unused diff.Lines and LineEdits functions from API.
- remove TODO to use []bytes everywhere.
  We tried it in CL 439277 and didn't like it.
- Document that the diff is textual, even when given []byte.

Change-Id: I2da3257cc3d12c569218a2d7ce182452e8647a96
Reviewed-on: https://go-review.googlesource.com/c/tools/+/439835
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-07 14:48:35 +00:00
Alan Donovan 60ddccae85 internal/diff: Apply: validate inputs
Apply now checks that its edits are valid
(not out of bounds or overlapping),
and reports an error if not.

It also sorts them, if necessary, using (start, end)
as the key, to ensure that insertions (end=start)
are ordered before deletions at the same point
(but without changing the relative order of insertions).

Two other implementations of the diff.Apply algorithm
have been eliminated. (One of them failed to sort edits,
requiring the protocol sender to do so; that burden
is now gone.)

Change-Id: Ia76e485e6869db4a165835c3312fd14bc7d43db2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/439278
Auto-Submit: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
2022-10-07 14:24:20 +00:00
Alan Donovan 02bef08ac8 go/packages/packagestest: break dependency on gopls' span package
The span package is properly part of gopls, and we'd like to move
it into that module. However, the packagestest package unfortunately
depends on span.Span as an alternative notation for Ranges.

This change decouples span.Span from packagestest.Range using a
new (unexported for now) rangeSetter interface, which Span implements.
Neither package depends on the other.

Technically this is a breaking API change:
all the Range methods have gone away, as have the Span, URI,
and Point types and their methods, which were accessible via
Range.Span(). However, clients would not be able to access
these internal types, and I think it is highly unlikely that
anyone depends on it. Nonethless this is a cautionary tale about
the risks from one innocuous-looking type alias declaration.

Change-Id: I8acb03f4acb1f798f304b03648445e37a44f9c45
Reviewed-on: https://go-review.googlesource.com/c/tools/+/439715
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-10-07 14:18:09 +00:00
cui fliter bd8c28ff5c internal/diff/lcs: fix shell format error
Change-Id: Id333dd169c7b7a54823bd077ce677fc74b4eb057
GitHub-Last-Rev: f16abccaad
GitHub-Pull-Request: golang/tools#397
Reviewed-on: https://go-review.googlesource.com/c/tools/+/431136
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-10-06 14:25:42 +00:00
Alan Donovan d96b2388c6 internal/diff: simplify API, break span dependency
diff.TextEdit (now called simply Edit) no longer has a Span,
and no longer depends on the span package, which is really
part of gopls. Instead, it records only start/end byte
offsets within an (implied) file.

The diff algorithms have been simplified to avoid the need to
map offsets to line/column numbers (e.g. using a token.File).
All the conditions actually needed by the logic can be derived
by local string operations on the source text.

This change will allow us to move the span package into the
gopls module.

I was expecting that gopls would want to define its own
Span-augmented TextEdit type but, surprisingly, diff.Edit
is quite convenient to use throughout the entire repo:
in all places in gopls that manipulate Edits, the implied
file is obvious. In most cases, less conversion boilerplate
is required than before.

API Notes:
- diff.TextEdit -> Edit (it needn't be text)
- diff.ApplyEdits -> Apply
- source.protocolEditsFromSource is now private

Change-Id: I4d7cef078dfbd189b4aef477f845db320af6c5f6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/436781
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>
Auto-Submit: Alan Donovan <adonovan@google.com>
2022-10-05 20:32:15 +00:00
Alan Donovan 9856077059 internal/diff: abolish errors
Computing the difference between two strings is logically an
infallible operation. This change makes the code reflect that. The
actual failures were unreachable given consistent inputs, but that was
hard to see from the complexity of the logic surrounding span.Span.
(The problem only occurs when converting offsets beyond the end of the
file to Spans, but the code preserves the integrity of offsets.)

gopls' "old" hooks.ComputeEdits impl (based on sergi/go-diff) now
reports a bug and returns a single diff for the entire file if it
panics.

Also, first steps towards simpler API and a
reusable diff package in x/tools:

- add TODO for new API. In particular, the diff package shouldn't care
  about filenames, spans, and URIs. These are gopls concerns.
- diff.String is the main diff function.
- diff.Unified prints edits in unified form;
  all its internals are now hidden.
- the ComputeEdits func type is moved to gopls (source.DiffFunction)
- remove all non-critical uses of myers.ComputeEdits. The only
  remaining one is in gopls' defaults, but perhaps that gets
  overridden by the default GoDiff setting in hooks, to BothDiffs
  (sergi + pjw impls), so maybe it's now actually unused in practice?

Change-Id: I6ceb5c670897abbf285b243530a7372dfa41edf6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/436778
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-05 20:30:46 +00:00
Alan Donovan 55e5cff611 internal/diff: unified: match GNU diff for empty file
GNU diff -u prints -0,0 for the special case of inserting
into an empty file. (I don't understand why this case is
special, but it's fair to assume it has been debugged;
perhaps patch(1) has a bug.)

This change matches that special behavior, and adds a test.
It also adds a (disabled) test for another bug I encountered.

Also, remove some overzealous uses of t.Helper() that served
to obscure the failure.

Change-Id: I3e0c389c478cde45163353130e36f2f8741a8659
Reviewed-on: https://go-review.googlesource.com/c/tools/+/436782
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
2022-10-03 15:32:10 +00:00
Alan Donovan 3e0355b898 gopls/.../fillstruct: support generic types
The code that generates a name for a struct type,
and a default value for a struct field, now
supports the case where either contains a type
parameter.

Also:
- use type-checker's name for the struct type unless
  it is a bare struct.
- populateValue: return *new(T) for a type parameter.
- various minor cleanups.
- various TODO comments for clarifications.
- fuzzy.FindBestMatch: use strings not identifiers.
  Remove Find prefix (also FindMatchingIdentifiers).

Fixes golang/go#54836

Change-Id: I4f6132598b4ac7e72ea1405e4a14d6a23c1eeeaa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/436777
Auto-Submit: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-30 19:58:05 +00:00
Alan Donovan 4dd4ddb972 go/packages: issue error if 'go list' on PATH is too new
An application that links in version 1.18 of (say)
go/types cannot process Go source files reported
by version 1.19 of 'go list'. There is no way to
tell go list to behave as if it was go1.18, so
for now we proceed with parsing/typechecking but,
in case of errors, we issue an additional informative
diagnostic.

Fixes golang/go#55883
Fixes golang/go#55045
Updates golang/go#50825
Updates golang/go#52078

Change-Id: I5fd99b09742c136f4db7f71d2a75e4cdb730460d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/435356
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
2022-09-28 14:34:08 +00:00
Alan Donovan 5214f412ae internal/gocommand: show pid of process
We're almost certain that the go process shown by ps
is not the one that we're waiting for in runCmdContext,
but only by printing the pid can we be sure.

Updates golang/go#54461

Change-Id: I1ce9580de6ee6bc4557d76c2a6b05f5a3e2eb6c2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/434637
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-09-26 20:21:32 +00:00
Robert Findley 14462efca9 go/analysis/passes/loopclosure: experiment with checking t.Run+Parallel
Add experimental new logic to the loopclosure analyzer that checks for
access to loop variables from parallel subtests. For now, this is gated
behind an internal variable so that we may experiment with it without
yet affecting cmd/vet.

Add an internal/loopclosure command that enables the experimental new
check.

Change-Id: Ibf7e388a58a2b3e712e66e095d06612cf3ea918c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/430916
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-09-20 22:09:32 +00:00
cui fliter 0e011a0e6c all: use constant to avoid repeated definitions
Change-Id: I9e0a167cc3a9772412f3ec809eeb4720ae331c98
GitHub-Last-Rev: 4a909d88f4
GitHub-Pull-Request: golang/tools#398
Reviewed-on: https://go-review.googlesource.com/c/tools/+/431637
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-09-19 15:32:23 +00:00
Robert Findley a61f20e1aa internal/gocommand: tweak debugging for hanging go commands
Add a TODO and wait for a shorter period of time following Kill, per
post-submit advice from bcmills on CL 424075.

For golang/go#54461

Change-Id: Ia0e388c0119660844dad32629ebca4f122fded12
Reviewed-on: https://go-review.googlesource.com/c/tools/+/431075
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-09-15 19:41:03 +00:00
Robert Findley 0398b3de2b internal/gocommand: add instrumentation for hanging go commands
When a go command hangs during gopls regression tests, print out
additional information about processes and file descriptors.

For golang/go#54461

Change-Id: I92aa4665e9056d15a274c154fce2783bed79718e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/424075
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-15 14:14:04 +00:00
cui fliter 5f27e05096 all: remove redundant type conversion
Change-Id: Iffb04ebd6b4afbe1a13b96b7e7469ec3b3e3380f
GitHub-Last-Rev: 6682724eb7
GitHub-Pull-Request: golang/tools#396
Reviewed-on: https://go-review.googlesource.com/c/tools/+/428980
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-09-07 17:33:19 +00:00
Robert Findley b15dac2b88 gopls: migrate internal/lsp to gopls/internal/lsp
This CL was created using the following commands:

    ./gopls/internal/migrate.sh
    git add .
    git codereview gofmt

For golang/go#54509

Change-Id: Iceeec602748a5e6f609c3ceda8d19157e5c94009
Reviewed-on: https://go-review.googlesource.com/c/tools/+/426796
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-07 16:44:44 +00:00
Peter Weinberger 83d76192b2 gopls : add a mention of staticcheck to settings documentation
Fixes golang/go#52874

Change-Id: I04664154d68e31f48234c13aefe8470b09f0413e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/428595
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-09-06 14:55:05 +00:00
Dylan Le d815cba582 internal/lsp: update LSP protocol for WorkspaceEdit
Change DocumentChanges field type from []TextDocumentEdit to []DocumentChanges. DocumentChanges is a union type of TextDocumentEdit and RenameFile used for renaming package feature. It distinguishes a renaming directory ops from a text document edit ops.

For golang/go#41567

Change-Id: I25d106b34821effc53b712800f7175248e59ee25
Reviewed-on: https://go-review.googlesource.com/c/tools/+/427538
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Dylan Le <dungtuanle@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-02 19:58:35 +00:00
Robert Griesemer 6a585a2bf9 x/tools/internal/typeparams: use regexp to match wanted result
CL 410955 changes printing of unions which breaks two typeparams tests.
Use regexp matching and adjust the wanted results accordingly.

For golang/go#53279.
For golang/go#54822.

Change-Id: I7060df47d36ce3069570237dafff024aaad637a5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/428055
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
2022-09-02 19:06:05 +00:00
Robert Griesemer 5ba85415fa x/tools/internal/lsp/source: disable some tests for std lib changes
CL 410955 changes printing of unions which breaks a few lsp tests.
Disable them for now so we can submit CL 410955.

For golang/go#53279.
For golang/go#54822.

Change-Id: I54ff99a4f5530181a39557b6b62e776af082c28d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/428054
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
2022-09-02 18:17:25 +00:00
Robert Griesemer 40cfafff02 x/tools/internal/lsp/source: disable some tests for std lib changes
CL 425716 changes parser behavior for incorrect code (it is more
lenient) which breaks a few lsp tests. Disable them for now so we
can submit CL 425716.

For golang/go#54511.
For golang/go#54822.

Change-Id: I00fa67e29628137f3e4e44c38e92094ea581a61b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/427654
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-09-01 22:03:33 +00:00
Brian Pursley f16be35d92 internal/lsp/source: add functions to type hover output
Add functions to the output when hovering over a type.

Fixes golang/go#54008

Change-Id: Ia0a7b5a878c3d63c4bbc549f003c45592db1c135
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420714
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-01 17:52:14 +00:00
Robert Findley dfc8d49339 internal/lsp/testdata: fix diagnostics checksum
Fix an incorrect diagnostics checksum causing builder failures.

Change-Id: Ief4f9edd6acbf8d42eaf1109ec6ddc0085f20b05
Reviewed-on: https://go-review.googlesource.com/c/tools/+/427536
Auto-Submit: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Dylan Le <dungtuanle@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2022-09-01 17:30:47 +00:00
Alan Donovan 6c10975b72 internal/lsp/cache: honor RunDespiteErrors=false
This change prevents analysis from running on a package containing
any kind of error unless the analyzer has indicated that it is robust.
This is presumed to be the cause of several panics in production.

And a test.

Updates golang/go#54762

Change-Id: I9327e18ef8d7773c943ea45fc786991188358131
Reviewed-on: https://go-review.googlesource.com/c/tools/+/426803
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-09-01 15:27:30 +00:00
Robert Griesemer 49ab44de90 x/tools/internal/lsp: re-enable a test with adjusted error message
This is a follow-up on CL 425497. Must be submitted after CL 425007.

For golang/go#54511.

Change-Id: Ice9c1c62b911efa8efa20ea295bf313aabe8c5bb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/425594
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-09-01 03:24:42 +00:00
Robert Findley 550e1f5a55 internal/lsp/tests: use a shorter module path for test data
While moving internal/lsp to gopls/internal/lsp, we discovered that
we're bumping up against a command line length limit on windows. Use an
arbitrary shorter module path to avoid this, for now.

Updates golang/go#54800
Updates golang/go#54509

Change-Id: I7be07da29a769c1ce7c31cbbd374ca47b0944132
Reviewed-on: https://go-review.googlesource.com/c/tools/+/426801
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-31 21:10:26 +00:00
Robert Findley 4ccc73cbb5 internal/lsp/tests: simplify comparison of markdown at go1.18
In several places throughout the x/tools codebase, the internal/lsp/diff
package is used to provide clearer test output when comparing large,
multi-line strings. In some places, this is implemented via the
tests.Diff helper function, but in others it is not (presumably due to
import cycles).

Factor out this pattern into a diff.Pretty function, and add commentary.
Also remove the *testing.T argument, as diffs should never fail; opt to
panic instead. Also add a test.

Using this function, simplify the logic to comparing our 1.18 markdown
output with 1.19 golden content, by normalizing differences between the
two.

This is necessary as markdown content will change as a result of moving
internal/lsp to gopls/internal/lsp.

For golang/go#54509

Change-Id: Ie1fea1091bbbeb49e00c4efa7e02707cafa415cc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/426776
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-08-31 21:08:24 +00:00