Skip to content
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: code action for “add field names to struct literal” #43198

Open
bcmills opened this issue Dec 15, 2020 · 5 comments
Open

x/tools/gopls: code action for “add field names to struct literal” #43198

bcmills opened this issue Dec 15, 2020 · 5 comments

Comments

@bcmills
Copy link
Member

@bcmills bcmills commented Dec 15, 2020

gopls version
golang.org/x/tools/gopls v0.6.0
    golang.org/x/tools/gopls@v0.6.0-pre.1 h1:i+eJsCS+4N+3YSxLbuq0SrfWim3V8eG4WgdK8xQdzwI=

What did you do?

  1. In an emacs buffer, open $GOROOT/src/html/template/template.go:229:
    ret := &Template{
    nil,
    text,
    text.Tree,
    t.nameSpace,
    }
  2. 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

@gopherbot gopherbot added this to the Unreleased milestone Dec 15, 2020
@stamblerre stamblerre removed this from the Unreleased milestone Dec 15, 2020
@stamblerre stamblerre added this to the gopls/unplanned milestone Dec 15, 2020
@fatih
Copy link
Member

@fatih fatih commented Dec 16, 2020

What is the expected output for the assignment on line template.go/229 ? I'm not sure how we can add tags here (but maybe I'm missing something). For the record, here are some examples that we support recently: https://github.com/fatih/gomodifytags/releases/tag/v1.13.0

@hyangah
Copy link
Contributor

@hyangah hyangah commented Dec 16, 2020

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.

@bcmills
Copy link
Member Author

@bcmills bcmills commented Dec 16, 2020

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, 
	 } 

@fatih
Copy link
Member

@fatih fatih commented Dec 16, 2020

Aha I see, thanks for the clarification. I think keyify does this for you (it also has an emacs plugin). In vim-go you can use :GoKeyify

https://github.com/dominikh/go-tools/tree/master/cmd/keyify

@dominikh
Copy link
Member

@dominikh dominikh commented Jan 8, 2021

Integrating keyify with gopls is on my todo list. At the same time, gopls already has fillstruct, and I wouldn't be surprised if most of the code required for keyify and fillstruct is identical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants