rioj7 / command-variable

Visual Studio Code extension for variable substitution via ${command:commandID}
54 stars 10 forks source link

Add variableSubstArgs property to named arguments #54

Closed tcm0116 closed 1 year ago

tcm0116 commented 1 year ago

This PR adds the variableSubstArgs property as suggested in https://github.com/rioj7/command-variable/issues/50 in order to allow for expansion of variables in named arguments.

rioj7 commented 1 year ago

@tcm0116

see v1.49.0

tcm0116 commented 1 year ago

@rioj7

what is the need for the pickStringRemember changes in variableSubstitution?

These changes were done because, in the following example, ${remember:selectedBazelTarget} is not substituted within the description field of the options for pickBazelTarget prior to the pick list being displayed. This is because the current implementation of variableSubstitution doesn't pass the processPick argument to common.pickStringRemember, so the description field can't be substituted.

    "inputs": [
        {
            "id": "bazelTargetPath",
            "type": "command",
            "command": "extension.commandvariable.transform",
            "args": {
                "key": "selectedBazelTargetPath",
                "text": "${command:getBazelTargetPath}",
                "command": {
                    "getBazelTargetPath": {
                        "command": "shellCommand.execute",
                        "variableSubstArgs": true,
                        "args": {
                            "command": "bazel cquery --config=${command:cpptools.activeConfigName} --compilation_mode=dbg --output=files ${pickStringRemember:pickBazelTarget}",
                            "useSingleResult": true,
                            "cwd": "${workspaceFolder}",
                        },
                        "pickStringRemember": {
                            "pickBazelTarget": {
                                "description": "Choose a target",
                                "key": "selectedBazelTarget",
                                "rememberTransformed": true,
                                "options": [
                                    { "label": "Previous Target", "value": "${remember:selectedBazelTarget}", "description": "${remember:selectedBazelTarget}" },
                                    { "label": "Select target", "value": "${command:bazelTargets}", "description": "NOTE: It may take some time for the selection list to be displayed" }
                                ],
                                "command": {
                                    "bazelTargets": {
                                        "command": "shellCommand.execute",
                                        "args": {
                                            "command": "bazel query 'kind(cc_binary*, //...)'",
                                            "cwd": "${workspaceFolder}"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    ]
rioj7 commented 1 year ago

@tcm0116 Nice catch. update v1.49.1

I was confused by the comment and did not see the variableSubstitution argument. I only tested the shell example from the PR.

I have changed the example to use:

            "pickStringRemember": {
              "pickAnOption": {
                "key": "selectedOption",
                "description": "Pick an option",
                "options": [
                  { "label": "Previous option:",
                    "value": "${remember:selectedOption}",
                    "description": "${remember:selectedOption}"
                  },
                  "Option A",
                  "Option B",
                  "Option C",
                  "Option D"
                ]
              }
            }

README update in next version