-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: code action for “add field names to struct literal” #43198
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
Comments
What is the expected output for the assignment on line |
Based on the title, it sounds like the feature is about transformation to use named fields instead of positional args for struct literals. gomodifytags is to add structure tags, so unrelated. |
Yes, @hyangah has the right intent. I want the code action to transform the code from ret := &Template{
nil,
text,
text.Tree,
t.nameSpace,
} to ret := &Template{
escapeErr: nil,
text: text,
Tree: text.Tree,
nameSpace: t.nameSpace,
} |
Aha I see, thanks for the clarification. I think https://github.com/dominikh/go-tools/tree/master/cmd/keyify |
Integrating keyify with gopls is on my todo list. At the same time, gopls already has |
It seems that it's not easy to get And although golang/vscode-go#1631 has been resolved, which seems to have made omitting field names a better option, I think having field names still has its advantages:
So it'd be great if gopls can offer this functionality. |
This capability has been available since [email protected] and works in neovim lsp too |
This issue can probably be closed as a dupe of #53062 which has the attached PR that was merged in v0.9.0 to support this capability |
Thank you for spotting that, @dnwe! |
@dnwe Looks like this only works if the struct is in a different package? No code actions on Bar (or govet warning) Our test matrices usually involve some (anonymous) structs in the same package. Any way to make this case work? Ty |
What did you do?
emacs
buffer, open$GOROOT/src/html/template/template.go:229
:go/src/html/template/template.go
Lines 228 to 233 in f1980ef
M-x eglot-code-actions
What did you expect to see?
An LSP code action that can add field names to the Go struct literal at the current location.
(@stamblerre informs me that VSCode currently provides this functionality using
gomodifytags
; cc @fatih.)What did you see instead?
[eglot] No code actions here
The text was updated successfully, but these errors were encountered: