receiver func autocompletion behavior

Answered

I can't find a way to tell Goland that it should use pointer receivers in autocompleting a func/method signature instead of value receivers. It doesn't seem to consider already existing methods on the struct like the “mixed value and pointer receiver”-inspection does. So for example I already have:

but even the autocomplete dropdown shows the asterisk for the receiver, if I choose this completion the generated code still looks like this:

I could add the asterisk manually in the step where I can rename the receiver by first using “right arrow” followed by “asterisk” every time but I find this quite cumbersome, especially when already existing methods all have pointer receivers.

Is there a way to configure this behavior or is this a bug or is it working as designed?

0
1 comment

Hi Christian,
 
Vadym with JetBrains Support team is here. Thank you for your message and for providing the screenshots - those helped a lot. I've run some checks on our end and was able to reproduce the same behavior in my testing environment. 
 
After checking this additionally, I'd like to confirm that what you see on your end is expected - indeed, methods in Go accept both value and pointer receivers. As such, we default to the first option when declaring methods and functions, like in your case.
 
I also understand this might not be perfect in some cases so checked if we have similar suggestions logged by other users and have found this one - https://youtrack.jetbrains.com/issue/GO-14981/Suggest-pointer-receiver-in-func-meth-templates. I'm attaching your message to this improvement request as well. Please feel free to check it to see if there are any updates.
 
Thank you once more and please don't hesitate to contact us should you have any additional questions.

0

Please sign in to leave a comment.