Possibility to create a value for function param that is pointer, on the spot

Answered

Example:

```

type Thing struct {

  // fields

}

func Foo(t *Thing) {

  // code

}

func Bar() {

  Foo({CURSOR})

}

```

Now when I have my cursor at {CURSOR}, I can see the params suggestions pop up. It says "t *Thing". So it knows a *Thing is supposed to go in there. But there is no way I can press a button to generate a *Thing on the spot; when I press ctrl+space, I get only "nil" as a suggestion. Would be nice if there was also an option to generate code for a *Thing.

4 comments
Comment actions Permalink
Official comment

You can use the Smart Type Completion and it should generate the right thing (tested in the latest version, 2020.1.3), see the image below:

Comment actions Permalink

Found it! I typically mostly use the normal suggestions (ctrl+space, I think?). It is a bit confusing that that one **does** show a suggestion for a non-pointer value, but not for a pointer value.

E.g.

vs

So then herby, if possible, I would like to make this a feature request/suggestion, because it's nice to be able to consistently use the same keyboard shortcut to get suggestions.

Nonetheless, thanks for helping me find where the option was hidden.

0
Comment actions Permalink

I'll ask my colleagues if we can do anything about this and raise an issue as a follow-up if needed, which I'll link here.

 

Meanwhile, another way to get the pointer there is to use Postfix Completion and do something like in the following gif:

0
Comment actions Permalink

Good idea, I can try to make more use of those. Thanks!

0

Please sign in to leave a comment.