1
0
mirror of https://github.com/golang/go synced 2024-11-06 01:46:12 -07:00
Commit Graph

3167 Commits

Author SHA1 Message Date
Michael Matloob
340a1cdb50 internal/lsp: copy fact support from go/analysis/internal/checker.go
This changes the analysis code from that which was in unitchecker.go
to that in checker.go, so we can run actions that get facts for dependencies
concurrently.

Adds the rest of the traditional vet suite to the LSP.

TODO(matloob): test that facts are actually propagated between packages

Change-Id: I946082159777943af81bcf10e503fecc99da521e
Reviewed-on: https://go-review.googlesource.com/c/161671
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-12 19:58:15 +00:00
Michael Matloob
05d253c83e go/analysis/analysistest: change error message checked in expectation
text/scanner now uses the word "invalid" instead of "illegal".
See golang.org/cl/161199

Change-Id: I7db0ea2628760cba5c993bdec6e15e76b20b0e06
Reviewed-on: https://go-review.googlesource.com/c/162137
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-12 19:41:11 +00:00
Ian Cottrell
44bee7e801 internal/lsp: changing server noun to serve verb
Also adding in --remote support and using it to implement the equivalent
functionality of the external forward command
Also adding in --listen as a replacement for --port as it is more flexible,
specifically it allows localhost:port which
is helpful in environments where opening remotely accesible ports is
problematic.

Change-Id: I5de1cea7dd6f1ee46e7423f3be2a4caca6f040b2
Reviewed-on: https://go-review.googlesource.com/c/161658
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-11 22:49:14 +00:00
Michael Matloob
657755b003 internal/lsp: fix crash caused by lack of TypeSizes from go/packages.Load
Get dummy sizes values until we can get go/packages to forward the correct
values.

Change-Id: Ie31333e9ed7c57d02e1447097567fa894ea9de7d
Reviewed-on: https://go-review.googlesource.com/c/161937
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-11 18:30:33 +00:00
Rebecca Stambler
3744606dbb internal/lsp: type-check packages from source
This change moves gopls from type-checking packages using the
go/packages API to type-checking from source. This is the first step in
adding caching to gopls.

Change-Id: I2a7dcfd8c9c0bfc6c35c86eadcdc6f9ce53d9be7
Reviewed-on: https://go-review.googlesource.com/c/161497
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-08 22:27:37 +00:00
Michael Matloob
a3f91d6be4 internal/lsp: add support for analyzers with dependencies on other analyzers
Steal alan's parallel analysis-graph-running code from multichecker.
Facts are still not supported.

Change-Id: I22f83375d7a314b49d4f458d6dd40c33febc795b
Reviewed-on: https://go-review.googlesource.com/c/161659
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-08 18:55:13 +00:00
Rebecca Stambler
44bcb96178 go/packages: fix broken tests to handle changes to packagestest
golang.org/cl/161317 set Tests to true in the packagestest go/packages
Config. Handle this in the go/packages tests.

Fixes golang/go#30115

Change-Id: I6b4c0ca3dc2d73855239f3e7122e29da6ce81657
Reviewed-on: https://go-review.googlesource.com/c/161457
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-02-06 22:14:03 +00:00
Michael Matloob
a8576e2603 internal/lsp: connect basic analysis functionality
This starts hooking up the analysis framework into the LSP. It runs
the Tests analysis (which I think might be the only one that doesn't
need facts or results) and reports its diagnostics if there are
no parse or typecheck failures.

Next step: figure out how to pass through results.

Change-Id: I21702d1cf5d54da399df54437f556b9351caa864
Reviewed-on: https://go-review.googlesource.com/c/161358
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-06 21:48:25 +00:00
Yasuhiro Matsumoto
4892ae6946 go/packages: use strings.EqualFold in sameFile to handle case-insensitive file systems
Name of file or URI must be checked ignorecase on Windows.

Change-Id: I61507b0aa95389c5e1f421f0702ba6ad17b79177
Reviewed-on: https://go-review.googlesource.com/c/160597
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-06 17:56:59 +00:00
Rebecca Stambler
40960b6deb internal/lsp/cmd: fix a nil pointer and some minor clean-up
This change fixes a nil error, in addition to cleaning up a spacing
error and a typo. It also fixes the golint errors in internal/lsp/cmd.

