Skip to content

Commit 66afc1a

Browse files
muirdmfindleyr
authored andcommitted
gopls/completion: tweak fuzz handling to make its own MethodSet
I'm going to try changing methodsAndFields() to not use types.MethodSet anymore. The `*testing.F` handling depends on the MethodSet, so let's change it to make its own. Change-Id: Iba81a58eb66142ede87f2be9125ae08753fb1700 Reviewed-on: https://go-review.googlesource.com/c/tools/+/594235 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Joedian Reid <[email protected]> Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Run-TryBot: Muir Manders <[email protected]>
1 parent 7d92dd6 commit 66afc1a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

gopls/internal/golang/completion/completion.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,13 @@ func ignoreUnimportedCompletion(fix *imports.ImportFix) bool {
14961496
}
14971497

14981498
func (c *completer) methodsAndFields(typ types.Type, addressable bool, imp *importInfo, cb func(candidate)) {
1499+
if isStarTestingDotF(typ) {
1500+
// is that a sufficient test? (or is more care needed?)
1501+
if c.fuzz(typ, imp, cb) {
1502+
return
1503+
}
1504+
}
1505+
14991506
mset := c.methodSetCache[methodSetKey{typ, addressable}]
15001507
if mset == nil {
15011508
if addressable && !types.IsInterface(typ) && !isPointer(typ) {
@@ -1508,13 +1515,6 @@ func (c *completer) methodsAndFields(typ types.Type, addressable bool, imp *impo
15081515
c.methodSetCache[methodSetKey{typ, addressable}] = mset
15091516
}
15101517

1511-
if isStarTestingDotF(typ) && addressable {
1512-
// is that a sufficient test? (or is more care needed?)
1513-
if c.fuzz(mset, imp, cb) {
1514-
return
1515-
}
1516-
}
1517-
15181518
for i := 0; i < mset.Len(); i++ {
15191519
obj := mset.At(i).Obj()
15201520
// to the other side of the cb() queue?

gopls/internal/golang/completion/fuzz.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ import (
2020
// PJW: are there other packages where we can deduce usage constraints?
2121

2222
// if we find fuzz completions, then return true, as those are the only completions to offer
23-
func (c *completer) fuzz(mset *types.MethodSet, imp *importInfo, cb func(candidate)) bool {
23+
func (c *completer) fuzz(testingF types.Type, imp *importInfo, cb func(candidate)) bool {
2424
// 1. inside f.Fuzz? (only f.Failed and f.Name)
2525
// 2. possible completing f.Fuzz?
2626
// [Ident,SelectorExpr,Callexpr,ExprStmt,BlockiStmt,FuncDecl(Fuzz...)]
2727
// 3. before f.Fuzz, same (for 2., offer choice when looking at an F)
2828

29+
mset := types.NewMethodSet(testingF)
30+
2931
// does the path contain FuncLit as arg to f.Fuzz CallExpr?
3032
inside := false
3133
Loop:

0 commit comments

Comments
 (0)