Skip to content

Run shellCommand to transform value in remember #50

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
tcm0116 opened this issue Feb 7, 2023 · 5 comments
Closed

Run shellCommand to transform value in remember #50

tcm0116 opened this issue Feb 7, 2023 · 5 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}" },
              ],

@roussak
Copy link

roussak commented Feb 3, 2025

I'd like to have this feature working in the vscode, but I can't... :'(

I copy-pasted your example from the Documentation page (the part "Named Arguments", right after this issue is mentioned), but it results in that the pickStringRemember:pickAnOptions works fine, but then I get "Could not find input with command 'echo You selected Option B' and taskId 'undefined'" pop up:

Image

I'll mention this comment at augustocdias's issues page too because I'm not sure which extension gives this behaviour.

@rioj7
Copy link
Owner

rioj7 commented Feb 3, 2025

@roussak The Tasks Shell Input extension tries to locate the input that calls this command.
It can't find it and thus gives an exception/message.

I have filed a pull request: augustocdias/vscode-shell-command#133

This does not search for an input if the completeInput argument is set to true.

            "args": {
              "command": "echo You selected ${pickStringRemember:pickAnOption}",
              "useSingleResult": true,
              "completeInput": true,
            },

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

3 participants