Updates golang/go#30091

Change-Id: I24867bb878fda4e341f87d31bbec701a3814a341
Reviewed-on: https://go-review.googlesource.com/c/161220
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-06 04:15:39 +00:00
Rebecca Stambler
279ab8e001 internal/lsp, go/packages/packagestest: support testing test files
This change allows testdata files to be *_test.go files.

Change-Id: Ic771ea7c89ff2d2aabd1af8be56f9c7286da9053
Reviewed-on: https://go-review.googlesource.com/c/161317
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-06 04:07:32 +00:00
Rebecca Stambler
379209517f internal/lsp: add additional logging for go/packages failures
Change-Id: I8c6dae4309df1746cd8b74d280f1f360f42cc77b
Reviewed-on: https://go-review.googlesource.com/c/161218
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-05 20:13:29 +00:00
Rebecca Stambler
90c8b4f75b internal/lsp: handle escaping URIs for files in the module cache
This change makes sure to handle escaped characters, for instance, files
in the module cache contain "@" in the path. Also, return errors when a
package is not found for a file.

Updates golang/go#30027

Change-Id: I6c4f6d0f30dde55701308b89785f02b671e81cc6
Reviewed-on: https://go-review.googlesource.com/c/161077
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
2019-02-05 18:18:01 +00:00
Rebecca Stambler
069601f371 internal/lsp: use interface for diagnostics code
Since the diagnostics code can be either a string or a number, use an
empty interface.

Change-Id: Ie1a4183b5c82ef177176075828511070ae3520bd
Reviewed-on: https://go-review.googlesource.com/c/161217
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-05 18:07:22 +00:00
Agniva De Sarker
7f7074d5bc godoc: remove leading tabs while formatting text
Fixes golang/go#29568

Change-Id: Ia9e91bb4cf7a5916696268141ef5ec29e4372130
Reviewed-on: https://go-review.googlesource.com/c/160917
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-05 05:01:22 +00:00
Jonathan Amsterdam
b2f7fe607d cmd/stringer: type check using export data
Use go/packages to find and type check packages using export data.

In addition to type checking with export data, this should also enable
cmd/stringer to work correctly when using go modules.

jba: took over CL, tweaked package.Config use.

Change-Id: Ie253378b52fbd909f7194dfd09c039aab63dd8f0
Reviewed-on: https://go-review.googlesource.com/c/126535
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-04 22:01:59 +00:00
Rebecca Stambler
d810ce9e47 cmd/guru: remove Go 1.9 handling, since we no longer support 1.8
Some tests were split off for Go 1.9, when we still supported Go 1.8.
This change recombines them and removes the special handling for 1.9.

Fixes golang/go#24421

Change-Id: Ic871f4c3af4bb90b00cdd6d7b8f3253783554535
Reviewed-on: https://go-review.googlesource.com/c/161000
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-02-04 19:56:32 +00:00
Rebecca Stambler
021ffbf1e9 internal/lsp: do not return nil identifiers without errors
Change-Id: I9ffc37dc07f46536a44f7173277d0374fdda1fb8
Reviewed-on: https://go-review.googlesource.com/c/160698
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-04 17:30:59 +00:00
Rebecca Stambler
8a24307720 internal/lsp/diff: fix sources listed for diff implementation
Change-Id: I36b2903f4938c4e7a3f15567e11ab31f3f7d78f7
Reviewed-on: https://go-review.googlesource.com/c/160840
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-04 17:30:30 +00:00
Andzej Maciusovic
7414d4c1f7 internal/lsp: rank types higher when completing in return of a function
Completion now ranks type names higher for func receiver, type params and type results (e.g. func (<>) foo(<>) (<>) {}).

Fixes golang/go#29152

Change-Id: Icdd18b1b344c1cd617a4f45a7b071e53c1345478
GitHub-Last-Rev: e6acb1f2d2a7e571ffcecc500e407fdefd118fed
GitHub-Pull-Request: golang/tools#73
Reviewed-on: https://go-review.googlesource.com/c/159797
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-02 23:51:57 +00:00
Brad Fitzpatrick
718ddee956 Revert "go/analysis/passes/atomicalign: handle pointers to struct"
This reverts CL 158999, commit 8dbcc66f33.

Reason for revert: broke the build, nobody ever ran trybots

Change-Id: I2180ed8f9281b413b2ffea086abbd09fbfc3c99e
Reviewed-on: https://go-review.googlesource.com/c/160839
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2019-02-02 20:26:10 +00:00
Rebecca Stambler
51e363b66d internal/lsp: implement diff for computing text edits
Rather than replacing the whole file on gofmt or goimports, use the Myers
diff algorithm to compute diffs for a file. We send those back as text
edits.

Change-Id: I4f8cce5b27d51eae1911049ea002558a84cdf1bf
Reviewed-on: https://go-review.googlesource.com/c/158579
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-01 23:18:25 +00:00
Brad Fitzpatrick
0e05534988 cmd/tip: delete
The cmd/tip program moved to x/build (along with its history) in:

  https://go.googlesource.com/build/+/63986c177d1ff5d2629840f6b00c445f1cb932bf

(There's no associated Gerrit CL; the merge commit of x/build's old
HEAD + a git-filter-branch of x/tools's cmd/tip was pushed directly to
Gerrit's git server, without creating Gerrit CLs for review for each
commit in its history)

Updates golang/go#29981

Change-Id: I16b9b1b0079e3d7b6851cb3e7322a878ece73e23
Reviewed-on: https://go-review.googlesource.com/c/160817
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-02-01 18:59:10 +00:00
Ian Cottrell
067a2f313b internal/lsp/cmd: add the definition mode
Change-Id: Ib171016fb1bb063a6424677458b554a08144465c
Reviewed-on: https://go-review.googlesource.com/c/159438
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-01-31 16:39:42 +00:00
Aurélien Rainone
8dbcc66f33 go/analysis/passes/atomicalign: handle pointers to struct
The atomicalign checker detects non-64-bit aligned struct field
arguments to sync/atomic functions but currently misses out cases
where the struct variable identifier is a pointer to struct. This
is very common as it happens when the 64-bit field is accessed
in a method with pointer receiver, where the struct is itself the
method receiver. Add some tests to cover that new case.

While I'm at it, fix some typos.

Change-Id: I582cf5b7286b11285010f085045f58dc636ef3ee
Reviewed-on: https://go-review.googlesource.com/c/158999
Reviewed-by: Alan Donovan <adonovan@google.com>
2019-01-31 14:20:11 +00:00
Rebecca Stambler
bb1329dc71 godoc/static: update static.go
golang.org/cl/158137 was missing a corresponding update to static.go.

Updates golang/go#29482

Change-Id: I60e059c3f00408c0d41e5284cb3e154fc1515032
Reviewed-on: https://go-review.googlesource.com/c/160482
Reviewed-by: Katie Hockman <katie@golang.org>
2019-01-30 21:42:55 +00:00
Rebecca Stambler
58ecf64b2c go/internal/gcimporter: write export data for go/types
Add an iexport.go (and corresponding iexport_test.go) file, which is an
adapted version of $GOROOT/src/cmd/compile/internal/gc/iexport.go. This
code writes exportdata for a *go/types.Package.

A majority of this code is directly copied from iexport.go, with a
change of types, while some of it had to be modified slightly.

Updates golang/go#28260

Change-Id: Ic7e8e99f0c6b886839280b410afffb037da8a79b
Reviewed-on: https://go-review.googlesource.com/c/156901
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2019-01-30 20:35:36 +00:00
Andrew Bonventre
9bdeaddf5f godoc/static: inherit textarea color to avoid illegible text
The cascading sylesheet from the users UI can be inverted.
If the background color is altered in the textarea and the text
style is left unchanged the text may become illegible.
The default value of the textarea color is that of the users UI
styling and is not the same as that of the document body.
Setting color: inherit; resolves this.

Fixes golang/go#29482

Change-Id: Iaa6780154e0bd01d2a8219d813468dab25331b46
GitHub-Last-Rev: 8706d7aa4e183f98144b0b958f745bab12b6ce75
GitHub-Pull-Request: golang/tools#70
Reviewed-on: https://go-review.googlesource.com/c/158137
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2019-01-30 19:01:28 +00:00
Ian Cottrell
cb89afadce imports: drop anything after a non identifier rune in package names
A package name cannot contain a '.' anyway, so this is a mostly likely
internal package name in the presence of a '.' in the import path.
This stops goimports from adding a local alias in places where it is not
needed, for instance in gopkg.in conventions.

Fixes golang/go#29556

Change-Id: I0ab11f2852d7f1dae14457995692760077201c8e
Reviewed-on: https://go-review.googlesource.com/c/157357
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-01-30 18:50:28 +00:00
Dmitri Shuralyov
1c3581914d godoc/short: point to new tracking issue for shortlink creation
There's a new dedicated issue tracking this task, point to it instead
of the previous large issue which has been closed by now.

Updates golang/go#29988
Updates golang/go#27205

Change-Id: Ib1443d14a6369322b36cdf8305344a35c421a2e5
Reviewed-on: https://go-review.googlesource.com/c/160377
Reviewed-by: Agniva De Sarker <agniva.quicksilver@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-30 17:39:57 +00:00
Josh Bleecher Snyder
a06a922acc imports: update zstdlib to Go 1.12
Change-Id: Ie70c3d060de9c2e5d3404e073bdc20defdc46357
Reviewed-on: https://go-review.googlesource.com/c/160183
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-30 01:50:43 +00:00
Michael Matloob
9cefa6771f go/packages: rename name= query and "disable" it
It was originally added to support goimports, but goimports
is going with another solution. We're going to disable it for
now, but not delete it, so that the goimports code path that
uses it can continue to be tested if and when we want to
use it.

We don't think there are any other users of name= but if
there are, please let us know and we'll work with you to
fix you, or we'll stop or revert this change. Thanks!

Change-Id: I73b7b6c0a5788148af5f3380189055b450f7b45e
Reviewed-on: https://go-review.googlesource.com/c/159702
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-01-29 21:16:23 +00:00
Dmitri Shuralyov
0a99049195 go/vcs: remove go.googlesource.com vcsPath entry
This change synchronizes the absence of a special case entry for
go.googlesource.com import paths in cmd/go/internal/get to this
package. It seems it was added to x/tools/go/vcs in CL 180540043,
but it was never added to cmd/go/internal/get itself.

Having an go.googlesource.com entry here but not in cmd/go/internal/get
means the import path resolution logic diverges from that of the go
command, which is counter to the goal of this package.

After this change is applied, vcs.RepoRootForImportPathStatic reports
correct results for import paths like "go.googlesource.com/scratch.git"
(resolving it without an error) and "go.googlesource.com/scratch"
(reporting an error).

Updates golang/go#11490

Change-Id: I0b1c959675d9e20205a587a06d734fcd103ebf91
Reviewed-on: https://go-review.googlesource.com/c/159817
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-28 23:20:29 +00:00
Michael Matloob
3c4dfba64b cmd/heapview: delete
This is all dead code that never went anywhere.

Change-Id: I79db05d6391709bb9ae3d86f557246f1dd3b21f7
Reviewed-on: https://go-review.googlesource.com/c/159957
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-28 22:39:01 +00:00
Andrew Bonventre
d66bd3c5d5 cmd/godoc: add x/xerrors redirect
Change-Id: I367caa5f8c90e53768b07427248ed2bcc83a58e3
Reviewed-on: https://go-review.googlesource.com/c/159739
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-01-25 23:20:54 +00:00
Ian Cottrell
cc6a436ffe internal/lsp: refactor definition and hover to share functionality
The source package now exposes an Identifier method that returns information
about an identifier, which can be used to implement Definition, TypeDefinition
and Hover, as well as other command line functions in a later cl.

Change-Id: I03629c2c940215b4e2c86ee45bee8a18b79ee0e1
Reviewed-on: https://go-review.googlesource.com/c/159337
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-01-24 21:53:03 +00:00
Douglas Danger Manley
4e3518700c go/packages: stop parsing files if the context is canceled
`stamblerre/gocode`, which is the fork of `mdempsky/gocode` that supports Go 1.11 modules, uses `packages.Load` to load all of the Go code for, among other things, IDE autocomplete support.  A common aspect to IDE autocomplete is asking for suggestions very frequently (perhaps at every character typed).  Once the user has typed another character, the previous request for autocomplete is invalid and can be canceled.

`packages.Load` already stops its `go list` component if the context is canceled, but if the context is canceled afterward, then it will parse all of the files that it found.  This change stops the parsing of Go files once it detects that the context has been canceled.  When a file has not been processed due to cancelation, its error will be set to that of the context.

This change dramatically improves the performance of the `stamblerre/gocode` fork when requests have been canceled.

Change-Id: Iba8c1e08eefa59137559ac9108238bfe5ba4ac21
GitHub-Last-Rev: 11a2210c8ce2ed9db9462ddc3e9676476f49f937
GitHub-Pull-Request: golang/tools#72
Reviewed-on: https://go-review.googlesource.com/c/159259
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-01-24 20:56:45 +00:00
Michael Matloob
a78a3054ec go/analysis/passes/composite: add an example to the doc
Change-Id: I929a5390aa5f4a4484e57ffa1eaa66f3238da1c1
Reviewed-on: https://go-review.googlesource.com/c/159338
Reviewed-by: Alan Donovan <adonovan@google.com>
2019-01-24 19:20:49 +00:00
Ian Cottrell
78ee07aa94 cmd/gopls/integration: git ignore temporary vscode files
Change-Id: I9585fb227f44c4bf8071247bb6b89b6fed6cf83b
Reviewed-on: https://go-review.googlesource.com/c/159277
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-01-24 00:41:07 +00:00
Julie Qiu
0c44af741b godoc/dl: add julieqiu to validUser
Change-Id: I6b2a49fdae7c45b2b40865c637243402952826af
Reviewed-on: https://go-review.googlesource.com/c/159138
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-23 19:20:57 +00:00
tell-k
85a87a81a9 cmd/present: fix CSS when printing slides
The existing CSS style was causing slides to not align with page
boundaries when printing slides. The cause of that is the CSS transform
property that is applied to automatically scale size of slides.
This change clears the transform property just before printing.

Fixes golang/go#29480

Change-Id: I6f719ad1b716e9bda8ba83007c3d1d7dece9ce08
GitHub-Last-Rev: d46dfee57601b2e9127c5e8e80e596dc2a2f24fa
GitHub-Pull-Request: golang/tools#67
Reviewed-on: https://go-review.googlesource.com/c/155940
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-01-23 18:36:29 +00:00
Dmitri Shuralyov
9279ec27fd cmd/tip: also fetch x/net repository before building cmd/godoc
x/tools/cmd/godoc uses at least one Go package from x/net as of
CL 157197.

Don't add it to signature because we don't want the signature to
change whenever new commits to x/net are pushed, causing tip.golang.org
to be redeployed. This is because x/net is not considered a critical
component of the website at this time, and that's not expected to
change soon.

When the website begins using modules, it will specify the x/net
version precisely and this decision will no longer matter.

Fixes golang/go#29874

Change-Id: I1fa76bb81f8d2ffc2314375e2dfe4898c3af58de
Reviewed-on: https://go-review.googlesource.com/c/158937
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-23 02:11:25 +00:00
Heschi Kreinick
9c309ee22f imports: stop using go/packages for modules
go/packages needs to call `go list` multiple times, which causes
redundant work and slows down goimports. If we reimplement `go list` in
memory, we can reuse state, saving time. `go list` also does work we
don't really need, like adding stuff to go.mod, and skipping that saves
more time.

We start with `go list -m`, which does MVS and such. The remaining work
is mostly mapping import paths and directories through the in-scope
modules to make sure we're giving the right answers. Unfortunately this
is quite subtle, and I don't know where all the traps are. I did my
best.

cmd/go already has tests for `go list`, of course, and packagestest is
not well suited to tests of this complexity. So I ripped off the script
tests in cmd/go that seemed relevant and made sure that our logic
returns the right stuff in each case. I'm sure that there are more cases
to cover, but this hit all the stuff I knew about and quite a bit I
didn't.

Since we may want to use the go/packages code path in the future, e.g.
for Bazel, I left that in place. It won't be used unless the magic env
var is set.

Files in internal and imports/testdata/mod were copied verbatim from
cmd/go.

Change-Id: I1248d99c400c1a0c7ef180d4460b9b8a3db0246b
Reviewed-on: https://go-review.googlesource.com/c/158097
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-01-22 20:29:12 +00:00
Andzej Maciusovic
2d2e1b1749 internal/lsp: do not complete inside comments in functions
The previous change (https://go-review.googlesource.com/c/tools/+/157678) only stopped completion in comments in global scope. This change prevents completions results from being sent for comments inside of functions.

Fixes golang/go#29370

Change-Id: I2b43ae2942c6ce7376d2a5f88c40e6ac45c2b773
GitHub-Last-Rev: bc4aac1370aa5758941cdfae63290f061a55e204
GitHub-Pull-Request: golang/tools#71
Reviewed-on: https://go-review.googlesource.com/c/158538
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-01-22 18:08:10 +00:00
Ian Lance Taylor
b2f1847864 go/analysis/internal/checker: correct comment grammar
Change-Id: I78b41326c5d8d22fbff40f89721ac3aad3a5c63c
Reviewed-on: https://go-review.googlesource.com/c/158841
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-22 15:45:57 +00:00
Aurélien Rainone
24cd39ecf7 go/analysis/passes/atomicalign: add atomicalign ckecker
The atomicalign Analyzer checks the alignment of 64-bits variables
accessed atomically via sync/atomic functions on 32-bits
architectures. Per the sync/atomic BUG note those variables must
be 64-bits aligned, otherwise a runtime panic is issued.

The analyzer only shows and runs on 32-bits architectures.

This CL should not introduce any false positives.

Add some tests in testdata/src/a to verify the analyzer behavior
on affected architectures plus some very basic test to verify that
no warning is generated on non-affected ones.

Fixes golang/go#11891

Change-Id: I02cfc574883564cd2a213a92d33bda3cc9a1ea98
Reviewed-on: https://go-review.googlesource.com/c/158277
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2019-01-21 14:31:47 +00:00
Heschi Kreinick
16909d206f imports: remove globals, stop using build.Default
The imports package's public API is build.Default, but that doesn't mean
we need to use it in the internal implementation or the tests. Now we
have a new type, fixEnv, that contains everything relevant from
build.Context, as well as the various global vars that were only used
for testing.

Don't worry too much about the new function parameters; they mostly
move into the resolvers in the next CL.

Refactoring only; no user-visible changes intended.

Change-Id: I0d4c904955c5854dcdf904009cb3413c734baf88
Reviewed-on: https://go-review.googlesource.com/c/158437
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-01-18 19:33:59 +00:00
Heschi Kreinick
6466e7265e imports: don't eagerly guess package names
Before this change, we guessed package names during loadPackageNames
when necessary. That made it impossible to tell if we failed to load
a package's name, e.g. because its source code is unavailable. That
interferes with fixes for golang/go#29557. It also meant that each
implementation of package name loading needs to do the guessing,
which gets annoying in CL 158097.

Instead, leave package names unset unless we're certain about them, and
guess only in (*pass).importIdentifier when necessary.

Refactoring only; no user-visible changes intended.

Change-Id: Ia6072ada823e6e3a86981ad90228f30baa2ac708
Reviewed-on: https://go-review.googlesource.com/c/158199
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-01-18 19:13:21 +00:00
Alan Donovan
b4b6fe2cb8 go/{analysis,packages}: add TypesSizes
Many Analyzers need to measure the width of an integer and all today
use hacks. This change causes analysis.Pass to retain and expose the
type sizing function used during type checking.

This in turn requires go/packages to retain and expose the type sizing
function in Packages.TypesSizes, which addresses a longstanding need
among many of its clients.

Change-Id: Ia8362019bcde34c10cb4fbc38cfdfddcbef3eb5c
Reviewed-on: https://go-review.googlesource.com/c/158317
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
2019-01-17 19:41:23 +00:00
Rebecca Stambler
b258f6da23 cmd/gopls: rename "golsp" to "gopls", as in "Go Please"
Change-Id: Ie5688759ce21bffa6745eb86ef3606639e3ce335
Reviewed-on: https://go-review.googlesource.com/c/158197
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-01-16 23:16:16 +00:00