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: support fillstruct for partially-filled structs #39804

Closed
stamblerre opened this issue Jun 24, 2020 · 4 comments
Closed

x/tools/gopls: support fillstruct for partially-filled structs #39804

stamblerre opened this issue Jun 24, 2020 · 4 comments
Labels
FeatureRequest FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@stamblerre
Copy link
Contributor

We currently only offer fillstruct for completely empty struct literals. We should also offer to fill in values for partially filled structs.

/cc @joshbaum

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jun 24, 2020
@stamblerre stamblerre added this to the gopls/v0.5.0 milestone Jun 24, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jun 24, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.5.0 Jun 24, 2020
@gopherbot
Copy link

Change https://golang.org/cl/262018 mentions this issue: x/tools/gopls: support fillstruct for partially-filled structs

@jeanbza
Copy link
Member

jeanbza commented Oct 16, 2020

https://golang.org/cl/262018 now adds support for partially filled structs - wooo! But, all comments get destroyed. =)


Coming to a crossroads, now that I'm tackling comments. The ast package is proving to be a huge hindrance, since fillstruct doesn't use *ast.File in its implementation. Instead, it prints with token.FileSet. I'm not seeing a way to print subsets of the file (which seems to require token.FileSet) with comments (which appear to only exist on ast.File and printer.CommentedNode).

I had hoped that printer.CommentedNode would do the trick, but printing printer.CommentedNode with an ast.Expr and some comments seems to not work. (Does that meet expectations?)

So, the crossroads I'm at:

Option A: github.com/dave/dst

It looks like github.com/dave/dst has what I'm looking for: comments tied directly to nodes. But, introducing a v0 dependency seems sketchy.

Option B: hacky printing

I vaguely bet there's a way to figure out the fields that are already set (expr.Elts), then just go to the end of the struct and stick zero values of all the not-set fields at the end with printing hackery. That would leave all the comments and set fields up at the top, and all the zero'd values at the bottom. Not pretty but I thiiiink doable?


@joshbaum @stamblerre are there any directions that I'm missing? If not, any preference on the above?

@stamblerre
Copy link
Contributor Author

I think Option B would be best, as we'd like to avoid adding dependencies to x/tools.
I would honestly say that overwriting the comments is also fine--but I'm guessing this is incompatible with our test frameworks?

@jeanbza
Copy link
Member

jeanbza commented Oct 21, 2020

Ah! Ok, that helps a lot. I actually haven't tried all the other tests, but not sure. I'll give option B a shot, and then if that doesn't work will either rewrite comments or just not work when comments exist. :) Will report back soon!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants