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 type parameters for function literal snippet completions #50623

Closed
marwan-at-work opened this issue Jan 15, 2022 · 3 comments
Labels
FrozenDueToAge 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

@marwan-at-work
Copy link
Contributor

Given the following code:

type Tree[T any] struct{}

func (tree Tree[T]) Do(f func(s T)) {}

func _() {
  var t Tree[string]
  t.Do(fun) // trigger completion
}

The current completion that gopls gives for the func(...) {} snippet option is: func(s T) {}, but that is incorrect as T is not really valid. The correct solution would be whatever type was instantiated at compile time, so the completion in the example above should be func(s string) {}

@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 Jan 15, 2022
@gopherbot gopherbot added this to the Unreleased milestone Jan 15, 2022
@gopherbot
Copy link

Change https://golang.org/cl/378714 mentions this issue: internal/lsp/source: use the real type parameter in snippet completions

@rkfg
Copy link

rkfg commented Jan 15, 2022

Does this change above also fix completion for generic type method receivers or is it a different issue? Currently it suggests the structure name but without type parameters so I have to add them manually every time. Same with calling a function with type parameters, placeholders for them would be nice (they can't be guessed of course).

@findleyr
Copy link
Contributor

Thanks for the issue and CL, Marwan! Left some comments, and @pjweinb will be looking at completion issues.

@rkfg no I don't think this will fix the problem you describe. I opened #50684 to track that issue.

@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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