Skip to content

Commit

Permalink
internal/imports: repair warnings from default analyzers
Browse files Browse the repository at this point in the history
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 <heschi@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
pjweinbgo committed Oct 19, 2022
1 parent bc2e3ae commit d67c3ad
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 162 deletions.
4 changes: 2 additions & 2 deletions internal/imports/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -1372,9 +1372,9 @@ func (r *gopathResolver) scan(ctx context.Context, callback *scanCallback) error
return err
}
var roots []gopathwalk.Root
roots = append(roots, gopathwalk.Root{filepath.Join(goenv["GOROOT"], "src"), gopathwalk.RootGOROOT})
roots = append(roots, gopathwalk.Root{Path: filepath.Join(goenv["GOROOT"], "src"), Type: gopathwalk.RootGOROOT})
for _, p := range filepath.SplitList(goenv["GOPATH"]) {
roots = append(roots, gopathwalk.Root{filepath.Join(p, "src"), gopathwalk.RootGOPATH})
roots = append(roots, gopathwalk.Root{Path: filepath.Join(p, "src"), Type: gopathwalk.RootGOPATH})
}
// The callback is not necessarily safe to use in the goroutine below. Process roots eagerly.
roots = filterRoots(roots, callback.rootFound)
Expand Down
7 changes: 6 additions & 1 deletion internal/imports/mkstdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func main() {
outf := func(format string, args ...interface{}) {
fmt.Fprintf(&buf, format, args...)
}
outf(`// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
`)
outf("// Code generated by mkstdlib.go. DO NOT EDIT.\n\n")
outf("package imports\n")
outf("var stdlib = map[string][]string{\n")
Expand Down Expand Up @@ -77,7 +82,7 @@ func main() {
}
sort.Strings(paths)
for _, path := range paths {
outf("\t%q: []string{\n", path)
outf("\t%q: {\n", path)
pkg := pkgs[path]
var syms []string
for sym := range pkg {
Expand Down
12 changes: 6 additions & 6 deletions internal/imports/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,22 @@ func (r *ModuleResolver) init() error {
})

r.roots = []gopathwalk.Root{
{filepath.Join(goenv["GOROOT"], "/src"), gopathwalk.RootGOROOT},
{Path: filepath.Join(goenv["GOROOT"], "/src"), Type: gopathwalk.RootGOROOT},
}
r.mainByDir = make(map[string]*gocommand.ModuleJSON)
for _, main := range r.mains {
r.roots = append(r.roots, gopathwalk.Root{main.Dir, gopathwalk.RootCurrentModule})
r.roots = append(r.roots, gopathwalk.Root{Path: main.Dir, Type: gopathwalk.RootCurrentModule})
r.mainByDir[main.Dir] = main
}
if vendorEnabled {
r.roots = append(r.roots, gopathwalk.Root{r.dummyVendorMod.Dir, gopathwalk.RootOther})
r.roots = append(r.roots, gopathwalk.Root{Path: r.dummyVendorMod.Dir, Type: gopathwalk.RootOther})
} else {
addDep := func(mod *gocommand.ModuleJSON) {
if mod.Replace == nil {
// This is redundant with the cache, but we'll skip it cheaply enough.
r.roots = append(r.roots, gopathwalk.Root{mod.Dir, gopathwalk.RootModuleCache})
r.roots = append(r.roots, gopathwalk.Root{Path: mod.Dir, Type: gopathwalk.RootModuleCache})
} else {
r.roots = append(r.roots, gopathwalk.Root{mod.Dir, gopathwalk.RootOther})
r.roots = append(r.roots, gopathwalk.Root{Path: mod.Dir, Type: gopathwalk.RootOther})
}
}
// Walk dependent modules before scanning the full mod cache, direct deps first.
Expand All @@ -158,7 +158,7 @@ func (r *ModuleResolver) init() error {
addDep(mod)
}
}
r.roots = append(r.roots, gopathwalk.Root{r.moduleCacheDir, gopathwalk.RootModuleCache})
r.roots = append(r.roots, gopathwalk.Root{Path: r.moduleCacheDir, Type: gopathwalk.RootModuleCache})
}

r.scannedRoots = map[gopathwalk.Root]bool{}
Expand Down
Loading

0 comments on commit d67c3ad

Please sign in to comment.