x/tools/gopls: improved completion of iterators #66637
Labels
gopls/completion
Issues related to auto-completion in gopls.
gopls
Issues related to the Go language server, gopls.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
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: