Skip to content

pickStringRemember: Is it possible to remember a key for each options in an optionGroup ? #108

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

Closed
axelnxp opened this issue Feb 19, 2025 · 2 comments

Comments

@axelnxp
Copy link

axelnxp commented Feb 19, 2025

Hi !

I'm trying to figure out if it's possible to associate a key for each category of optionGroups, so I can remember it with extension.commandvariable.remember and use as a discrete input.

Let me try to give an example:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Test task",
            "type": "shell",
            "command": "echo options: \"${input:options}, category2 option: ${input:remember_option}\"",
            "options": {
                "cwd": "${workspaceFolder}"
            },
        },
    ],
    "inputs": [
        {
            "id": "options",
            "type": "command",
            "command": "extension.commandvariable.pickStringRemember",
            "args": {
                "description": "Select options",
                "key": "options",
                "multiPick": true,
                "optionGroups": [
                    {
                        "label": "Category 1",
                        "minCount": 1,
                        "maxCount": 1,
                        "options": [
                            ["cat1_option1", "cat1_option1_value"],
                            ["cat1_option2", "cat1_option2_value"],
                        ],
                    },
                    {
                        "label": "Category 2",
                        "minCount": 1,
                        "maxCount": 1,
                        "options": [
                            ["cat2_option1", "cat2_option1_value"],
                            ["cat2_option2", "cat2_option2_value"],
                        ],
                    },
                ]
            }
        },
        {
            "id": "remember_option",
            "type": "command",
            "command": "extension.commandvariable.remember",
            "args": { "key": "category2-option" }
        },
    ]
}

This obviously doesn't work, there's no link with the key to remember.
So, how can I change this to be able to remember and retrieve the value of one of the option selected in one category ?

@rioj7 rioj7 closed this as completed in 1a6ccd6 Feb 26, 2025
@rioj7
Copy link
Owner

rioj7 commented Feb 26, 2025

@axelnxp try v1.67.0, look at Example 13

@axelnxp
Copy link
Author

axelnxp commented Feb 26, 2025

@rioj7 thanks ! It works as expected.

In fact, my use case evolved and is a bit different that what I described initial in my ticket, I pushed the thing a bit further.
What I need, is to be able to remember an "alternative" value.
I need this because in some cases, I don't need all the information stored in the value, so I want to associate an alternative value which stores only a part of this information.

I could find a way to do it, here is an example:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Test task",
            "type": "shell",
            "command": "echo options: \"${input:options}, category1 option alt value: ${input:remember_altvalue}\"",
            "options": {
                "cwd": "${workspaceFolder}"
            },
        },
    ],
    "inputs": [
        {
            "id": "options",
            "type": "command",
            "command": "extension.commandvariable.pickStringRemember",
            "args": {
                "description": "Select options",
                "key": "options",
                "multiPick": true,
                "optionGroups": [
                    {
                        "label": "Category 1",
                        "minCount": 1,
                        "maxCount": 1,
                        "options": [
                            {
                                "label": "cat1_option1", "value": {
                                    "value": "cat1_option1_value",
                                    "alt_value": "cat1_option1_altvalue",
                                    "__key": "value"
                                }
                            },
                            {
                                "label": "cat1_option2", "value": {
                                    "value": "cat1_option2_value",
                                    "alt_value": "cat1_option2_altvalue",
                                    "__key": "value"
                                }
                            },
                        ],
                    },
                    {
                        "label": "Category 2",
                        "minCount": 1,
                        "maxCount": 1,
                        "options": [
                            ["cat2_option1", "cat2_option1_value"],
                            ["cat2_option2", "cat2_option2_value"],
                        ],
                    },
                ]
            }
        },
        {
            "id": "remember_altvalue",
            "type": "command",
            "command": "extension.commandvariable.remember",
            "args": { "key": "alt_value" }
        },
    ]
}

I don't know if this is the best way to do it, but it works.

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

No branches or pull requests

2 participants