Navigation Menu

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

Run shellCommand to transform value in remember #50

Closed
tcm0116 opened this issue Feb 7, 2023 · 3 comments
Closed

Run shellCommand to transform value in remember #50

tcm0116 opened this issue Feb 7, 2023 · 3 comments
Assignees

Comments

@tcm0116
Copy link

tcm0116 commented Feb 7, 2023

As a follow-up to the suggestion provided in #45 (comment), I'm trying to determine if there's a way to use a shell command to transform the value stored in a remember. Below is an example of what I'm looking to do. In this situation, the idea is that the launch configuration would call ${input:bazelTargetPath}, which would end up prompting the user to select a bazel target (which gets stored in selectedBazelTarget), and then the the result of that selection is then run through another shell command to get a different value (which gets stored in selectedBazelTargetPath). Is there a way to do something like this?

    "inputs": [
        {
            "id": "pickBazelTarget",
            "type": "command",
            "command": "extension.commandvariable.pickStringRemember",
            "args": {
                "description": "Choose a target",
                "key": "selectedBazelTarget",
                "rememberTransformed": true,
                "options": [
                    [ "Previous Target", "${remember:selectedBazelTarget}" ],
                    [ "Select target", "${command:bazelTargets}" ],
                ],
                "command": {
                    "bazelTargets": {
                        "command": "shellCommand.execute",
                        "args": {
                            "command": "bazel query 'kind(cc_binary*, //...)'",
                            "cwd": "${workspaceFolder}"
                        }
                    }
                }
            }
        },
        {
            "id": "bazelTargetPath",
            "type": "command",
            "command": "extension.commandvariable.remember",
            "args": {
                "key": "selectedBazelTargetPath",
                "command": {
                    "getBazelTargetPath": {
                        "command": "shellCommand.execute",
                        "args": {
                            "command": "bazel cquery --config=${command:cpptools.activeConfigName} --compilation_mode=dbg --output=files ${input:pickBazelTarget}",
                            "cwd": "${workspaceFolder}"
                        }
                    }
                }
            }
        }
    ]
@rioj7 rioj7 self-assigned this Feb 9, 2023
@rioj7
Copy link
Owner

rioj7 commented Feb 9, 2023

@tcm0116
It will have to be done in a construct like:

"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}",
                      "cwd": "${workspaceFolder}"
                  },
                  "pickStringRemember": {
                      "pickBazelTarget" : {
                          "description": "Choose a target",
                          "key": "selectedBazelTarget",
                          "rememberTransformed": true,
                          "options": [
                              [ "Previous Target", "${remember:selectedBazelTarget}" ],
                              [ "Select target", "${command:bazelTargets}" ]
                          ],
                          "command": {
                              "bazelTargets": {
                                  "command": "shellCommand.execute",
                                  "args": {
                                      "command": "bazel query 'kind(cc_binary*, //...)'",
                                      "cwd": "${workspaceFolder}"
                                  }
                              }
                          }
                      }
                  }
              }
          }
      }
  }
]

I have to implement the argument "variableSubstArgs": true for the ${command}.

@tcm0116
Copy link
Author

tcm0116 commented Feb 9, 2023

@rioj7 - in conjunction with the changes in #54, I was able to get your suggestion to work with the following tasks.json:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Pick Bazel Target",
      "type": "shell",
      "command": "echo ${input:bazelTargetPath} ${input:selectedBazelTarget}"
    }
  ],
  "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": [
                    [
                      "Previous Target",
                      "${remember:selectedBazelTarget}"
                    ],
                    [
                      "Select target",
                      "${command:bazelTargets}"
                    ]
                  ],
                  "command": {
                    "bazelTargets": {
                      "command": "shellCommand.execute",
                      "args": {
                        "command": "bazel query 'kind(cc_binary*, //...)'",
                        "cwd": "${workspaceFolder}"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "id": "selectedBazelTarget",
      "type": "command",
      "command": "extension.commandvariable.transform",
      "args": {
        "text": "${remember:selectedBazelTarget}"
      }
    }
  ]
}

@rioj7 rioj7 closed this as completed in f983393 Feb 11, 2023
@rioj7
Copy link
Owner

rioj7 commented Feb 11, 2023

@tcm0116 v1.49.0 use the syntax of comment

You can use the following options:

              "options": [
                { "label": "Previous Target:",
                  "value": "${remember:selectedBazelTarget}",
                  "description": "${remember:selectedBazelTarget}"
                },
                { "label": "Select target...", "value": "${command:bazelTargets}" },
              ],

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