-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: consider using &S form instead of *S for pointer type struct field autocompletion #39227
Comments
/cc @muirdm |
This was discussed briefly in #38416, but we should consider getting rid of the struct field placeholder text altogether. It is weird to insert invalid, informational Go code when most editors already present the type information to the user. Composite literals prepend the "&" for you automatically as needed, and sometimes you don't want a composite literal, so I don't think having "&" placeholder text is a net win. |
@muirdm Interestingly I found the struct field placeholder is useful when dealing with badly named long type names with common prefixes, even though I dislike the current way of formulating function parameter place holders. I don't know about other editors, but at least, in VS Code the suggested text syntax is followed. So if I don't want a composite literal, just typing the other value at the cursor completely replaces the entire suggested text with my input. Actually, that's easier than using the suggested text. VS Code presents the type info as a hover message, which means I have to hover over the field to remember the type name to trigger meaningful autocompletion results. Additional cognitive overhead. It would be convenient if As a workaround, I hoped just typing BTW I didn't encounter automatically prepended "&". Is there any configuration I need to set to enable it? Or, do you mean the fact that the completion response includes |
Yes, that would be convenient in many cases. And of course it also contains the type information of the current placeholder.
You can also try triggering completion without typing anything at all (
Yes, the candidate will include "&" if it needs to be a pointer. In your example you could type "Very" and probably get a candidate for "&someproto.VeryLongMessage{}". @stamblerre how do you complete a long composite literal for a struct field value when you don't remember the name? Do you rely on hover popup, trigger completion manually, or something else? |
Ah, so I was confused by this and now I see why this has never been an issue for me. I don't use placeholders, so when I complete a struct literal, it looks like this: (This image shows a completion triggered at I also trigger completion manually a lot with Ctrl + Space. This flow works well for me, but I could see it being hard with placeholders. I would support having the placeholder be an |
Currently autocompletion for a struct field uses the field's type as the placeholder text. For example,
The autocompletion for the
Field
will return"newText":"Field: ${1:*F},"
.gopls
uses the type info for placeholder text, so I don't think the choice is incorrect nor invalid.But if the suggestion used
&F
instead, it would be more convenient when users want to use composite literals. Especially, if the type name is long to type, reusing what's already in the placeholder will save many keystrokes.(Based on golang/vscode-go#85)
The text was updated successfully, but these errors were encountered: