-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/completion: prefer rangeable funcs in range statements
Teach gopls that `range` statements can accept iterator funcs per upcoming Go 1.23 language change (and Go 1.22 "rangefunc" experiment). I didn't bother disabling this preference for earlier versions of Go since false positive completions seem unlikely. For golang/go#66637 Change-Id: Id57687f3fa205fa8e4b4616eebee471e6d11d802 Reviewed-on: https://go-review.googlesource.com/c/tools/+/592915 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Run-TryBot: Muir Manders <muir@mnd.rs> Auto-Submit: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
- Loading branch information
Showing
2 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
gopls/internal/test/marker/testdata/completion/range_func.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
This test shows we prefer rangeable funcs in range statements. | ||
|
||
-- flags -- | ||
-ignore_extra_diags | ||
|
||
-- range_func.go -- | ||
package rangefunc | ||
|
||
func iterNot(func(int)) {} | ||
func iter0(func() bool) {} | ||
func iter1(func(int) bool) {} | ||
func iter2(func(int, int) bool) | ||
|
||
func _() { | ||
for range i { //@rankl(" {", "iter0", "iterNot"),rankl(" {", "iter1", "iterNot"),rankl(" {", "iter2", "iterNot") | ||
} | ||
|
||
for k := range i { //@rankl(" {", "iter1", "iterNot"),rankl(" {", "iter1", "iter0"),rankl(" {", "iter2", "iter0") | ||
} | ||
|
||
for k, v := range i { //@rankl(" {", "iter2", "iterNot"),rankl(" {", "iter2", "iter0"),rankl(" {", "iter2", "iter1") | ||
} | ||
} |