mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
internal/lsp: address staticcheck warnings
Change-Id: I67c689d31b61425b1eec8b4719e906ce26777759 Reviewed-on: https://go-review.googlesource.com/c/tools/+/198441 Reviewed-by: Ian Cottrell <iancottrell@google.com> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
87e6e099c6
commit
f0a16743a2
18
internal/lsp/cache/builtin.go
vendored
18
internal/lsp/cache/builtin.go
vendored
@ -28,8 +28,8 @@ func (b *builtinPkg) Files() []source.ParseGoHandle {
|
||||
// buildBuiltinPkg builds the view's builtin package.
|
||||
// It assumes that the view is not active yet,
|
||||
// i.e. it has not been added to the session's list of views.
|
||||
func (view *view) buildBuiltinPackage(ctx context.Context) error {
|
||||
cfg := view.Config(ctx)
|
||||
func (v *view) buildBuiltinPackage(ctx context.Context) error {
|
||||
cfg := v.Config(ctx)
|
||||
pkgs, err := packages.Load(cfg, "builtin")
|
||||
if err != nil {
|
||||
return err
|
||||
@ -40,19 +40,19 @@ func (view *view) buildBuiltinPackage(ctx context.Context) error {
|
||||
pkg := pkgs[0]
|
||||
files := make(map[string]*ast.File)
|
||||
for _, filename := range pkg.GoFiles {
|
||||
fh := view.session.GetFile(span.FileURI(filename), source.Go)
|
||||
ph := view.session.cache.ParseGoHandle(fh, source.ParseFull)
|
||||
view.builtin.files = append(view.builtin.files, ph)
|
||||
fh := v.session.GetFile(span.FileURI(filename), source.Go)
|
||||
ph := v.session.cache.ParseGoHandle(fh, source.ParseFull)
|
||||
v.builtin.files = append(v.builtin.files, ph)
|
||||
file, _, _, err := ph.Parse(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
files[filename] = file
|
||||
|
||||
view.ignoredURIsMu.Lock()
|
||||
view.ignoredURIs[span.NewURI(filename)] = struct{}{}
|
||||
view.ignoredURIsMu.Unlock()
|
||||
v.ignoredURIsMu.Lock()
|
||||
v.ignoredURIs[span.NewURI(filename)] = struct{}{}
|
||||
v.ignoredURIsMu.Unlock()
|
||||
}
|
||||
view.builtin.pkg, err = ast.NewPackage(cfg.Fset, files, nil, nil)
|
||||
v.builtin.pkg, err = ast.NewPackage(cfg.Fset, files, nil, nil)
|
||||
return err
|
||||
}
|
||||
|
1
internal/lsp/cache/external.go
vendored
1
internal/lsp/cache/external.go
vendored
@ -52,6 +52,7 @@ func (h *nativeFileHandle) Identity() source.FileIdentity {
|
||||
|
||||
func (h *nativeFileHandle) Read(ctx context.Context) ([]byte, string, error) {
|
||||
ctx, done := trace.StartSpan(ctx, "cache.nativeFileHandle.Read", telemetry.File.Of(h.identity.URI.Filename()))
|
||||
_ = ctx
|
||||
defer done()
|
||||
|
||||
ioLimit <- struct{}{}
|
||||
|
86
internal/lsp/cache/pkg.go
vendored
86
internal/lsp/cache/pkg.go
vendored
@ -56,12 +56,12 @@ type analysisEntry struct {
|
||||
*source.Action
|
||||
}
|
||||
|
||||
func (pkg *pkg) GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*source.Action, error) {
|
||||
pkg.mu.Lock()
|
||||
e, ok := pkg.analyses[a]
|
||||
func (p *pkg) GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*source.Action, error) {
|
||||
p.mu.Lock()
|
||||
e, ok := p.analyses[a]
|
||||
if ok {
|
||||
// cache hit
|
||||
pkg.mu.Unlock()
|
||||
p.mu.Unlock()
|
||||
|
||||
// wait for entry to become ready or the context to be cancelled
|
||||
select {
|
||||
@ -70,7 +70,7 @@ func (pkg *pkg) GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*sour
|
||||
// If errors other than cancelation/timeout become possible, it may
|
||||
// no longer be appropriate to always retry here.
|
||||
if !e.succeeded {
|
||||
return pkg.GetActionGraph(ctx, a)
|
||||
return p.GetActionGraph(ctx, a)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
@ -81,11 +81,11 @@ func (pkg *pkg) GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*sour
|
||||
done: make(chan struct{}),
|
||||
Action: &source.Action{
|
||||
Analyzer: a,
|
||||
Pkg: pkg,
|
||||
Pkg: p,
|
||||
},
|
||||
}
|
||||
pkg.analyses[a] = e
|
||||
pkg.mu.Unlock()
|
||||
p.analyses[a] = e
|
||||
p.mu.Unlock()
|
||||
|
||||
defer func() {
|
||||
// If we got an error, clear out our defunct cache entry. We don't cache
|
||||
@ -93,9 +93,9 @@ func (pkg *pkg) GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*sour
|
||||
// Currently the only possible error is context.Canceled, though, which
|
||||
// should also not be cached.
|
||||
if !e.succeeded {
|
||||
pkg.mu.Lock()
|
||||
delete(pkg.analyses, a)
|
||||
pkg.mu.Unlock()
|
||||
p.mu.Lock()
|
||||
delete(p.analyses, a)
|
||||
p.mu.Unlock()
|
||||
}
|
||||
|
||||
// Always close done so waiters don't get stuck.
|
||||
@ -107,7 +107,7 @@ func (pkg *pkg) GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*sour
|
||||
|
||||
// Add a dependency on each required analyzers.
|
||||
for _, req := range a.Requires {
|
||||
act, err := pkg.GetActionGraph(ctx, req)
|
||||
act, err := p.GetActionGraph(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -117,13 +117,13 @@ func (pkg *pkg) GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*sour
|
||||
// An analysis that consumes/produces facts
|
||||
// must run on the package's dependencies too.
|
||||
if len(a.FactTypes) > 0 {
|
||||
importPaths := make([]string, 0, len(pkg.imports))
|
||||
for importPath := range pkg.imports {
|
||||
importPaths := make([]string, 0, len(p.imports))
|
||||
for importPath := range p.imports {
|
||||
importPaths = append(importPaths, string(importPath))
|
||||
}
|
||||
sort.Strings(importPaths) // for determinism
|
||||
for _, importPath := range importPaths {
|
||||
dep, err := pkg.GetImport(ctx, importPath)
|
||||
dep, err := p.GetImport(ctx, importPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -139,20 +139,20 @@ func (pkg *pkg) GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*sour
|
||||
return e.Action, nil
|
||||
}
|
||||
|
||||
func (pkg *pkg) ID() string {
|
||||
return string(pkg.id)
|
||||
func (p *pkg) ID() string {
|
||||
return string(p.id)
|
||||
}
|
||||
|
||||
func (pkg *pkg) PkgPath() string {
|
||||
return string(pkg.pkgPath)
|
||||
func (p *pkg) PkgPath() string {
|
||||
return string(p.pkgPath)
|
||||
}
|
||||
|
||||
func (pkg *pkg) Files() []source.ParseGoHandle {
|
||||
return pkg.files
|
||||
func (p *pkg) Files() []source.ParseGoHandle {
|
||||
return p.files
|
||||
}
|
||||
|
||||
func (pkg *pkg) File(uri span.URI) (source.ParseGoHandle, error) {
|
||||
for _, ph := range pkg.Files() {
|
||||
func (p *pkg) File(uri span.URI) (source.ParseGoHandle, error) {
|
||||
for _, ph := range p.Files() {
|
||||
if ph.File().Identity().URI == uri {
|
||||
return ph, nil
|
||||
}
|
||||
@ -160,9 +160,9 @@ func (pkg *pkg) File(uri span.URI) (source.ParseGoHandle, error) {
|
||||
return nil, errors.Errorf("no ParseGoHandle for %s", uri)
|
||||
}
|
||||
|
||||
func (pkg *pkg) GetSyntax(ctx context.Context) []*ast.File {
|
||||
func (p *pkg) GetSyntax(ctx context.Context) []*ast.File {
|
||||
var syntax []*ast.File
|
||||
for _, ph := range pkg.files {
|
||||
for _, ph := range p.files {
|
||||
file, _, _, err := ph.Cached(ctx)
|
||||
if err == nil {
|
||||
syntax = append(syntax, file)
|
||||
@ -171,41 +171,41 @@ func (pkg *pkg) GetSyntax(ctx context.Context) []*ast.File {
|
||||
return syntax
|
||||
}
|
||||
|
||||
func (pkg *pkg) GetErrors() []packages.Error {
|
||||
return pkg.errors
|
||||
func (p *pkg) GetErrors() []packages.Error {
|
||||
return p.errors
|
||||
}
|
||||
|
||||
func (pkg *pkg) GetTypes() *types.Package {
|
||||
return pkg.types
|
||||
func (p *pkg) GetTypes() *types.Package {
|
||||
return p.types
|
||||
}
|
||||
|
||||
func (pkg *pkg) GetTypesInfo() *types.Info {
|
||||
return pkg.typesInfo
|
||||
func (p *pkg) GetTypesInfo() *types.Info {
|
||||
return p.typesInfo
|
||||
}
|
||||
|
||||
func (pkg *pkg) GetTypesSizes() types.Sizes {
|
||||
return pkg.typesSizes
|
||||
func (p *pkg) GetTypesSizes() types.Sizes {
|
||||
return p.typesSizes
|
||||
}
|
||||
|
||||
func (pkg *pkg) IsIllTyped() bool {
|
||||
return pkg.types == nil || pkg.typesInfo == nil || pkg.typesSizes == nil
|
||||
func (p *pkg) IsIllTyped() bool {
|
||||
return p.types == nil || p.typesInfo == nil || p.typesSizes == nil
|
||||
}
|
||||
|
||||
func (pkg *pkg) GetImport(ctx context.Context, pkgPath string) (source.Package, error) {
|
||||
if imp := pkg.imports[packagePath(pkgPath)]; imp != nil {
|
||||
func (p *pkg) GetImport(ctx context.Context, pkgPath string) (source.Package, error) {
|
||||
if imp := p.imports[packagePath(pkgPath)]; imp != nil {
|
||||
return imp, nil
|
||||
}
|
||||
// Don't return a nil pointer because that still satisfies the interface.
|
||||
return nil, errors.Errorf("no imported package for %s", pkgPath)
|
||||
}
|
||||
|
||||
func (pkg *pkg) SetDiagnostics(a *analysis.Analyzer, diags []source.Diagnostic) {
|
||||
pkg.diagMu.Lock()
|
||||
defer pkg.diagMu.Unlock()
|
||||
if pkg.diagnostics == nil {
|
||||
pkg.diagnostics = make(map[*analysis.Analyzer][]source.Diagnostic)
|
||||
func (p *pkg) SetDiagnostics(a *analysis.Analyzer, diags []source.Diagnostic) {
|
||||
p.diagMu.Lock()
|
||||
defer p.diagMu.Unlock()
|
||||
if p.diagnostics == nil {
|
||||
p.diagnostics = make(map[*analysis.Analyzer][]source.Diagnostic)
|
||||
}
|
||||
pkg.diagnostics[a] = diags
|
||||
p.diagnostics[a] = diags
|
||||
}
|
||||
|
||||
func (p *pkg) FindDiagnostic(pdiag protocol.Diagnostic) (*source.Diagnostic, error) {
|
||||
|
@ -44,13 +44,13 @@ Example: reformat this file:
|
||||
|
||||
// Run performs the check on the files specified by args and prints the
|
||||
// results to stdout.
|
||||
func (f *format) Run(ctx context.Context, args ...string) error {
|
||||
func (c *format) Run(ctx context.Context, args ...string) error {
|
||||
if len(args) == 0 {
|
||||
// no files, so no results
|
||||
return nil
|
||||
}
|
||||
// now we ready to kick things off
|
||||
conn, err := f.app.connect(ctx)
|
||||
conn, err := c.app.connect(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -82,19 +82,19 @@ func (f *format) Run(ctx context.Context, args ...string) error {
|
||||
}
|
||||
formatted := diff.ApplyEdits(string(file.mapper.Content), sedits)
|
||||
printIt := true
|
||||
if f.List {
|
||||
if c.List {
|
||||
printIt = false
|
||||
if len(edits) > 0 {
|
||||
fmt.Println(filename)
|
||||
}
|
||||
}
|
||||
if f.Write {
|
||||
if c.Write {
|
||||
printIt = false
|
||||
if len(edits) > 0 {
|
||||
ioutil.WriteFile(filename, []byte(formatted), 0644)
|
||||
}
|
||||
}
|
||||
if f.Diff {
|
||||
if c.Diff {
|
||||
printIt = false
|
||||
u := diff.ToUnified(filename+".orig", filename, string(file.mapper.Content), sedits)
|
||||
fmt.Print(u)
|
||||
|
@ -83,7 +83,7 @@ func (r *rename) Run(ctx context.Context, args ...string) error {
|
||||
|
||||
// Make output order predictable
|
||||
var keys []string
|
||||
for u, _ := range *we.Changes {
|
||||
for u := range *we.Changes {
|
||||
keys = append(keys, u)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
@ -62,7 +62,7 @@ func (r *runner) Diagnostics(t *testing.T, uri span.URI, want []source.Diagnosti
|
||||
delete(got, expect)
|
||||
}
|
||||
}
|
||||
for extra, _ := range got {
|
||||
for extra := range got {
|
||||
t.Errorf("extra diagnostic %q", extra)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package debug exports debug information for gopls.
|
||||
package debug
|
||||
|
||||
import (
|
||||
|
@ -137,7 +137,7 @@ func (r *rpcs) Metric(ctx context.Context, data telemetry.MetricData) {
|
||||
b = &rpcCodeBucket{Key: status}
|
||||
stats.Codes = append(stats.Codes, b)
|
||||
sort.Slice(stats.Codes, func(i int, j int) bool {
|
||||
return stats.Codes[i].Key < stats.Codes[i].Key
|
||||
return stats.Codes[i].Key < stats.Codes[j].Key
|
||||
})
|
||||
}
|
||||
b.Count = data.(*metric.Int64Data).Rows[i]
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
"golang.org/x/tools/internal/lsp/fuzzy"
|
||||
)
|
||||
|
||||
func ExampleFuzzyMatcher() {
|
||||
func ExampleMatcher() {
|
||||
pattern := "TEdit"
|
||||
candidates := []string{"fuzzy.TextEdit", "ArtEdit", "TED talks about IT"}
|
||||
|
||||
|
@ -210,7 +210,7 @@ func formatFieldList(ctx context.Context, v View, list *ast.FieldList) ([]string
|
||||
}
|
||||
typ := replacer.Replace(b.String())
|
||||
if len(p.Names) == 0 {
|
||||
result = append(result, fmt.Sprintf("%s", typ))
|
||||
result = append(result, typ)
|
||||
}
|
||||
for _, name := range p.Names {
|
||||
if name.Name != "" {
|
||||
@ -219,7 +219,7 @@ func formatFieldList(ctx context.Context, v View, list *ast.FieldList) ([]string
|
||||
}
|
||||
result = append(result, fmt.Sprintf("%s %s", name.Name, typ))
|
||||
} else {
|
||||
result = append(result, fmt.Sprintf("%s", typ))
|
||||
result = append(result, typ)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,8 +78,9 @@ func objectString(obj types.Object, qf types.Qualifier) string {
|
||||
}
|
||||
|
||||
func (d Declaration) hover(ctx context.Context) (*HoverInformation, error) {
|
||||
ctx, done := trace.StartSpan(ctx, "source.hover")
|
||||
_, done := trace.StartSpan(ctx, "source.hover")
|
||||
defer done()
|
||||
|
||||
obj := d.obj
|
||||
switch node := d.node.(type) {
|
||||
case *ast.ImportSpec:
|
||||
|
@ -612,7 +612,7 @@ func (r *runner) Reference(t *testing.T, src span.Span, itemList []span.Span) {
|
||||
t.Errorf("references failed: different lengths got %v want %v", len(got), len(want))
|
||||
}
|
||||
|
||||
for spn, _ := range got {
|
||||
for spn := range got {
|
||||
if !want[spn] {
|
||||
t.Errorf("references failed: incorrect references got %v want locations %v", got, want)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user