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>
-i has been deprecated since 1.15, and is now gone in the soon-to-be-1.20.
Change-Id: Ib570f2bcfd0b1feb937990b72e4c9e43e1ada8cd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443456
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
This reverts commit 9b5e55b1a7.
Reason for revert: Should have been fixed by https://go.dev/cl/443100
Change-Id: I44eeff6605697b745c3729ac1ec49b9c09114f71
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443340
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>
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.
Fixesgolang/go#46047.
Fixesgolang/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>
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>
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>
(*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>
Since we removed the 'recover' in analysis, which swept crash
bugs under the rug, we've seen a large number of crashes on
the builders in which an analyzer crashes while trying
to use the result of another analyzer (e.g. the inspector)
on the same package. Logging shows that the "same" package
is in fact a stale version of the same package.
The root cause is that the key for the analysis cache
is the analyzer name paired with the "recipe" for the
package. However, analysis is not content with an equivalent
package: identity matters for ast.Nodes, types.Objects, etc.
This change attemps to fix the problem by, in effect, using
the identity (not the recipe) of the package as part of the key.
It is materialized by adding a store of promises to the pkg,
and then using the analysis name as the key within this store.
Change-Id: I057807d2781492a685f27c815250c3445e7475f9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443100
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>
Unlike other calls of qualified functions, the type of certain functions
in the unsafe package (namely Slice, Add) is not constant, and cannot be
determined by the types.Func being called. Update Finder.expr to
pre-emptively handle calls to functions in the unsafe package, similarly
to how it handles other builtins.
Fixesgolang/go#56227
Change-Id: I7af51c1ecacbdf35e39c8e7b8273ffe6f953427f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443096
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
We now understand the longstanding race causing panics in gopls analysis
(the cache key for analysis handles is not correct, and can lead to
cache hits for analysis of stale packages).
It will take a little while to redesign our analysis caching, the
simplest solution being to hang analysis results off of the actual
package they are analyzing. In the meantime, suppress the panic as
before, to eliminate flakes.
For golang/go#55201
For golang/go#56035
Change-Id: I96600f186f9f31b67dae10c0a95a14fa73630571
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442794
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>
This change moves the *pkg out of the actionHandle into
the actionResult. (In future we may not need to load the
package before creating the handle.) The actionResult
retains only the exported type information, to avoid keeping
the syntax trees (etc) live.
Also, perform object fact filtering once after the analysis pass,
instead of every time it is imported by another analysis.
Also, filter out unexported constants.
Also, log internal errors even when we don't bug.Reportf,
since errors merely returned by analysis are usually ignored,
making it harder to understand the analysis crashes.
Change-Id: I7257e8da5dc269090bff2817409948e46dcf7176
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442556
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
A stray print statement was accidentally left in CL 441877. Remove it.
Change-Id: I44e4408059f30d35ad8c84b070aea3e197762d1c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442782
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
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)
Fixesgolang/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>
Add support in gopls for working on "standalone main files", which are
Go source files that should be treated as standalone packages.
Standalone files are identified by a specific build tag, which may be
configured via the new standaloneTags setting. For example, it is common
to use the directive "//go:build ignore" to colocate standalone files
with other package files.
Specifically,
- add a new loadScope interface for use in snapshot.load, to add a bit
of type safety
- add a new standaloneTags setting to allow configuring the set of build
constraints that define standalone main files
- add an isStandaloneFile function that detects standalone files based
on build constraints
- implement the loading of standalone files, by querying go/packages for
the standalone file path
- rewrite getOrLoadIDsForURI, which had inconsistent behavior with
respect to error handling and the experimentalUseInvalidMetadata
setting
- update the WorkspaceSymbols handler to properly format
command-line-arguments packages
- add regression tests for LSP behavior with standalone files, and for
dynamic configuration of standalone files
Fixesgolang/go#49657
Change-Id: I7b79257a984a87b67e476c32dec3c122f9bbc636
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441877
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>
This change eliminates these redundant helper functions
- cache.rangeFromPositions
- source.LineToRange
- source.ByteOffsetsToRange
and makes various other simplifications and documentation
improvements.
Change-Id: Ic820ab560d71b88bde00b005e3a919334a5d1856
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442015
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>
Make sure we aren't sending multiple code actions
that do the same thing. This also adds a upgrade
to latest code action.
Change-Id: Ic9cecd0a9410648673d4afe63da5a940960a4afc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/436776
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Separate command into a separate line in order to make it easier to copy and paste into the terminal
Change-Id: I2e446475201c40ddb5054fe403ff23ed79b0742e
GitHub-Last-Rev: bbd650aa12415725168b59ec934aafeeaf0f21aa
GitHub-Pull-Request: golang/tools#346
Reviewed-on: https://go-review.googlesource.com/c/tools/+/361394
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Changes `ssadump -run` to ensure that the package runtime
is not imported (changed from must be imported). For several
years, the runtime package has used unsafe constructs
x/tools/go/ssa/interp cannot interpret. This must have been
failing a similar amount of time.
This is unfortunate, but is unlikely to be addressed soon.
For golang/go#43163
Change-Id: I9e2aee640ff7b1123e591e6c49cac9967c5e8da8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441817
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
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>
golang.org/cl/437298 updates go list to not exit with a non-zero
error code in some cases and instead place the error on the Package
struct. Also, as a cleanup, some places where exit status 2 was returned
will return exit status 1 (bringing it in line with other errors
returned by the go command).
TestEncodeDecode in facts_test.go has been updated to fix a missing
function body that is not relevant to the test, but that was causing an
error because the Package struct now has an error on it.
TestRunDespiteErrors in checker_test.go has been updated to reflect that
in some cases an analysis with RunDespiteErrors will fail to run because
a build error returned by go list when it's run to get export data is
not recognized as being a parse/typechecker error (the kind of error
allowed by TestRunDespiteError).
TestIntegration in unitchecker_test.go has been updated to reflect that
go vet running unitchecker will now fail with exit status 1 instead of 2
(so it just checks for a zero or non-zero status).
For golang/go#25842
Change-Id: Idbbd19b5de661e6e5f49e0475c5bc918d8e33803
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441879
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Most invalidation happens in snapshot.clone, but to be safe we were also
invalidating package data when new metadata is set via packages.Load. At
the time, I wasn't sure why this was necessary.
Now I understand: with experimentalUseInvalidMetadata it is possible
that we re-compute invalidated data using stale metadata in between the
initial clone and the subsequent reload. I noticed that it was also
possible to have stale analysis results after the Load results arrive.
Fix this by invalidating analysis results on Load, in addition to
packages. Factor out invalidation into a new helper method.
Since we believe this may fix analyzer panics, re-enable strict handling
of analysis panics during tests.
For golang/go#56035
For golang/go#54762
For golang/go#42857
Change-Id: I8c28e0700f8c16c58df4ecf60f6127b1c05d6dc5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420538
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
When finding references or implementations, we must include objects
defined in intermediate test variants. However, as we have seen we
should be careful to avoid accidentally type-checking intermediate test
variants in ParseFull, which is not their workspace parse mode.
Therefore eliminate the problematic TypecheckAll type-check mode in
favor of special handling in this one case where it is necessary.
Along the way:
- Simplify the mapping of protocol position->offset. This should not
require getting a package, or even parsing a file. For isolation,
just use the NewColumnMapper constructor, even though it may
technically result in building a token.File multiple times.
- Update package renaming logic to use TypecheckWorkspace, since we
only need to rename within the workspace.
- Add regtest support for Implementations requests.
Fixesgolang/go#43144
Change-Id: I41f684ad766f5af805abbd7c5ee0a010ff9b9b8c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/438755
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
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>
We've been using this setting in experimental for some time without
issue, so switch it to default.
For golang/go#52967
Change-Id: Ib4d786e689d4b0f009195cc86d7dd5d8269cf424
Reviewed-on: https://go-review.googlesource.com/c/tools/+/427534
Reviewed-by: Peter Weinberger <pjw@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Unaffecting vulnerabilities that appear should be shown as
informational diagnostics. These do not have current version.
Change-Id: I5dc8d111fd9de8388195627c8f050a2660426abb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441875
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
VS Code suppresses notifications if we send too many, but we don't want
users to miss warnings about deprecated settings. Merge them all into a
single message body.
Also fix a race in a test that added in the preceding CL: the old go
warnings may race with the initial workspace load.
For golang/vscode-go#2487
Change-Id: I69d61a17e0e6e888fa04fa1edce864e28a8d650e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/440180
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Investigation of renaming flakes revealed that renaming is known to be
flaky on windows, and the go command has a robustio package that works
around known flakes for certain IO operations on darwin and windows.
Rather than duplicate this logic piecemeal, copy the entire robustio
package to the gopls module, along with a script to sync it from GOROOT
using go generate. Use this new package to de-flake renaming, and
replace an existing workaround.
The copy script got a little out of hand at the point where I needed to
add +build constraints. Nevertheless, I've decided to keep it with the
caveat that it may be removed if it proves too difficult to maintain. As
is, it at least serves as documentation for how the sync was done.
For golang/go#56040
For golang/go#56039
For golang/go#56038
For golang/go#55324
Change-Id: Ifeda408ac44a2866e84015a2a38ae340dc0a88bb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/440181
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
We now have a plausible model for the cause of the analysis
crashes and are disabling this check until we have submitted
a plausible fix.
(Specifically: actionHandle.promise may be a stale promise
for an older package with the same ID, since snapshot.actions
uses the package ID as a key. This causes us to re-use
stale inspectors, whose syntax nodes won't be found in TypesInfo.)
Updates golang/go#54762
Updates golang/go#56035
Change-Id: I1a7cc1b02b8c322692b1a6bee03f6cd858c08ea0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/440179
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>
Auto-Submit: Alan Donovan <adonovan@google.com>
Add a showMessage notification when the Go version in PATH is too old.
Also delete the unused View.Rebuild method.
Updates golang/go#50825
Change-Id: I279a04f021a0f8ddb09fcfe299fbab8d10e8c022
Reviewed-on: https://go-review.googlesource.com/c/tools/+/439836
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
It has a known bug, and the purpose of the PanicOnBugs is to
find unknown bugs.
Updates golang/go#54762
Updates golang/go#56035
Change-Id: Id9fdfff478ef52b1d864acee366991808baeb574
Reviewed-on: https://go-review.googlesource.com/c/tools/+/440178
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
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>
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>
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>
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>
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>
The analysis driver uses a hack to reconstruct type
errors (which contain a token.Pos) from packages.Errors
(which contain file:line:col strings). This hack will
be obviated by https://go.dev/cl/425095 but in the meantime
it creates a dependency on the span package, which is
really part of gopls.
This change replaces the span.Parse function with simple
calls to the standard library to extract the line and column.
(Dependency aside, span.Parse was always overkill for this task,
but perhaps packages.Error should have a File,Line,Col accessor.)
Change-Id: I55108337f8a753523db68fe9e2aea15bb059cf15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/439755
gopls-CI: kokoro <noreply+kokoro@google.com>
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>
Make the test run only with go1.18+.
Change-Id: I8a2645929070bc1a63401ee942de1e88b5c083fa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/439275
Reviewed-by: Jamal Carvalho <jamal@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
These functions are now both expressed in terms of OffsetPosition,
which converts a file offset to a protocol (UTF-16) position.
No span.Point intermediaries are allocated.
Also, note some TODOs for further simplification.
Change-Id: I7e95c1b3ab16e4acfe4e461ee0aaa260efb6eec5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/439276
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>
This package hosts helper utilities for vulncheck features. This package requires go1.18+.
Most of the code were adopted from golang.org/x/vulndb/internal.
The first batch is NewDatabase reads YAML-format vulnerability
information files
(https://github.com/golang/vulndb/blob/master/doc/format.md)
packaged in txtar, and creates a filesystem-based vuln database
that can be used as a data source of golang.org/x/vuln/client
APIs.
See db_test.go for example.
* Source of the code
db.go:
golang.org/x/vulndb/internal/database#Generate
report.go:
golang.org/x/vulndb/internal/report#Report
stdlib.go:
golang.org/x/vulndb/internal/stdlib
This change adds a new dependency on "gopkg.in/yaml.v3"
for parsing YAMLs in testing
Change-Id: Ica5da4284c38a8a9531b1f943deb4288a2058c9b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/435358
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>
This is to pick up the fix for the file-scheme url handling bug
cd gopls
GOPROXY=direct go get golang.org/x/vuln@2aa0553d353b
go mod tidy -compat=1.16
Also updates the tests to use span.URIFromPath to generate
correct test database file uris.
Change-Id: I6de296cd21f3b98d72700ea57d1aa867658e7ac3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/438756
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
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>