Skip to content

x/tools/gopls: support type parameters for function literal snippet completions #50623

@marwan-at-work

Description

@marwan-at-work

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) {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions