mirror of https://github.com/golang/go.git
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>
This commit is contained in:
parent
c43c25c95a
commit
bce87a7896
|
|
@ -575,7 +575,7 @@ func (c *completer) collectCompletions(ctx context.Context) error {
|
|||
}
|
||||
|
||||
if lt := c.wantLabelCompletion(); lt != labelNone {
|
||||
c.labels(ctx, lt)
|
||||
c.labels(lt)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -1065,7 +1065,7 @@ func (c *completer) selector(ctx context.Context, sel *ast.SelectorExpr) error {
|
|||
// 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 @@ func (c *completer) selector(ctx context.Context, sel *ast.SelectorExpr) error {
|
|||
// 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 @@ func (c *completer) unimportedMembers(ctx context.Context, id *ast.Ident) error
|
|||
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 @@ func unimportedScore(relevance int) float64 {
|
|||
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 @@ func (c *completer) packageMembers(ctx context.Context, pkg *types.Package, scor
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ func (c *completer) item(ctx context.Context, cand candidate) (CompletionItem, e
|
|||
// 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 @@ func (c *completer) item(ctx context.Context, cand candidate) (CompletionItem, e
|
|||
}
|
||||
|
||||
// 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 @@ func (c *completer) importEdits(ctx context.Context, imp *importInfo) ([]protoco
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
package completion
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go/ast"
|
||||
"go/token"
|
||||
"math"
|
||||
|
|
@ -50,7 +49,7 @@ func takesLabel(n ast.Node) labelType {
|
|||
|
||||
// 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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ func (c *completer) literal(ctx context.Context, literalType types.Type, imp *im
|
|||
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
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func packageClauseCompletions(ctx context.Context, snapshot source.Snapshot, fh
|
|||
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 @@ func packageClauseCompletions(ctx context.Context, snapshot source.Snapshot, fh
|
|||
// 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
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ outer:
|
|||
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 @@ outer:
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ func computeImportEdits(ctx context.Context, snapshot Snapshot, pgf *ParsedGoFil
|
|||
}
|
||||
|
||||
// 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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue