Skip to content
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

Open
adonovan opened this issue Apr 1, 2024 · 4 comments
Open

x/tools/gopls: improved completion of iterators #66637

adonovan opened this issue Apr 1, 2024 · 4 comments
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

Comments

@adonovan
Copy link
Member

adonovan commented Apr 1, 2024

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 a yield func(T) bool. (The name "yield" is conventional but not required.) Often of course it has the type iter.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:

func (c *Collection[T]) Elements(yield func(elem T) bool) { ... }

for range c.Elements { ... }

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 as for range c.Elements { ... }. Perhaps, in statement context, given the prefix c., it should offer not just c.Elements, but for for elem := range c.Elements { ... } (using the name of the yield parameter). There are likely other opportunities too.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Apr 1, 2024
@gopherbot gopherbot added this to the Unreleased milestone Apr 1, 2024
@adonovan adonovan modified the milestones: Unreleased, gopls/v0.17.0 Apr 1, 2024
@adonovan adonovan added gopls Issues related to the Go language server, gopls. gopls/completion Issues related to auto-completion in gopls. and removed gopls Issues related to the Go language server, gopls. labels Apr 1, 2024
@atdiar
Copy link

atdiar commented Apr 1, 2024

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?
Seems that it could help discovery.
Admittedly, it will require some kind of closures to transform old forms of iterators using the plain bool type, if there is any.
Maybe it has been addressed in which case, just ignore.

@adonovan
Copy link
Member Author

adonovan commented Apr 1, 2024

I'm wondering if making the bool return type a defined type has been addressed?

I think you're asking a question about the language change; this issue is about gopls completion support.

You might want to read the lengthy discussions around #61405 and #61897.

@atdiar
Copy link

atdiar commented Apr 1, 2024

@adonovan 👍🏿 thanks. I hadn't seen #61897

@KreanXie
Copy link

KreanXie commented Apr 2, 2024

lg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

4 participants