Skip to content

Commit dff5032

Browse files
committed
[gopls-release-branch.0.7] all: merge master into gopls-release-branch.0.7
acac939 go/analysis/passes/bools: add typeparams test ac2ed98 go/analysis/passes/printf: warn against using non-error interface values with %w 378b9e1 internal/lsp/analysis: add typeparams tests for nonewvars and noresultvalues 24389d4 internal/lsp: use the correct dynamic registration booleans 074820e go/analysis/passes/usesgenerics: a new analysis to detect generic code 94178a2 internal/lsp: use source.Offset instead of tok.Offset 0b930fb cmd/goimports: recommend go install instead of go get in docs c83725b go/analysis/passes/loopclosure: add typeparams test 18fa840 internal/lsp/semantic: prepare for generics 1af23bd go/analysis/passes/assign: add typeparams test ee04797 go/types/objectpath: canonical order for methods c5188f2 gopls/doc/advanced.md: update unstable version installation instruction d477ef3 go/analysis/passes/atomic: add a test that uses typeparams 2dc2755 internal/lsp/protocol: update LSP definitions and stubs 81efdbc cover: add function to parse profiles from an io.Reader 36e7bf9 internal/lsp/analysis/unusedparams: add tests for generics db89b5a internal/lsp: handle nil pointer in fixInitStmt ccaa907 go/analysis/passes/unmarshal: allow unmarshalling to a type parameter 0ebff1a go/ast/astutil: update PathEnclosingInterval to handle type parameters 942994f internal/typeparams: use alias rather than indirection for IndexListExpr 13c407c go/ast/inspector: add support for the new IndexListExpr node 58ad7eb go/types/objectpath: add support for type parameters 3883e4a go/internal/gcimporter: allow both prefixes and subscripts for tparams 6f5fd9b internal/lsp: add parameterized slice test for simplifyslice analysis 2189684 internal/typeparams: use NewSignatureType, IsMethodSet, and Context e89823e x/tools/go/internal/gcimporter: exclude a file from TestImportTypeparamTests 1c35f2a internal/lsp/analysis: quick-fix to remove unnecessary type arguments 7d467dc internal/lsp: support go.work outside of experimental d9648c9 go/analysis: test errorsas analysis with type params d42c92b internal/lsp/analysis/fillreturns: skip any parameterized functions 5dbd5e4 internal/typeparams: filter out API diffs related to types.Environment df9a164 Revert "internal/typeparams: hide go1.18 API usage behind a build constraint" 0df0ca0 internal/typeparams: hide go1.18 API usage behind a build constraint 7898fe6 internal/lsp/analysis: move implementmissing logic into undeclared da36f79 go/internal/gcimporter: skip typeparam import tests on unified builders 64bbad1 internal/lsp/debug: improve readability of session options b182fde go/analysis/passes/tests: check example output ba6b94c internal/lsp: add fields to anonymous struct info 939195f go/ssa: skip the "constraints" package in TestStdlib e1e06b8 go/internal/gcimporter: temporarily skip the contraints package on the unified builder 6d1e33f internal/lsp: handle panic in hoverRune by using token.Pos c8db761 internal/lsp/cache: keep going on failed analyzers 2847958 internal/lsp/analysis: add a useany analyzer efaec4e go/pointer: skip tests that depend on an unstable API changed in Go 1.18 ecbcf3a go/callgraph/vta: improve support for function value flow b98090b internal/lsp/analysis/implementmissing: add analyzer 0d12d39 internal/typeparams: update to the new Instances API fe076c8 internal/typesinternal: document ReadGo116ErrorData 91c880c go/internal/gcimporter: add support for exporting the 1.18 export format d2417d5 gopls/doc: add instructions for the new "kokoro rerun" feature 464a887 internal/lsp/templates: replace panic by logging a0016a2 internal/lsp/diagnostics: avoid erroneous error message for orphaned files 7559231 internal/lsp/command: fix typo in comment 2758b04 gopls/api-diff: create api-diff command for gopls api aba0c5f go/callgraph/vta: optimize scc type initialization 1a7ca93 internal/lsp/source: update SuggestedFixFunc to accept source.Snapshot 76d4494 internal/lsp: fix panic in find references on Error 4ba3eff gopls/doc: remove -tags=typeparams from generic build instructions 02e5238 go/internal/gcimporter: rename instType to instanceType 0cffec9 go/internal/gcimporter: update iimport.go to support type parameters 5492d01 internal/lsp/testdata: update inferred.go to use hoverdef 9207707 go/internal/gcimporter: skip TestIExportData_stdlib on go1.18 cd7c003 internal/lsp: add support for hovering runes 258ee27 internal/lsp/template: implement completions for template files 384e5da go/ssa: keep the ops doc sorted alphabetically e7de652 internal/lsp: produce "method" in place of "member" as per the spec 915f620 go/ssa: fix slice to array ptr conversions for named type a568412 go/callgraph/vta: fix call site computation bug 295a39b internal/lsp: remove the TODO and add a test for the hover panic c163c31 gopls: add more instructions for working with Bazel and gopls 076821b internal/typeparams: update MultiIndexExpr to IndexListExpr 2cae65c internal/typeparams: follow changes to Type in the go/ast and go/types 0a6f080 internal/lsp: check InRange before calling token.Offset e5f719f internal/lsp/source: consider test variants when finding pkg from pos 3604566 go/analysis/passes/testinggoroutine: fix panic in goStmtFun d39bbca gopls: consistently capitalize enum variants for symbolStyle 4e109c5 gopls: use new "codelenses" config key in docs over deprecated "codelens" 7391fc1 gopls/doc: update generic code section of advanced.md 3b801c8 internal/lsp: exclude node_modules in the workspace root by default Change-Id: I9e6d85aa0a8506c63d082e1a73c749781dccf720
2 parents fd02dfa + acac939 commit dff5032

File tree

220 files changed

+6286
-1213
lines changed

Some content is hidden

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

220 files changed

+6286
-1213
lines changed

cmd/goimports/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Command goimports updates your Go import lines,
88
adding missing ones and removing unreferenced ones.
99
10-
$ go get golang.org/x/tools/cmd/goimports
10+
$ go install golang.org/x/tools/cmd/goimports@latest
1111
1212
In addition to fixing imports, goimports also formats
1313
your code in the same style as gofmt so it can be used

copyright/copyright.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,37 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.18
6+
// +build go1.18
7+
58
// Package copyright checks that files have the correct copyright notices.
69
package copyright
710

811
import (
912
"go/ast"
1013
"go/parser"
1114
"go/token"
15+
"io/fs"
1216
"io/ioutil"
13-
"os"
1417
"path/filepath"
1518
"regexp"
1619
"strings"
1720
)
1821

1922
func checkCopyright(dir string) ([]string, error) {
2023
var files []string
21-
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
24+
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
2225
if err != nil {
2326
return err
2427
}
25-
if info.IsDir() {
28+
if d.IsDir() {
2629
// Skip directories like ".git".
27-
if strings.HasPrefix(info.Name(), ".") {
30+
if strings.HasPrefix(d.Name(), ".") {
31+
return filepath.SkipDir
32+
}
33+
// Skip any directory that starts with an underscore, as the go
34+
// command would.
35+
if strings.HasPrefix(d.Name(), "_") {
2836
return filepath.SkipDir
2937
}
3038
return nil

copyright/copyright_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.18
6+
// +build go1.18
7+
58
package copyright
69

710
import (

cover/profile.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"bufio"
1111
"errors"
1212
"fmt"
13+
"io"
1314
"math"
1415
"os"
1516
"sort"
@@ -45,14 +46,18 @@ func ParseProfiles(fileName string) ([]*Profile, error) {
4546
return nil, err
4647
}
4748
defer pf.Close()
49+
return ParseProfilesFromReader(pf)
50+
}
4851

49-
files := make(map[string]*Profile)
50-
buf := bufio.NewReader(pf)
52+
// ParseProfilesFromReader parses profile data from the Reader and
53+
// returns a Profile for each source file described therein.
54+
func ParseProfilesFromReader(rd io.Reader) ([]*Profile, error) {
5155
// First line is "mode: foo", where foo is "set", "count", or "atomic".
5256
// Rest of file is in the format
5357
// encoding/base64/base64.go:34.44,37.40 3 1
5458
// where the fields are: name.go:line.column,line.column numberOfStatements count
55-
s := bufio.NewScanner(buf)
59+
files := make(map[string]*Profile)
60+
s := bufio.NewScanner(rd)
5661
mode := ""
5762
for s.Scan() {
5863
line := s.Text()

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ require (
88
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d
99
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
1010
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e
11+
golang.org/x/text v0.3.6
1112
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
1213
)

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
1818
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
1919
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2020
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
21+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
22+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
2123
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
24+
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
2225
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
2326
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
2427
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=

go/analysis/analysistest/analysistest.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,13 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns
196196
want := string(bytes.TrimRight(vf.Data, "\n")) + "\n"
197197
formatted, err := format.Source([]byte(out))
198198
if err != nil {
199+
t.Errorf("%s: error formatting edited source: %v\n%s", file.Name(), err, out)
199200
continue
200201
}
201202
if want != string(formatted) {
202203
d, err := myers.ComputeEdits("", want, string(formatted))
203204
if err != nil {
204-
t.Errorf("failed to compute suggested fixes: %v", err)
205+
t.Errorf("failed to compute suggested fix diff: %v", err)
205206
}
206207
t.Errorf("suggested fixes failed for %s:\n%s", file.Name(), diff.ToUnified(fmt.Sprintf("%s.golden [%s]", file.Name(), sf), "actual", want, d))
207208
}
@@ -225,12 +226,13 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns
225226

226227
formatted, err := format.Source([]byte(out))
227228
if err != nil {
229+
t.Errorf("%s: error formatting resulting source: %v\n%s", file.Name(), err, out)
228230
continue
229231
}
230232
if want != string(formatted) {
231233
d, err := myers.ComputeEdits("", want, string(formatted))
232234
if err != nil {
233-
t.Errorf("failed to compute edits: %s", err)
235+
t.Errorf("%s: failed to compute suggested fix diff: %s", file.Name(), err)
234236
}
235237
t.Errorf("suggested fixes failed for %s:\n%s", file.Name(), diff.ToUnified(file.Name()+".golden", "actual", want, d))
236238
}

go/analysis/passes/assign/assign_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ import (
99

1010
"golang.org/x/tools/go/analysis/analysistest"
1111
"golang.org/x/tools/go/analysis/passes/assign"
12+
"golang.org/x/tools/internal/typeparams"
1213
)
1314

1415
func Test(t *testing.T) {
1516
testdata := analysistest.TestData()
16-
analysistest.RunWithSuggestedFixes(t, testdata, assign.Analyzer, "a")
17+
tests := []string{"a"}
18+
if typeparams.Enabled {
19+
tests = append(tests, "typeparams")
20+
}
21+
analysistest.RunWithSuggestedFixes(t, testdata, assign.Analyzer, tests...)
1722
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// This file contains tests for the useless-assignment checker.
6+
7+
//go:build go1.18
8+
9+
package testdata
10+
11+
import "math/rand"
12+
13+
type ST[T interface{ ~int }] struct {
14+
x T
15+
l []T
16+
}
17+
18+
func (s *ST[T]) SetX(x T, ch chan T) {
19+
// Accidental self-assignment; it should be "s.x = x"
20+
x = x // want "self-assignment of x to x"
21+
// Another mistake
22+
s.x = s.x // want "self-assignment of s.x to s.x"
23+
24+
s.l[0] = s.l[0] // want "self-assignment of s.l.0. to s.l.0."
25+
26+
// Bail on any potential side effects to avoid false positives
27+
s.l[num()] = s.l[num()]
28+
rng := rand.New(rand.NewSource(0))
29+
s.l[rng.Intn(len(s.l))] = s.l[rng.Intn(len(s.l))]
30+
s.l[<-ch] = s.l[<-ch]
31+
}
32+
33+
func num() int { return 2 }
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// This file contains tests for the useless-assignment checker.
6+
7+
//go:build go1.18
8+
9+
package testdata
10+
11+
import "math/rand"
12+
13+
type ST[T interface{ ~int }] struct {
14+
x T
15+
l []T
16+
}
17+
18+
func (s *ST[T]) SetX(x T, ch chan T) {
19+
// Accidental self-assignment; it should be "s.x = x"
20+
// want "self-assignment of x to x"
21+
// Another mistake
22+
// want "self-assignment of s.x to s.x"
23+
24+
// want "self-assignment of s.l.0. to s.l.0."
25+
26+
// Bail on any potential side effects to avoid false positives
27+
s.l[num()] = s.l[num()]
28+
rng := rand.New(rand.NewSource(0))
29+
s.l[rng.Intn(len(s.l))] = s.l[rng.Intn(len(s.l))]
30+
s.l[<-ch] = s.l[<-ch]
31+
}
32+
33+
func num() int { return 2 }

0 commit comments

Comments
 (0)