Skip to content

Commit 56dc868

Browse files
committed
all: merge master (a297bfd) into gopls-release-branch.0.15
For golang/go#64973 Conflicts: - gopls/go.mod - gopls/go.sum Merge List: + 2024-02-06 a297bfd go/callgraph/rta: audit for types.Alias safety + 2024-02-06 08393e0 cmd/deadcode: audit for types.Alias safety + 2024-02-06 37586e4 internal/apidiff: audit for types.Alias safety + 2024-02-06 6d4ccf2 gopls/internal/cache: prime goimports cache asynchronously + 2024-02-06 8b6359d gopls/internal/cache: share goimports state for GOMODCACHE + 2024-02-06 2bb7f1c gopls/internal/test/integration/bench: improve completion benchmarks + 2024-02-06 f6dc1e9 internal/imports: merge init and newModuleResolver + 2024-02-06 4f6024e internal/gopathwalk: walk directories concurrently + 2024-02-06 8fcb5f0 gopls/internal/test/marker: skip on LUCI solaris builders + 2024-02-06 08bd728 gopls/internal/test/integration: add a test for an inner go.work file + 2024-02-06 aee2e76 gopls/internal/settings: deprecate "allowModfileModifications" + 2024-02-05 ddb71b0 gopls/internal/cache: remove findWorkspaceModFile + 2024-02-05 365517a gopls/internal/cache: detect and reinit on workspace vendor changes + 2024-02-05 0be034b internal/aliases: Adds an internal alias package. + 2024-02-05 8efa10c internal/imports: add a benchmark for the initial mod cache scan + 2024-02-05 df03d7d gopls/internal/golang: add missing check for nil funcBody + 2024-02-03 a1fbc78 gopls/internal/golang: move Go semantic tokens out of server + 2024-02-03 51e3724 gopls: remove unused parameters + 2024-02-03 d6bd2d7 gopls/internal/cache: add assertions for export data inconsistency + 2024-02-02 3403ce1 go/internal/gccgoimporter: recognize "any" as a builtin type + 2024-02-02 aecdb2d gopls/internal/cache: support workspace vendoring + 2024-02-02 e80085c gopls/internal/golang: downgrade bug.Reportf for missing builtin + 2024-02-02 9c43803 gopls/internal/cache: allow command-line-package >1 CompileGoFiles + 2024-02-02 efce0f5 gopls/internal/cache/metadata: assert graph is acyclic + 2024-02-02 c3f60b7 gopls/internal/golang: hover: show embedded fields + 2024-02-02 85146f5 gopls/internal/lsp/source: highlight returns correctly + 2024-02-02 e211e0f gopls: enable crashmonitor for unexpected crashes + 2024-02-01 d077888 gopls: update third party dependencies + 2024-02-01 2e15dc7 gopls/internal/test/marker: reject "module testdata" + 2024-02-01 c07f927 cmd/deadcode: enable crash reporting + 2024-02-01 44aed24 gopls/internal/analysis/undeclaredname: improve fix name + 2024-02-01 afe5265 go/packages: wait for sizes goroutine on all control paths + 2024-02-01 4250783 refactor/eg: don't use cgo in Test + 2024-02-01 1efbdde cmd/stringer, go/loader: use testenv.NeedsTool(t, "cgo") + 2024-01-31 5f90691 go/buildutil: permit comma delimiters in build tags + 2024-01-31 0c80ba3 internal/imports: remove the unused ProcessEnv.ModFile field + 2024-01-31 c046c5b gopls/internal/test/marker/testdata: move test to correct location + 2024-01-31 da7ed64 gopls/internal/cache/imports: simplify importsState invalidation + 2024-01-30 7ec8ac0 gopls/internal/golang: hover: show type's methods after doc comment + 2024-01-29 0e1f5be gopls: update x/telemetry dependency + 2024-01-29 341c043 gopls/internal/test/integration/bench: fix broken benchmarks + 2024-01-29 b048cf1 cmd/callgraph: unskip TestCallgraph on windows/arm64 + 2024-01-29 14d7f7b gopls/internal/cache: memoize the view filter func + 2024-01-29 5e16437 gopls/internal/cache: skip TestZeroConfigAlgorithm on wasm + 2024-01-29 dd0f88f gopls/doc/emacs.md: explain how to organize imports automatically + 2024-01-25 3d49bd5 internal/lsp: publish protocol.UnmarshalJSON + 2024-01-24 35d8b1b gopls/internal/golang: don't bug.Report repaired ASTs in hover + 2024-01-24 8174727 gopls/internal/test: await quiescence in TestInconsistentVendoring + 2024-01-24 df2fa1e gopls/doc: s/source/golang/ in the SVG file + 2024-01-24 238800b gopls: manual tweaks after the lsp/ -> . rename + 2024-01-24 95c6ac4 gopls/internal/protocol/command: move from ../lsp + 2024-01-24 6d109d1 gopls/internal/protocol: move out of lsp/ + 2024-01-24 f872b3d gopls/internal/cache: move out of lsp/ + 2024-01-24 6823da4 gopls/internal/golang: move from lsp/source + 2024-01-23 129144e gopls/internal/lsprpc: move out of lsp/ + 2024-01-23 eed1997 gopls: use relative watched file patterns if supported + 2024-01-23 fa791ac gopls/internal/progress: simplify API + 2024-01-23 816dcdf go/packages: add test for flake observed on Android + 2024-01-23 d5e76f1 gopls/internal/progress: move from lsp/ + 2024-01-23 6fe9326 gopls/internal/telemetry/cmd/stacks: include client name in report + 2024-01-23 6a58b98 gopls/internal/lsp/lsprpc: radically reduce API + 2024-01-23 0ffb1d0 gopls/doc: add Helix editor documentation for gopls + 2024-01-23 c16e222 gopls/internal/test/integration: add regtest for hover crash + 2024-01-23 bd547e5 gopls/internal/lsp/cache: clean up public API + 2024-01-22 4c53267 gopls/internal/lsp/cache: don't report a bug for standalone test files + 2024-01-22 a49867f internal/imports: don't add imports that shadow predeclared names + 2024-01-22 e2ca594 gopls/internal/lsp/source: address problems detected by staticcheck + 2024-01-22 94d99e3 gopls/internal/test/marker: re-enable some tests + 2024-01-22 060c748 gopls: consolidate analyzers, eliminating "convenience" analyzers + 2024-01-22 7f6ec23 go/ssa: suppress go/packages-based test on android + 2024-01-22 a987ef7 go/packages: publish Driver{Request,Response} + 2024-01-19 e1555a3 go/ssa: add Function.DomPostorder + 2024-01-19 cd7b510 gopls/internal/lsp/cache: allow versions of form "go1.2.3" + 2024-01-19 d0930db gopls/internal/lsp/cache: fix bug reports from toGobDiagnostics + 2024-01-19 1871a2e gopls/internal/lsp/source: move Go CodeActions logic from server + 2024-01-19 afcd676 gopls/internal/lsp/source: show promoted methods in hover + 2024-01-19 525acd1 go/analysis/internal/analysisflags: add RelatedInformation JSON + 2024-01-19 c7ccb51 gopls/doc/design: rewrite the architecture overview + 2024-01-19 39a2545 gopls/internal/version: amend the year in a recent copyright header + 2024-01-19 186fcf3 gopls/internal/lsp/source: factor edit conversion utils + 2024-01-19 83c6c25 gopls/internal/server: analyze widest packages for open files + 2024-01-19 c467be3 gopls: add a main.version variable to override the version at linktime + 2024-01-19 6673e7a gopls/internal/lsp/source/completion: infer parameter types + 2024-01-18 3458e0c gopls/internal/lsp/source: fix Fix titles + 2024-01-18 72a36a7 gopls/internal/test/marker: fix test breakage due to semantic conflict + 2024-01-18 470afda gopls/internal/analysis/unusedparams: eliminate false positives + 2024-01-18 592d9e1 internal/lsp: convert refactor code actions to use codeAction/resolve + 2024-01-17 f2d3f78 gopls/internal/lsp/protocol: fix TestURIFromPath on windows + 2024-01-17 d2200d1 gopls/internal/test/marker: update skip comment for addgowork.txt + 2024-01-17 c0db45f gopls/internal/server: simplify DiagnoseFiles to avoid a race + 2024-01-17 0d1b478 gopls/internal/test/integration: fix flakiness of TestResolveImportCycle + 2024-01-17 d517112 gopls/internal/lsp/protocol: deliver log messages in order + 2024-01-12 9164f2a gopls/internal/test/marker: skip on solaris-amd64-oraclerel + 2024-01-12 dbc9d3e internal/analysisinternal: TypeExpr: don't forget Variadic + 2024-01-12 54cf5bc internal/debug: show new View information in the debug page + 2024-01-12 b37fde9 gopls: simplify gopls command configuration + 2024-01-12 6a0605d gopls/internal/test/marker: regenerate golden data + 2024-01-11 f572b7e gopls/internal/lsp/source/stub: trim version suffix from module path + 2024-01-11 0b1f1d4 gopls/internal/lsp/cache: (re-)ensure clean shutdown + 2024-01-10 706525d gopls/internal/lsp/source/completion: support postfix completion (iferr, + 2024-01-09 581c0b3 gopls/internal/lsp/source: add receiver name to stubbed methods + 2024-01-08 c95fa0f gopls/internal/test: skip marker tests on darwin builders if -short + 2024-01-08 25a0e9d go.mod: update golang.org/x dependencies + 2024-01-05 c9c95f9 internal/refactor/inline: improve a confusing error message + 2024-01-05 ba8672b go/analysis/passes/unusedresult: add functions from slices package Change-Id: I428339a4a66ce849c3a3f8827da47125218bb121
2 parents 50d32be + a297bfd commit 56dc868

File tree

457 files changed

+9643
-5818
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

457 files changed

+9643
-5818
lines changed

cmd/callgraph/main_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"log"
1616
"os"
1717
"path/filepath"
18-
"runtime"
1918
"strings"
2019
"testing"
2120

@@ -35,10 +34,6 @@ func init() {
3534
}
3635

3736
func TestCallgraph(t *testing.T) {
38-
if runtime.GOOS == "windows" && runtime.GOARCH == "arm64" {
39-
t.Skipf("skipping due to suspected file corruption bug on windows/arm64 (https://go.dev/issue/50706)")
40-
}
41-
4237
testenv.NeedsTool(t, "go")
4338

4439
gopath, err := filepath.Abs("testdata")

cmd/deadcode/deadcode.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ import (
2626
"strings"
2727
"text/template"
2828

29+
"golang.org/x/telemetry/counter"
30+
"golang.org/x/telemetry/crashmonitor"
2931
"golang.org/x/tools/go/callgraph"
3032
"golang.org/x/tools/go/callgraph/rta"
3133
"golang.org/x/tools/go/packages"
3234
"golang.org/x/tools/go/ssa"
3335
"golang.org/x/tools/go/ssa/ssautil"
36+
"golang.org/x/tools/internal/aliases"
3437
)
3538

3639
//go:embed doc.go
@@ -62,6 +65,9 @@ Flags:
6265
}
6366

