microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.63k stars 29.04k forks source link

consider to allow for variable substitution in the inputs section #64358

Open weinand opened 5 years ago

weinand commented 5 years ago

testing #64214:

I assume that variable substitution in the "inputs" section is disabled to avoid recursion...

However, I think it would be helpful to allow "simple" non-interactive variables like ${env:...}, ${config:...}, ${workspaceFolder:...}. This makes it possible to do something like this:

{
            "label": "echoPrompt",
            "description": "Please enter a folder name",
            "default": "${env:HOME}",
            "type": "prompt",
}
alexvy86 commented 5 years ago

My use case would be to use the path to the current file as the default value for one of my inputs.

"inputs": [
  {
    "id": "which-file",
    "description": "Enter the path to a .py file",
    "default": "${file}",
    "type": "promptString",
  }
]
userchefo commented 5 years ago

It would be very helpful, to be able to pass a list of strings to the "pickString" input. This would allow the usage of variable number of strings.

set myStrings="s1", "s2", "s3"

"inputs": [
    {
        "type": "pickString",
        "id": "str",
        "description": "Choose string...",
        "options": [${env:myStrings}],
        "default": "s1"
    }
]
GlenDC commented 4 years ago

This would definitely be useful to have as there are plenty of use cases for which this is handy. Why is this not supported in the first place, what is the rational?

alexr00 commented 4 years ago

To avoid recursion and sequencing problems.

codewrite commented 4 years ago

Are there any workarounds? i.e. any way to have a variable input default?

mdeggers commented 3 years ago

As noted above, while variable substitution appears to work (at least with the extension I'm using), the prompt and resulting command line are non-intuitive.

ARF1 commented 3 years ago

@mdeggers

As noted above, while variable substitution appears to work (at least with the extension I'm using), the prompt and resulting command line are non-intuitive.

Can you give an example of a variable substitution that works for you? For me, no substitutions work.

mdeggers commented 3 years ago

I'm using DeltaXML's XSLT/XPath extension, and I've created the following task:

{ "version": "2.0.0", "tasks": [ { "type": "xslt", "label": "Basic XSLT", "saxonJar": "${config:XSLT.tasks.saxonJar}", "xsltFile": "${input:xslFile}", "xmlSource": "${input:srcFile}", "resultPath": "${input:outFile}", "group": { "kind": "build" }, "problemMatcher": [ "$saxon-xslt" ] } ], "inputs": [ { "type": "promptString", "id": "xslFile", "description": "XSLT file name", "default": "${fileBasenameNoExtension}.xsl" }, { "type": "promptString", "id": "srcFile", "description": "SRC file name", "default": "${fileBasenameNoExtension}.xml" }, { "type": "promptString", "id": "outFile", "description": "Output file name", "default": "./xslt-out/${fileBasenameNoExtension}" } ] }

The "default" doesn't work,, in that I still get ${fileBasenameNoExtention} as the default.

When I run the command, I still see the unsubstituted values:

Executing task: D:\Programs-x64\Java\jdk-11.0.11+9-jre\bin\java.exe -cp D:\Programs\saxon\saxon-he-10.3.jar net.sf.saxon.Transform -xsl:${fileBasenameNoExtension}.xsl -s:${fileBasenameNoExtension}.xml -o:./xslt-out/${fileBasenameNoExtension}.html

However, if I have greeting.xsl open, the XSL file used is greeting,xsl, the source file used is greeting.xml, and once I add .html to the output, I get greeting.html as expected.

@mdeggers

As noted above, while variable substitution appears to work (at least with the extension I'm using), the prompt and resulting command line are non-intuitive.

Can you give an example of a variable substitution that works for you? For me, no substitutions work.

idraper commented 2 years ago

Is there any update on this? Is this planned for the future or officially not being supported?

pgfearo commented 1 year ago

@mdeggers As of January 2022 DeltaXML's XSLT/XPath extension has commands for getting task file-paths. You may therefore not need to use the Task inputs property. The user is presented with a 'QuickPick' list of recently used files or the option to trigger the relevant 'File Open' or 'File Save' dialog - as shown below:

xslt-tasks-file

As well as specialist XSLT commands for picking xslt, input-xml and result-xml, there's also a general purpose 'pickFile' command that takes a configuration argument and therefore does need to be defined in the 'inputs' property.