Skip to content

Commit bca115b

Browse files
committed
[gopls-release-branch.0.7] all: merge master into gopls-release-branch.0.7
8122e49 go/pointer: remove use of deprecated ssa.CreateTestMainPackage 1a3081d all: prepare for formatting any as 'any' in type strings 4adea50 internal/typeparams: normalize the underlying constraint interface 4392381 go/analysis/passes/unsafeptr: add tests using generics 49ce184 cmd/guru: remove use of deprecated ssa.CreateTestMainPackage fda06c1 gopls/internal/regtest/diagnostics: skip Test_Issue38211 c116b72 internal/lsp/lsprpc: increase timeout for TestEnvForwarding fc3ed20 internal/lsp: enable template processing and add templateFiles option e900012 go/callgraph/vta: represent type sets using tries 5e46725 internal/lsp: return all code action kinds with context.only prefix fafc446 go/internal/gccgoimporter: skip obj importer test on AIX a5321bf go/internal/gccgoimporter: skip installation test on AIX 0edd7b8 go/internal/gccgoimporter: fix up gccgo installation test e93be81 go/internal/gccgoimporter: use t.TempDir() in tests 17472e0 go/internal/gccgoimporter: change all .gox files to text c8e8de6 go/ssa: correct names of examples b766c28 internal/jsonrpc2: make Serve wait for all connections to close 2cdcc60 cmd: avoid printing redundant newlines 0c60b7c go/analysis/passes/printf: add test for generic printf wrappers ddcef59 go/analysis/passes/printf: warn about verbs that don’t match a type parameter’s type set b8b8e7f analysis/internal/facts: Updating facts for generics. 4ab7496 go/analysis/passes/copylock: avoid infinite recursion via type params 1c6f3cc go/analysis/passes/ctrlfow: rely on typeutil.StaticCallee 1ae27d3 internal/lsp/cache: don't offset invalid positions 6f75aad go/callgraph/vta: add trie implementation to VTA 84e69e7 go/analysis/passes/copylock: detect copylock in multi-assignment 68536fa internal/testenv: treat linux-riscv64-unmatched as a slow builder 012c320 internal/regtest: skip TestQuickFixEmptyFiles: it is too flaky 7e23819 internal/regtest: skip TestProgressBarErrors: it is too flaky 3b1a674 go/types/objectpath: temporarily comment-out some tests 714668c go/internal/gcimporter: remove skipSpecialPlatforms 9aacde2 go/internal/gcimporter: avoid printing to stderr in passing tests 6561d8c go/internal/gcimporter: skip Test{I,B}ExportData_stdlib in -short mode 182bbdc go/pointer: skip TestInput on 32-bit platforms f6440c8 x/tools: print check misses concatenated strings bb4add0 go/analysis/passes/printf: refactor and simplify matchArgType 1ba8fdb go/analysis/passes/errorsas: avoid type param on RHS of type decl 058ed05 go/analysis/passes/copylock: find locks via type parameters ebc40b3 go/pointer: replace use of deprecated CreateTestMainPackage API 4d06874 internal/testenv: treat dragonfly-amd64 as a slow machine ee08195 go/types/typeutil: Callee supports generics e8bb373 go/types/objectpath: fix testcase for the fix of TypeName.IsAlias b7d65fb go/types/objectpath: comment some testcase temporarily for the fix of TypeName.IsAlias 42daa65 go/analysis/passes/stringintconv: add support for type parameters 513e3fb cmd/godoc: deprecate and point to cmd/pkgsite 351c04c /internal/lsp/source: apply directory filters to workspace symbols a6c6f4b go/analysis/passes/nilfunc: add typeparams test a2be0cd go/analysis/passes/tests: update for generics 4d2571b go/analysis/passes/testinggoroutine: update for generics 96715ad internal/lsp: check for invalid URIs in definition 170abdd go/analysis/passes/stdmethods: add tests with generic receivers d6a9af8 godoc/analysis: remove deprecated analysis package e7eb6f6 go/analysis/passes/unusedresult: add test for typeparams c8ad2e1 go/analysis/passes/ctrlflow: add typeparams test 8de2a7f go/analysis/passes/sortslice: add missing functions using empty interface 9cd58b0 x/tools/cmd/stringer: adjust generics tests 7b0b504 go/analysis/passes/ifaceassert: add a typeparams test 58ba5e4 go/analysis/passes/internal/analysisutil: add a test for generic type assertions 1b02aa2 go/analysis/passes/shift: update for generics 08f2e89 gopls/api-diff: fix api-diff command for Go 1.18 d5520c2 internal/lsp/source: check for nil objects in call hierarchy e1e2965 all: update install commands to go install pkg@version 591e12a go/analysis/passes/cgocall: add typeparams test 26dbf47 go/analysis/passes/lostcancel: add typeparams test 9626607 all: update dependencies post-release 244f92e internal/lsp: do not send semantic tokens that client doesn't support c4ead46 go/analysis/passes/httpresponse: fix a testing issue 903c757 go/analysis/passes/httpresponse: add typeparams test f916b54 go/analysis,go/ssa: initialize the types.Info.Instances map 1050b5c go/analysis/passes/composite: update for generics 5a40697 tools/gopls: use `go install` instead of `go get` bcc6fa8 internal/typeparams: guard against generics in stdlib tests fc8b4ca go/internal/gcimporter: stub support importing/exporting constant kind 18096c5 go/internal/gcimporter: add support for the Go 1.18 export data version affba50 internal/lsp: temporarily strip subscripts from generic hover 316ba0b go/packages/packagestest: skip nested module directories in copying 6f2254e internal/lsp: adjust extract function range if block statement baf4e38 go/gcexportdata: limit reader to the export data section of the archive 4100dac go/analysis/passes/deepequalerrors: add typeparams test 9b675d0 gopls/doc: remove bad gopls cli link cbf1d01 go/internal/gcimporter: avoid setting unnecessary lines in fakeFileSet 4ea6123 internal/lsp: don't add multiple views for the same folder 81f084e go/internal/gcimporter: remove support for type parameters subscripts 3a9f390 gopls: update generics instructions to mention go.mod go directive 9f721e8 internal/lsp: fix data race in Templates code 1feb683 internal/lsp/analysis/infertypeargs: reduce diagnostic range 98f6e03 internal/lsp: disable fillstruct for type params 288d0b3 gopls: tidy go.mod file for go1.18 ce04ca3 go/internal/gcimporter: normalize implicit interfaces in export tests 3a269dc internal/typeparams: copy the term list algorithm from go/types e69ba9d internal/lsp/cache: fix incorrect detection of useless code 88e80df cmd/stringer: add a few tests using instantiated generic types Change-Id: Ie4b34cafc81a488de650019f874287558f9a8d70
2 parents e08545a + 8122e49 commit bca115b

File tree

206 files changed

+6741
-2813
lines changed

Some content is hidden

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

206 files changed

+6741
-2813
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ Some of the tools, `godoc` and `vet` for example, are included in binary Go
99
distributions.
1010

1111
Others, including the Go `guru` and the test coverage tool, can be fetched with
12-
`go get`.
12+
`go install`.
1313

1414
Packages include a type-checker for Go and an implementation of the
1515
Static Single Assignment form (SSA) representation for Go programs.
1616

1717
## Download/Install
1818

19-
The easiest way to install is to run `go get -u golang.org/x/tools/...`. You can
20-
also manually git clone the repository to `$GOPATH/src/golang.org/x/tools`.
19+
The easiest way to install is to run `go install golang.org/x/tools/...@latest`.
2120

2221
## JS/CSS Formatting
2322

cmd/callgraph/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ var stdout io.Writer = os.Stdout
166166

167167
func doCallgraph(dir, gopath, algo, format string, tests bool, args []string) error {
168168
if len(args) == 0 {
169-
fmt.Fprintln(os.Stderr, Usage)
169+
fmt.Fprint(os.Stderr, Usage)
170170
return nil
171171
}
172172

cmd/cover/cover.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Finally, to generate modified source code with coverage annotations
4242
`
4343

4444
func usage() {
45-
fmt.Fprintln(os.Stderr, usageMessage)
46-
fmt.Fprintln(os.Stderr, "Flags:")
45+
fmt.Fprint(os.Stderr, usageMessage)
46+
fmt.Fprintln(os.Stderr, "\nFlags:")
4747
flag.PrintDefaults()
4848
fmt.Fprintln(os.Stderr, "\n Only one of -html, -func, or -mode may be set.")
4949
os.Exit(2)

cmd/eg/eg.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func doMain() error {
5959
args := flag.Args()
6060

6161
if *helpFlag {
62-
fmt.Fprint(os.Stderr, eg.Help)
62+
help := eg.Help // hide %s from vet
63+
fmt.Fprint(os.Stderr, help)
6364
os.Exit(2)
6465
}
6566

cmd/godoc/doc.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ The flags are:
5252
Go root directory
5353
-http=addr
5454
HTTP service address (e.g., '127.0.0.1:6060' or just ':6060')
55-
-analysis=type,pointer
56-
comma-separated list of analyses to perform
57-
"type": display identifier resolution, type info, method sets,
58-
'implements', and static callees
59-
"pointer": display channel peers, callers and dynamic callees
60-
(significantly slower)
61-
See https://golang.org/lib/godoc/analysis/help.html for details.
6255
-templates=""
6356
directory containing alternate template files; if set,
6457
the directory may provide alternative template files
@@ -115,5 +108,7 @@ see https://golang.org/pkg/testing/#hdr-Examples for the conventions.
115108
See "Godoc: documenting Go code" for how to write good comments for godoc:
116109
https://golang.org/doc/articles/godoc_documenting_go_code.html
117110
111+
// Deprecated: godoc cannot select what version of a package is displayed.
112+
// Instead, use golang.org/x/pkgsite/cmd/pkgsite.
118113
*/
119114
package main // import "golang.org/x/tools/cmd/godoc"

cmd/godoc/godoc_test.go

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
package main_test
66

77
import (
8-
"bufio"
98
"bytes"
109
"fmt"
1110
"go/build"
12-
"io"
1311
"io/ioutil"
1412
"net"
1513
"net/http"
@@ -479,135 +477,3 @@ func TestNoMainModule(t *testing.T) {
479477
t.Errorf("stderr contains 'go mod download', is that intentional?\nstderr=%q", stderr.String())
480478
}
481479
}
482-
483-
// Basic integration test for godoc -analysis=type (via HTTP interface).
484-
func TestTypeAnalysis(t *testing.T) {
485-
bin, cleanup := buildGodoc(t)
486-
defer cleanup()
487-
testTypeAnalysis(t, packagestest.GOPATH, bin)
488-
// TODO(golang.org/issue/34473): Add support for type, pointer
489-
// analysis in module mode, then enable its test coverage here.
490-
}
491-
func testTypeAnalysis(t *testing.T, x packagestest.Exporter, bin string) {
492-
if runtime.GOOS == "plan9" {
493-
t.Skip("skipping test on plan9 (issue #11974)") // see comment re: Plan 9 below
494-
}
495-
496-
// Write a fake GOROOT/GOPATH.
497-
// TODO(golang.org/issue/34473): This test uses import paths without a dot in first
498-
// path element. This is not viable in module mode; import paths will need to change.
499-
e := packagestest.Export(t, x, []packagestest.Module{
500-
{
501-
Name: "app",
502-
Files: map[string]interface{}{
503-
"main.go": `
504-
package main
505-
import "lib"
506-
func main() { print(lib.V) }
507-
`,
508-
},
509-
},
510-
{
511-
Name: "lib",
512-
Files: map[string]interface{}{
513-
"lib.go": `
514-
package lib
515-
type T struct{}
516-
const C = 3
517-
var V T
518-
func (T) F() int { return C }
519-
`,
520-
},
521-
},
522-
})
523-
goroot := filepath.Join(e.Temp(), "goroot")
524-
if err := os.Mkdir(goroot, 0755); err != nil {
525-
t.Fatalf("os.Mkdir(%q) failed: %v", goroot, err)
526-
}
527-
defer e.Cleanup()
528-
529-
// Start the server.
530-
addr := serverAddress(t)
531-
cmd := exec.Command(bin, fmt.Sprintf("-http=%s", addr), "-analysis=type")
532-
cmd.Dir = e.Config.Dir
533-
// Point to an empty GOROOT directory to speed things up
534-
// by not doing type analysis for the entire real GOROOT.
535-
// TODO(golang.org/issue/34473): This test optimization may not be viable in module mode.
536-
cmd.Env = append(e.Config.Env, fmt.Sprintf("GOROOT=%s", goroot))
537-
cmd.Stdout = os.Stderr
538-
stderr, err := cmd.StderrPipe()
539-
if err != nil {
540-
t.Fatal(err)
541-
}
542-
cmd.Args[0] = "godoc"
543-
if err := cmd.Start(); err != nil {
544-
t.Fatalf("failed to start godoc: %s", err)
545-
}
546-
defer killAndWait(cmd)
547-
waitForServerReady(t, cmd, addr)
548-
549-
// Wait for type analysis to complete.
550-
reader := bufio.NewReader(stderr)
551-
for {
552-
s, err := reader.ReadString('\n') // on Plan 9 this fails
553-
if err != nil {
554-
t.Fatal(err)
555-
}
556-
fmt.Fprint(os.Stderr, s)
557-
if strings.Contains(s, "Type analysis complete.") {
558-
break
559-
}
560-
}
561-
go io.Copy(os.Stderr, reader)
562-
563-
t0 := time.Now()
564-
565-
// Make an HTTP request and check for a regular expression match.
566-
// The patterns are very crude checks that basic type information
567-
// has been annotated onto the source view.
568-
tryagain:
569-
for _, test := range []struct{ url, pattern string }{
570-
{"/src/lib/lib.go", "L2.*package .*Package docs for lib.*/lib"},
571-
{"/src/lib/lib.go", "L3.*type .*type info for T.*struct"},
572-
{"/src/lib/lib.go", "L5.*var V .*type T struct"},
573-
{"/src/lib/lib.go", "L6.*func .*type T struct.*T.*return .*const C untyped int.*C"},
574-
575-
{"/src/app/main.go", "L2.*package .*Package docs for app"},
576-
{"/src/app/main.go", "L3.*import .*Package docs for lib.*lib"},
577-
{"/src/app/main.go", "L4.*func main.*package lib.*lib.*var lib.V lib.T.*V"},
578-
} {
579-
url := fmt.Sprintf("http://%s%s", addr, test.url)
580-
resp, err := http.Get(url)
581-
if err != nil {
582-
t.Errorf("GET %s failed: %s", url, err)
583-
continue
584-
}
585-
body, err := ioutil.ReadAll(resp.Body)
586-
resp.Body.Close()
587-
if err != nil {
588-
t.Errorf("GET %s: failed to read body: %s (response: %v)", url, err, resp)
589-
continue
590-
}
591-
592-
if !bytes.Contains(body, []byte("Static analysis features")) {
593-
// Type analysis results usually become available within
594-
// ~4ms after godoc startup (for this input on my machine).
595-
if elapsed := time.Since(t0); elapsed > 500*time.Millisecond {
596-
t.Fatalf("type analysis results still unavailable after %s", elapsed)
597-
}
598-
time.Sleep(10 * time.Millisecond)
599-
goto tryagain
600-
}
601-
602-
match, err := regexp.Match(test.pattern, body)
603-
if err != nil {
604-
t.Errorf("regexp.Match(%q) failed: %s", test.pattern, err)
605-
continue
606-
}
607-
if !match {
608-
// This is a really ugly failure message.
609-
t.Errorf("GET %s: body doesn't match %q, got:\n%s",
610-
url, test.pattern, string(body))
611-
}
612-
}
613-
}

cmd/godoc/main.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"flag"
2626
"fmt"
2727
"go/build"
28-
exec "golang.org/x/sys/execabs"
2928
"io"
3029
"log"
3130
"net/http"
@@ -38,8 +37,9 @@ import (
3837
"runtime"
3938
"strings"
4039

40+
exec "golang.org/x/sys/execabs"
41+
4142
"golang.org/x/tools/godoc"
42-
"golang.org/x/tools/godoc/analysis"
4343
"golang.org/x/tools/godoc/static"
4444
"golang.org/x/tools/godoc/vfs"
4545
"golang.org/x/tools/godoc/vfs/gatefs"
@@ -59,8 +59,6 @@ var (
5959
// file-based index
6060
writeIndex = flag.Bool("write_index", false, "write index to a file; the file name must be specified with -index_files")
6161

62-
analysisFlag = flag.String("analysis", "", `comma-separated list of analyses to perform when in GOPATH mode (supported: type, pointer). See https://golang.org/lib/godoc/analysis/help.html`)
63-
6462
// network
6563
httpAddr = flag.String("http", defaultAddr, "HTTP service address")
6664

@@ -208,12 +206,6 @@ func main() {
208206
if goModFile != "" {
209207
fmt.Printf("using module mode; GOMOD=%s\n", goModFile)
210208

211-
if *analysisFlag != "" {
212-
fmt.Fprintln(os.Stderr, "The -analysis flag is supported only in GOPATH mode at this time.")
213-
fmt.Fprintln(os.Stderr, "See https://golang.org/issue/34473.")
214-
usage()
215-
}
216-
217209
// Detect whether to use vendor mode or not.
218210
mainMod, vendorEnabled, err := gocommand.VendorEnabled(context.Background(), gocommand.Invocation{}, &gocommand.Runner{})
219211
if err != nil {
@@ -266,20 +258,6 @@ func main() {
266258
}
267259
}
268260

269-
var typeAnalysis, pointerAnalysis bool
270-
if *analysisFlag != "" {
271-
for _, a := range strings.Split(*analysisFlag, ",") {
272-
switch a {
273-
case "type":
274-
typeAnalysis = true
275-
case "pointer":
276-
pointerAnalysis = true
277-
default:
278-
log.Fatalf("unknown analysis: %s", a)
279-
}
280-
}
281-
}
282-
283261
var corpus *godoc.Corpus
284262
if goModFile != "" {
285263
corpus = godoc.NewCorpus(moduleFS{fs})
@@ -376,11 +354,6 @@ func main() {
376354
go corpus.RunIndexer()
377355
}
378356

379-
// Start type/pointer analysis.
380-
if typeAnalysis || pointerAnalysis {
381-
go analysis.Run(pointerAnalysis, &corpus.Analysis)
382-
}
383-
384357
// Start http server.
385358
if *verbose {
386359
log.Println("starting HTTP server")

cmd/gomvpkg/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func main() {
8383
}
8484

8585
if *helpFlag || *fromFlag == "" || *toFlag == "" {
86-
fmt.Println(Usage)
86+
fmt.Print(Usage)
8787
return
8888
}
8989

cmd/gorename/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func main() {
4646
}
4747

4848
if *helpFlag || (*offsetFlag == "" && *fromFlag == "" && *toFlag == "") {
49-
fmt.Println(rename.Usage)
49+
fmt.Print(rename.Usage)
5050
return
5151
}
5252

cmd/gotype/gotype.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ files to include for such packages.
167167
`
168168

169169
func usage() {
170-
fmt.Fprintln(os.Stderr, usageString)
170+
fmt.Fprint(os.Stderr, usageString)
171+
fmt.Fprintln(os.Stderr)
171172
flag.PrintDefaults()
172173
os.Exit(2)
173174
}

0 commit comments

Comments
 (0)