internal/lsp/source/completion: remove unused contexts
This change removes contexts from functions that don't use them. Passing
down context unnecessarily leads to us having to propagate them
everywhere.
Change-Id: I1723721faf4f487b6cc92b9daef3f23747d9cbc1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258285
Trust: Danish Dua <danishdua@google.com>
Run-TryBot: Danish Dua <danishdua@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
diff --git a/internal/lsp/source/completion/completion.go b/internal/lsp/source/completion/completion.go
index 9f8f428..bd157e6 100644
--- a/internal/lsp/source/completion/completion.go
+++ b/internal/lsp/source/completion/completion.go
@@ -575,7 +575,7 @@
}
if lt := c.wantLabelCompletion(); lt != labelNone {
- c.labels(ctx, lt)
+ c.labels(lt)
return nil
}
@@ -1065,7 +1065,7 @@
// Is sel a qualified identifier?
if id, ok := sel.X.(*ast.Ident); ok {
if pkgName, ok := c.pkg.GetTypesInfo().Uses[id].(*types.PkgName); ok {
- candidates := c.packageMembers(ctx, pkgName.Imported(), stdScore, nil)
+ candidates := c.packageMembers(pkgName.Imported(), stdScore, nil)
for _, cand := range candidates {
c.deepState.enqueue(cand)
}
@@ -1076,7 +1076,7 @@
// Invariant: sel is a true selector.
tv, ok := c.pkg.GetTypesInfo().Types[sel.X]
if ok {
- candidates := c.methodsAndFields(ctx, tv.Type, tv.Addressable(), nil)
+ candidates := c.methodsAndFields(tv.Type, tv.Addressable(), nil)
for _, cand := range candidates {
c.deepState.enqueue(cand)
}
@@ -1133,7 +1133,7 @@
if imports.ImportPathToAssumedName(path) != pkg.GetTypes().Name() {
imp.name = pkg.GetTypes().Name()
}
- candidates := c.packageMembers(ctx, pkg.GetTypes(), unimportedScore(relevances[path]), imp)
+ candidates := c.packageMembers(pkg.GetTypes(), unimportedScore(relevances[path]), imp)
for _, cand := range candidates {
c.deepState.enqueue(cand)
}
@@ -1183,7 +1183,7 @@
return (stdScore + .1*float64(relevance)) / 2
}
-func (c *completer) packageMembers(ctx context.Context, pkg *types.Package, score float64, imp *importInfo) []candidate {
+func (c *completer) packageMembers(pkg *types.Package, score float64, imp *importInfo) []candidate {
var candidates []candidate
scope := pkg.Scope()
for _, name := range scope.Names() {
@@ -1198,7 +1198,7 @@
return candidates
}
-func (c *completer) methodsAndFields(ctx context.Context, typ types.Type, addressable bool, imp *importInfo) []candidate {
+func (c *completer) methodsAndFields(typ types.Type, addressable bool, imp *importInfo) []candidate {
mset := c.methodSetCache[methodSetKey{typ, addressable}]
if mset == nil {
if addressable && !types.IsInterface(typ) && !isPointer(typ) {
diff --git a/internal/lsp/source/completion/completion_format.go b/internal/lsp/source/completion/completion_format.go
index 6f18e51..9549f87 100644
--- a/internal/lsp/source/completion/completion_format.go
+++ b/internal/lsp/source/completion/completion_format.go
@@ -104,7 +104,7 @@
// If this candidate needs an additional import statement,
// add the additional text edits needed.
if cand.imp != nil {
- addlEdits, err := c.importEdits(ctx, cand.imp)
+ addlEdits, err := c.importEdits(cand.imp)
if err != nil {
return CompletionItem{}, err
}
@@ -211,7 +211,7 @@
}
// importEdits produces the text edits necessary to add the given import to the current file.
-func (c *completer) importEdits(ctx context.Context, imp *importInfo) ([]protocol.TextEdit, error) {
+func (c *completer) importEdits(imp *importInfo) ([]protocol.TextEdit, error) {
if imp == nil {
return nil, nil
}
@@ -221,7 +221,7 @@
return nil, err
}
- return source.ComputeOneImportFixEdits(ctx, c.snapshot, pgf, &imports.ImportFix{
+ return source.ComputeOneImportFixEdits(c.snapshot, pgf, &imports.ImportFix{
StmtInfo: imports.ImportInfo{
ImportPath: imp.importPath,
Name: imp.name,
diff --git a/internal/lsp/source/completion/completion_labels.go b/internal/lsp/source/completion/completion_labels.go
index 2d4bdb9..e4fd961 100644
--- a/internal/lsp/source/completion/completion_labels.go
+++ b/internal/lsp/source/completion/completion_labels.go
@@ -5,7 +5,6 @@
package completion
import (
- "context"
"go/ast"
"go/token"
"math"
@@ -50,7 +49,7 @@
// labels adds completion items for labels defined in the enclosing
// function.
-func (c *completer) labels(ctx context.Context, lt labelType) {
+func (c *completer) labels(lt labelType) {
if c.enclosingFunc == nil {
return
}
diff --git a/internal/lsp/source/completion/completion_literal.go b/internal/lsp/source/completion/completion_literal.go
index 7582e57..e7ebc6e 100644
--- a/internal/lsp/source/completion/completion_literal.go
+++ b/internal/lsp/source/completion/completion_literal.go
@@ -98,7 +98,7 @@
matchName = types.TypeString(t.Elem(), qf)
}
- addlEdits, err := c.importEdits(ctx, imp)
+ addlEdits, err := c.importEdits(imp)
if err != nil {
event.Error(ctx, "error adding import for literal candidate", err)
return
diff --git a/internal/lsp/source/completion/completion_package.go b/internal/lsp/source/completion/completion_package.go
index f9d30d5..f8d3431 100644
--- a/internal/lsp/source/completion/completion_package.go
+++ b/internal/lsp/source/completion/completion_package.go
@@ -41,7 +41,7 @@
return nil, nil, err
}
- surrounding, err := packageCompletionSurrounding(ctx, snapshot.FileSet(), fh, pgf, rng.Start)
+ surrounding, err := packageCompletionSurrounding(snapshot.FileSet(), fh, pgf, rng.Start)
if err != nil {
return nil, nil, errors.Errorf("invalid position for package completion: %w", err)
}
@@ -68,7 +68,7 @@
// packageCompletionSurrounding returns surrounding for package completion if a
// package completions can be suggested at a given position. A valid location
// for package completion is above any declarations or import statements.
-func packageCompletionSurrounding(ctx context.Context, fset *token.FileSet, fh source.FileHandle, pgf *source.ParsedGoFile, pos token.Pos) (*Selection, error) {
+func packageCompletionSurrounding(fset *token.FileSet, fh source.FileHandle, pgf *source.ParsedGoFile, pos token.Pos) (*Selection, error) {
src, err := fh.Read()
if err != nil {
return nil, err
diff --git a/internal/lsp/source/completion/deep_completion.go b/internal/lsp/source/completion/deep_completion.go
index ec485f2..da8c117 100644
--- a/internal/lsp/source/completion/deep_completion.go
+++ b/internal/lsp/source/completion/deep_completion.go
@@ -196,7 +196,7 @@
if sig.Params().Len() == 0 && sig.Results().Len() == 1 {
path, names := c.deepState.newPath(cand, obj, true)
// The result of a function call is not addressable.
- candidates := c.methodsAndFields(ctx, sig.Results().At(0).Type(), false, cand.imp)
+ candidates := c.methodsAndFields(sig.Results().At(0).Type(), false, cand.imp)
for _, newCand := range candidates {
newCand.path, newCand.names = path, names
c.deepState.enqueue(newCand)
@@ -207,13 +207,13 @@
path, names := c.deepState.newPath(cand, obj, false)
switch obj := obj.(type) {
case *types.PkgName:
- candidates := c.packageMembers(ctx, obj.Imported(), stdScore, cand.imp)
+ candidates := c.packageMembers(obj.Imported(), stdScore, cand.imp)
for _, newCand := range candidates {
newCand.path, newCand.names = path, names
c.deepState.enqueue(newCand)
}
default:
- candidates := c.methodsAndFields(ctx, obj.Type(), cand.addressable, cand.imp)
+ candidates := c.methodsAndFields(obj.Type(), cand.addressable, cand.imp)
for _, newCand := range candidates {
newCand.path, newCand.names = path, names
c.deepState.enqueue(newCand)
diff --git a/internal/lsp/source/format.go b/internal/lsp/source/format.go
index bd669b4..5d25d18 100644
--- a/internal/lsp/source/format.go
+++ b/internal/lsp/source/format.go
@@ -134,7 +134,7 @@
}
// ComputeOneImportFixEdits returns text edits for a single import fix.
-func ComputeOneImportFixEdits(ctx context.Context, snapshot Snapshot, pgf *ParsedGoFile, fix *imports.ImportFix) ([]protocol.TextEdit, error) {
+func ComputeOneImportFixEdits(snapshot Snapshot, pgf *ParsedGoFile, fix *imports.ImportFix) ([]protocol.TextEdit, error) {
options := &imports.Options{
LocalPrefix: snapshot.View().Options().Local,
// Defaults.