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: Support More postfix completion for map, slice. (len, for, forr) #64037

Closed
rogeryk opened this issue Nov 9, 2023 · 3 comments
Closed
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@rogeryk
Copy link
Contributor

rogeryk commented Nov 9, 2023

Describe the solution you'd like

I was using Goland before, but now I have switched to neovim. The suffix completion provided in Goland is really powerful, and I hope gopls can offer the same experience. I noticed that gopls already supports some suffix completion, but not enough. I hope more can be added. I'm not sure what considerations are involved in determining if a completion should be integrated into gopls, but I will provide some suggestions that I think are meaningful.

  1. len
    len is a very high-frequency function, providing suffix completion can greatly improve coding experience. When dealing with a nested structure, for example, a.b.c.d, when I obtain the d field, I find that it is a slice. It may be necessary to first check the length when processing it. In this case, it would be very useful if suffix completion can be directly applied.
a.b.c.d.len|

to

len(a.b.c.d)
  1. for
    Iterating over slices and maps is a common operation, and suffix completion allows you to focus on the data itself, which provides a better experience. I know that there is already suffix completion "range", but I think the name is not very good, considering that most people think of "for" first when iterating over data.
s = make([]int, 3)
s.for|

to

s = make([]int, 3)
for i| := range s {

}
  1. forr
    In Go, there are two types of traversal: one that only traverses the index and one that traverses both the index and value at the same time. Different situations may require different methods, so it makes sense to distinguish between these two types.
s = make([]int, 3)
s.for|

to

s = make([]int, 3)
for i|, v := range s {

}

I'm looking at the code handling this part in gopls. I'm interested in lsp and I'm willing to provide some help if possible.

@rogeryk rogeryk added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Nov 9, 2023
@gopherbot gopherbot added this to the Unreleased milestone Nov 9, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/unplanned Nov 9, 2023
@findleyr
Copy link
Contributor

findleyr commented Nov 9, 2023

Thanks, these sound reasonable to me. Are they consistent with what goland provides?

@rogeryk
Copy link
Contributor Author

rogeryk commented Nov 10, 2023

Ok, I'll try.

Are they consistent with what goland provides?

Yes

@gopherbot
Copy link

Change https://go.dev/cl/541277 mentions this issue: gopls/internal/lsp/source/completion: support more postfix completion for map and slice (len, for, forr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
3 participants