golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.85k stars 737 forks source link

Add Struct Tags: transform per tag #905

Open skaldesh opened 3 years ago

skaldesh commented 3 years ago

Is your feature request related to a problem? Please describe. I want to configure a different transform for different tag types. Right now, I have to manually change it every time in the config, or I set promptForTag: true and write it in the dialog during Go: Add Struct Tags

Describe the solution you'd like I would like to be able to add per-tag defaults, similar as with the options.
So I would like to write: "transform": "json=snakecase,yaml=camelcase". Then, when struct tags are added, only the ones are added the user chooses during the promptForTags dialog, or all configured ones.

Describe alternatives you've considered None

Additional context None

hyangah commented 3 years ago

The transform, template, tags, options fields of go.addTags correspond to gomodifytags flags. So, I am a bit afraid of overloading the existing field. Recently transform and template were added, and I found the prompt chain is getting too long. What if we have more flexible settings like the following that has per-tag options.

   go.addTags.config: {
         "json" : {
                    "transform": "snakecase",
                    "template": "",
                    "options": "", 
                    "promptForTags": false,
          }, 
         ...
   }

In the presence of this setting, prompt users to choose tags, and use the config for the selected tags, or apply all. One caveat is that this type of setting structure will not work well with the VSCode's settings UI.

And since gomodifytags doesn't seem to support such level of customization for multiple tags (@fatih correct me if I am wrong - I don't know much about gomodifytags yet), this should be done from the extension and may require multiple invocations of the tool.

fatih commented 3 years ago

@hyangah, you're right that no flag lets the user do multi-tag, multi transforms simultaneously. The gomodifytags tool can work on multiple tags by selecting a range of lines or giving an offset to select the encapsulating struct with multiple fields, but the transform and template rules are applied to all fields once at the same time. The ideal solution is to invoke the tool multiple times for the selected tags.

Also, I'm not sure if it's feasible from a UX perspective to do multiple tags with multiple transform values. It would require a different form or UI to make it easier for people to input the various values.

hyangah commented 3 years ago

cc @OneOfOne

OneOfOne commented 3 years ago

I was thinking about something like:

go.addTags.config: [
    {
        "name": "json (oe)"
        "tags": "json",
        "options": "json=omitempty",
        "promptForTags": false,
        "transform": "snakecase",
        "template": ""
    },
    {
        "name": "json",
        "tags": "json",
        "options": "",
        "promptForTags": false,
        "transform": "snakecase",
        "template": ""
    },
    {
        "name": "bq",
        "tags": "bigquery",
        "options": "bigquery=omitempty",
        "promptForTags": false,
        "transform": "snakecase",
        "template": ""
    },
    ....
]

And just the sub menu would just list those names.

bilinxing commented 3 years ago

Looking forward to this new feature!!!

OneOfOne commented 3 years ago

I have been really swamped at work the past few weeks, hopefully next time I get a free weekend, I'll get this done.