6467
func main() {
68+
counter.Open() // Enable telemetry counter writing.
69+
crashmonitor.Start() // Enable crash reporting watchdog.
70+
6571
log.SetPrefix("deadcode: ")
6672
log.SetFlags(0) // no time prefix
6773

@@ -380,10 +386,10 @@ func prettyName(fn *ssa.Function, qualified bool) string {
380386
// method receiver?
381387
if recv := fn.Signature.Recv(); recv != nil {
382388
t := recv.Type()
383-
if ptr, ok := t.(*types.Pointer); ok {
389+
if ptr, ok := aliases.Unalias(t).(*types.Pointer); ok {
384390
t = ptr.Elem()
385391
}
386-
buf.WriteString(t.(*types.Named).Obj().Name())
392+
buf.WriteString(aliases.Unalias(t).(*types.Named).Obj().Name())
387393
buf.WriteByte('.')
388394
}
389395

cmd/deadcode/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ With no flags, the command prints the name and location of each dead
6363
function in the form of a typical compiler diagnostic, for example:
6464
6565
$ deadcode -f='{{range .Funcs}}{{println .Position}}{{end}}' -test ./gopls/...
66-
gopls/internal/lsp/command.go:1206:6: unreachable func: openClientEditor
66+
gopls/internal/protocol/command.go:1206:6: unreachable func: openClientEditor
6767
gopls/internal/template/parse.go:414:18: unreachable func: Parsed.WriteNode
6868
gopls/internal/template/parse.go:419:18: unreachable func: wrNode.writeNode
6969

cmd/stringer/endtoend_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"bytes"
1414
"flag"
1515
"fmt"
16-
"go/build"
1716
"io"
1817
"os"
1918
"path"
@@ -50,6 +49,8 @@ func TestMain(m *testing.M) {
5049
}
5150

5251
func TestEndToEnd(t *testing.T) {
52+
testenv.NeedsTool(t, "go")
53+
5354
stringer := stringerPath(t)
5455
// Read the testdata directory.
5556
fd, err := os.Open("testdata")
@@ -76,8 +77,8 @@ func TestEndToEnd(t *testing.T) {
7677
continue
7778
}
7879
t.Run(name, func(t *testing.T) {
79-
if name == "cgo.go" && !build.Default.CgoEnabled {
80-
t.Skipf("cgo is not enabled for %s", name)
80+
if name == "cgo.go" {
81+
testenv.NeedsTool(t, "cgo")
8182
}
8283
stringerCompileAndRun(t, t.TempDir(), stringer, typeName(name), name)
8384
})
@@ -155,6 +156,8 @@ func TestTags(t *testing.T) {
155156
// TestConstValueChange verifies that if a constant value changes and
156157
// the stringer code is not regenerated, we'll get a compiler error.
157158
func TestConstValueChange(t *testing.T) {
159+
testenv.NeedsTool(t, "go")
160+
158161
stringer := stringerPath(t)
159162
dir := t.TempDir()
160163
source := filepath.Join(dir, "day.go")

copyright/copyright.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func checkFile(toolsDir, filename string) (bool, error) {
9494
return shouldAddCopyright, nil
9595
}
9696

97-
// Copied from golang.org/x/tools/gopls/internal/lsp/source/util.go.
97+
// Copied from golang.org/x/tools/gopls/internal/golang/util.go.
9898
// Matches cgo generated comment as well as the proposed standard:
9999
//
100100
// https://golang.org/s/generatedcode

go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ go 1.18
55
require (
66
github.com/yuin/goldmark v1.4.13
77
golang.org/x/mod v0.14.0
8-
golang.org/x/net v0.19.0
8+
golang.org/x/net v0.20.0
99
)
1010

11-
require golang.org/x/sync v0.5.0
11+
require golang.org/x/sync v0.6.0
12+
13+
require (
14+
golang.org/x/sys v0.16.0 // indirect
15+
golang.org/x/telemetry v0.0.0-20240201224847-0a1d30dda509
16+
)

go.sum

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
22
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
33
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
44
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
5-
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
6-
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
7-
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
8-
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
5+
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
6+
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
7+
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
8+
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
9+
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
10+
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
11+
golang.org/x/telemetry v0.0.0-20240201224847-0a1d30dda509 h1:Nr7eTQpQZ/ytesxDJpQgaf0t4sdLnnDtAbmtViTrSUo=
12+
golang.org/x/telemetry v0.0.0-20240201224847-0a1d30dda509/go.mod h1:ZthVHHkOi8rlMEsfFr3Ie42Ym1NonbFNNRKW3ci0UrU=

go/analysis/diagnostic.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ type Diagnostic struct {
3131
// see https://pkg.go.dev/net/url#URL.ResolveReference.
3232
URL string
3333

34-
// SuggestedFixes contains suggested fixes for a diagnostic
35-
// which can be used to perform edits to a file that address
36-
// the diagnostic.
37-
//
38-
// Diagnostics should not contain SuggestedFixes that overlap.
39-
SuggestedFixes []SuggestedFix // optional
34+
// SuggestedFixes is an optional list of fixes to address the
35+
// problem described by the diagnostic, each one representing
36+
// an alternative strategy; at most one may be applied.
37+
SuggestedFixes []SuggestedFix
4038

41-
Related []RelatedInformation // optional
39+
// Related contains optional secondary positions and messages
40+
// related to the primary diagnostic.
41+
Related []RelatedInformation
4242
}
4343

4444
// RelatedInformation contains information related to a diagnostic.
@@ -55,8 +55,7 @@ type RelatedInformation struct {
5555
// user can choose to apply to their code. Usually the SuggestedFix is
5656
// meant to fix the issue flagged by the diagnostic.
5757
//
58-
// TextEdits for a SuggestedFix should not overlap,
59-
// nor contain edits for other packages.
58+
// The TextEdits must not overlap, nor contain edits for other packages.
6059
type SuggestedFix struct {
6160
// A description for this suggested fix to be shown to a user deciding
6261
// whether to accept it.

go/analysis/internal/analysisflags/flags.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,24 @@ type JSONSuggestedFix struct {
362362
Edits []JSONTextEdit `json:"edits"`
363363
}
364364

365-
// A JSONDiagnostic can be used to encode and decode analysis.Diagnostics to and
366-
// from JSON.
367-
// TODO(matloob): Should the JSON diagnostics contain ranges?
368-
// If so, how should they be formatted?
365+
// A JSONDiagnostic describes the JSON schema of an analysis.Diagnostic.
366+
//
367+
// TODO(matloob): include End position if present.
369368
type JSONDiagnostic struct {
370-
Category string `json:"category,omitempty"`
371-
Posn string `json:"posn"`
372-
Message string `json:"message"`
373-
SuggestedFixes []JSONSuggestedFix `json:"suggested_fixes,omitempty"`
369+
Category string `json:"category,omitempty"`
370+
Posn string `json:"posn"` // e.g. "file.go:line:column"
371+
Message string `json:"message"`
372+
SuggestedFixes []JSONSuggestedFix `json:"suggested_fixes,omitempty"`
373+
Related []JSONRelatedInformation `json:"related,omitempty"`
374+
}
375+
376+
// A JSONRelated describes a secondary position and message related to
377+
// a primary diagnostic.
378+
//
379+
// TODO(adonovan): include End position if present.
380+
type JSONRelatedInformation struct {
381+
Posn string `json:"posn"` // e.g. "file.go:line:column"
382+
Message string `json:"message"`
374383
}
375384

376385
// Add adds the result of analysis 'name' on package 'id'.
@@ -401,11 +410,19 @@ func (tree JSONTree) Add(fset *token.FileSet, id, name string, diags []analysis.
401410
Edits: edits,
402411
})
403412
}
413+
var related []JSONRelatedInformation
414+
for _, r := range f.Related {
415+
related = append(related, JSONRelatedInformation{
416+
Posn: fset.Position(r.Pos).String(),
417+
Message: r.Message,
418+
})
419+
}
404420
jdiag := JSONDiagnostic{
405421
Category: f.Category,
406422
Posn: fset.Position(f.Pos).String(),
407423
Message: f.Message,
408424
SuggestedFixes: fixes,
425+
Related: related,
409426
}
410427
diagnostics = append(diagnostics, jdiag)
411428
}

go/analysis/passes/lostcancel/lostcancel.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,18 @@ func runFunc(pass *analysis.Pass, node ast.Node) {
172172
if ret := lostCancelPath(pass, g, v, stmt, sig); ret != nil {
173173
lineno := pass.Fset.Position(stmt.Pos()).Line
174174
pass.ReportRangef(stmt, "the %s function is not used on all paths (possible context leak)", v.Name())
175-
pass.ReportRangef(ret, "this return statement may be reached without using the %s var defined on line %d", v.Name(), lineno)
175+
176+
pos, end := ret.Pos(), ret.End()
177+
// golang/go#64547: cfg.Block.Return may return a synthetic
178+
// ReturnStmt that overflows the file.
179+
if pass.Fset.File(pos) != pass.Fset.File(end) {
180+
end = pos
181+
}
182+
pass.Report(analysis.Diagnostic{
183+
Pos: pos,
184+
End: end,
185+
Message: fmt.Sprintf("this return statement may be reached without using the %s var defined on line %d", v.Name(), lineno),
186+
})
176187
}
177188
}
178189
}

0 commit comments

Comments
 (0)