Skip to content

Commit d67c3ad

Browse files
committed
internal/imports: repair warnings from default analyzers
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 <[email protected]> Run-TryBot: Peter Weinberger <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent bc2e3ae commit d67c3ad

File tree

4 files changed

+171
-162
lines changed

4 files changed

+171
-162
lines changed

internal/imports/fix.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1372,9 +1372,9 @@ func (r *gopathResolver) scan(ctx context.Context, callback *scanCallback) error
13721372
return err
13731373
}
13741374
var roots []gopathwalk.Root
1375-
roots = append(roots, gopathwalk.Root{filepath.Join(goenv["GOROOT"], "src"), gopathwalk.RootGOROOT})
1375+
roots = append(roots, gopathwalk.Root{Path: filepath.Join(goenv["GOROOT"], "src"), Type: gopathwalk.RootGOROOT})
13761376
for _, p := range filepath.SplitList(goenv["GOPATH"]) {
1377-
roots = append(roots, gopathwalk.Root{filepath.Join(p, "src"), gopathwalk.RootGOPATH})
1377+
roots = append(roots, gopathwalk.Root{Path: filepath.Join(p, "src"), Type: gopathwalk.RootGOPATH})
13781378
}
13791379
// The callback is not necessarily safe to use in the goroutine below. Process roots eagerly.
13801380
roots = filterRoots(roots, callback.rootFound)

internal/imports/mkstdlib.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func main() {
4949
outf := func(format string, args ...interface{}) {
5050
fmt.Fprintf(&buf, format, args...)
5151
}
52+
outf(`// Copyright 2022 The Go Authors. All rights reserved.
53+
// Use of this source code is governed by a BSD-style
54+
// license that can be found in the LICENSE file.
55+
56+
`)
5257
outf("// Code generated by mkstdlib.go. DO NOT EDIT.\n\n")
5358
outf("package imports\n")
5459
outf("var stdlib = map[string][]string{\n")
@@ -77,7 +82,7 @@ func main() {
7782
}
7883
sort.Strings(paths)
7984
for _, path := range paths {
80-
outf("\t%q: []string{\n", path)
85+
outf("\t%q: {\n", path)
8186
pkg := pkgs[path]
8287
var syms []string
8388
for sym := range pkg {

internal/imports/mod.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,22 @@ func (r *ModuleResolver) init() error {
129129
})
130130

131131
r.roots = []gopathwalk.Root{
132-
{filepath.Join(goenv["GOROOT"], "/src"), gopathwalk.RootGOROOT},
132+
{Path: filepath.Join(goenv["GOROOT"], "/src"), Type: gopathwalk.RootGOROOT},
133133
}
134134
r.mainByDir = make(map[string]*gocommand.ModuleJSON)
135135
for _, main := range r.mains {
136-
r.roots = append(r.roots, gopathwalk.Root{main.Dir, gopathwalk.RootCurrentModule})
136+
r.roots = append(r.roots, gopathwalk.Root{Path: main.Dir, Type: gopathwalk.RootCurrentModule})
137137
r.mainByDir[main.Dir] = main
138138
}
139139
if vendorEnabled {
140-
r.roots = append(r.roots, gopathwalk.Root{r.dummyVendorMod.Dir, gopathwalk.RootOther})
140+
r.roots = append(r.roots, gopathwalk.Root{Path: r.dummyVendorMod.Dir, Type: gopathwalk.RootOther})
141141
} else {
142142
addDep := func(mod *gocommand.ModuleJSON) {
143143
if mod.Replace == nil {
144144
// This is redundant with the cache, but we'll skip it cheaply enough.
145-
r.roots = append(r.roots, gopathwalk.Root{mod.Dir, gopathwalk.RootModuleCache})
145+
r.roots = append(r.roots, gopathwalk.Root{Path: mod.Dir, Type: gopathwalk.RootModuleCache})
146146
} else {
147-
r.roots = append(r.roots, gopathwalk.Root{mod.Dir, gopathwalk.RootOther})
147+
r.roots = append(r.roots, gopathwalk.Root{Path: mod.Dir, Type: gopathwalk.RootOther})
148148
}
149149
}
150150
// Walk dependent modules before scanning the full mod cache, direct deps first.
@@ -158,7 +158,7 @@ func (r *ModuleResolver) init() error {
158158
addDep(mod)
159159
}
160160
}
161-
r.roots = append(r.roots, gopathwalk.Root{r.moduleCacheDir, gopathwalk.RootModuleCache})
161+
r.roots = append(r.roots, gopathwalk.Root{Path: r.moduleCacheDir, Type: gopathwalk.RootModuleCache})
162162
}
163163

164164
r.scannedRoots = map[gopathwalk.Root]bool{}

0 commit comments

Comments
 (0)