Skip to content

Commit 264b0a5

Browse files
committed
gopls/internal/golang/completion: modernize
This CL applies the modernizers to the completion code, and removes some ununsed functions. Change-Id: I67a309f752deee000b7f556707e76f08aff14b9f Reviewed-on: https://go-review.googlesource.com/c/tools/+/667196 Reviewed-by: Alan Donovan <[email protected]> Reviewed-by: Madeline Kalil <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 7c6d4c6 commit 264b0a5

File tree

4 files changed

+4
-61
lines changed

4 files changed

+4
-61
lines changed

gopls/internal/golang/completion/completion.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,7 @@ type candidate struct {
489489
}
490490

491491
func (c candidate) hasMod(mod typeModKind) bool {
492-
for _, m := range c.mods {
493-
if m == mod {
494-
return true
495-
}
496-
}
497-
return false
492+
return slices.Contains(c.mods, mod)
498493
}
499494

500495
// Completion returns a list of possible candidates for completion, given a
@@ -1487,7 +1482,6 @@ func (c *completer) selector(ctx context.Context, sel *ast.SelectorExpr) error {
14871482
}
14881483

14891484
for _, uri := range mp.CompiledGoFiles {
1490-
uri := uri
14911485
g.Go(func() error {
14921486
return quickParse(uri, mp, tooNew)
14931487
})

gopls/internal/golang/completion/deep_completion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestDeepCompletionIsHighScore(t *testing.T) {
2020
}
2121

2222
// Fill up with higher scores.
23-
for i := 0; i < MaxDeepCompletions; i++ {
23+
for range MaxDeepCompletions {
2424
if !s.isHighScore(10) {
2525
t.Error("10 should be high score")
2626
}

gopls/internal/golang/completion/labels.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"go/ast"
99
"go/token"
1010
"math"
11+
"slices"
1112
)
1213

1314
type labelType int
@@ -96,12 +97,7 @@ func (c *completer) labels(lt labelType) {
9697
// Only search into block-like nodes enclosing our "goto".
9798
// This prevents us from finding labels in nested blocks.
9899
case *ast.BlockStmt, *ast.CommClause, *ast.CaseClause:
99-
for _, p := range c.path {
100-
if n == p {
101-
return true
102-
}
103-
}
104-
return false
100+
return slices.Contains(c.path, n)
105101
case *ast.LabeledStmt:
106102
addLabel(highScore, n)
107103
}

gopls/internal/golang/completion/unify.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -189,29 +189,6 @@ func (u *unifier) set(x *types.TypeParam, t types.Type) {
189189
*u.handles[x] = t
190190
}
191191

192-
// unknowns returns the number of type parameters for which no type has been set yet.
193-
func (u *unifier) unknowns() int {
194-
n := 0
195-
for _, h := range u.handles {
196-
if *h == nil {
197-
n++
198-
}
199-
}
200-
return n
201-
}
202-
203-
// inferred returns the list of inferred types for the given type parameter list.
204-
// The result is never nil and has the same length as tparams; result types that
205-
// could not be inferred are nil. Corresponding type parameters and result types
206-
// have identical indices.
207-
func (u *unifier) inferred(tparams []*types.TypeParam) []types.Type {
208-
list := make([]types.Type, len(tparams))
209-
for i, x := range tparams {
210-
list[i] = u.at(x)
211-
}
212-
return list
213-
}
214-
215192
// asInterface returns the underlying type of x as an interface if
216193
// it is a non-type parameter interface. Otherwise it returns nil.
217194
func asInterface(x types.Type) (i *types.Interface) {
@@ -245,30 +222,6 @@ func identicalOrigin(x, y *types.Named) bool {
245222
return x.Origin().Obj() == y.Origin().Obj()
246223
}
247224

248-
func match(x, y types.Type) types.Type {
249-
// Common case: we don't have channels.
250-
if types.Identical(x, y) {
251-
return x
252-
}
253-
254-
// We may have channels that differ in direction only.
255-
if x, _ := x.(*types.Chan); x != nil {
256-
if y, _ := y.(*types.Chan); y != nil && types.Identical(x.Elem(), y.Elem()) {
257-
// We have channels that differ in direction only.
258-
// If there's an unrestricted channel, select the restricted one.
259-
switch {
260-
case x.Dir() == types.SendRecv:
261-
return y
262-
case y.Dir() == types.SendRecv:
263-
return x
264-
}
265-
}
266-
}
267-
268-
// types are different
269-
return nil
270-
}
271-
272225
func coreType(t types.Type) types.Type {
273226
t = types.Unalias(t)
274227
tpar, _ := t.(*types.TypeParam)

0 commit comments

Comments
 (0)