-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/gopls: improved completion of iterators #66637
Comments
It's a bit off-topic for that issue and should be discussed in the main discussion but I'm wondering if making the bool return type a defined type has been addressed? |
lg |
Change https://go.dev/cl/592915 mentions this issue: |
We can also improve the |
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>
Unlike iterators in many languages, which always have a distinct type such as
Iterator<T>
, an iterator in Go 1.23 is any function that accepts ayield func(T) bool
. (The name "yield" is conventional but not required.) Often of course it has the typeiter.Seq[T]
, but this isn't necessary, and when a method of a collection is itself an iterator (as opposed to returning one), as in this example:it may not be immediately obvious that one is looking at an iterator. Completion may be able to help here. Given a prefix
for range c.
, we should offer completions such asfor range c.Elements { ... }
. Perhaps, in statement context, given the prefixc.
, it should offer not justc.Elements
, but forfor elem := range c.Elements { ... }
(using the name of the yield parameter). There are likely other opportunities too.The text was updated successfully, but these errors were encountered: