How do I Extract selection as Receiver Method?

已回答

On a mac, if I do Option+Cmd+M, I'm able to extract a function, is there a way to extract a method, or have a UI that allows me to convert a function from a function to a method? The change signature UI doesn't seem to have tis capability.

0

Hi,

You can use Extract method action to extract function or method with a receiver, e.g., with the following code:

package main

import "fmt"

type test struct{}

func (t *test) worker() (a int){
a = 0
for i:=0; i<10; i++{
a++
}
return
}

func main() {
var t *test
fmt.Println(t.worker())
}

Try to select the content inside the worker() method.

Could you please provide a code snippet with the actual and expected results?

or have a UI that allows me to convert a function from a function to a method

It isn't available yet, please see and follow GO-14.

1

Hey Daniil,

Can I do this if the original function doesn't have a receiver?

 

0

I want this instead:

func (a a) funcName() {
a.b += 1
}
0

Hi,

Not yet, please follow GO-14. Please see if you're not familiar with YouTrack: Watching YouTrack issues.

0

请先登录再写评论。