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: [proposal] .reverse postfix completion should use slices package #66222

Closed
ALX99 opened this issue Mar 9, 2024 · 2 comments
Closed
Labels
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.
Milestone

Comments

@ALX99
Copy link

ALX99 commented Mar 9, 2024

Notes

This is just a proposal to an existing postfix completion entry
If this change is considered welcomed I would like to have a try at adding it myself!

gopls version

devel

What did you do?

From the following code:

func main() {
  example := []string{}
}

What did you see happen?

typing example.reverse yields the following:

func main() {
  example := []string{}
  for i, j := 0, len(example)-1; i < j; i, j = i+1, j-1 {
    example[i], example[j] = example[j], example[i]
  }
  
}

What did you expect to see?

I would like it to yield the following instead since it communicates the intent better

func main() {
  example := []string{}
  slices.Reverse(example)
  
}
@ALX99 ALX99 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 Mar 9, 2024
@gopherbot gopherbot added this to the Unreleased milestone Mar 9, 2024
@ALX99 ALX99 changed the title x/tools/gopls: .reverse postfix completion should use slices package x/tools/gopls: [proposal] .reverse postfix completion should use slices package Mar 9, 2024
@adonovan
Copy link
Member

adonovan commented Mar 9, 2024

typing example.reverse yields the following: ...

That's definitely suboptimal; it should indeed suggest slices.Reverse. The necessary code change is to the template ingopls/internal/golang/completion/postfix_snippets.go, and we would indeed welcome it! While you're there, see if there are other cases that need updating for the slices package. Thanks.

@gopherbot
Copy link

Change https://go.dev/cl/572116 mentions this issue: gopls: use slices package for reverse slice

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

Successfully merging a pull request may close this issue.

4 participants