rioj7 / command-variable

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

feature request transform as tmp file #85

Closed lublak closed 8 months ago

lublak commented 8 months ago

Currently in need an option to use promptStringRemember and save it to a file and get a filepath back. The debugger needs a file not a text input.

From the example, it would be useful to somehow receive the promptText as a tmpfilepath.

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Task 1",
      "type": "shell",
      "command": "dostuff1",
      "args": ["-p", "${input:promptText}"]
    },
    {
      "label": "Task 2",
      "type": "shell",
      "command": "dostuff2",
      "args": ["-p", "${input:rememberText}"]
    },
    {
      "label": "Do Task 1 and 2",
      "dependsOrder": "sequence",
      "dependsOn": ["Task 1", "Task 2"],
      "problemMatcher": []
    }
  ],
  "inputs": [
    {
      "id": "promptText",
      "type": "command",
      "command": "extension.commandvariable.promptStringRemember",
      "args": {
        "key": "text",
        "description": "Enter a text"
      }
    },
    {
      "id": "rememberText",
      "type": "command",
      "command": "extension.commandvariable.remember",
      "args": { "key": "text" }
    }
  ]
}
rioj7 commented 8 months ago

@lublak It would have been better if you write an API proposal with new syntax.

If I understand it you want to save the text entered in promptStringRemember in a file and return and remember the file path.

Possible syntax would be:

  "inputs": [
    {
      "id": "promptText",
      "type": "command",
      "command": "extension.commandvariable.promptStringRemember",
      "args": {
        "key": "text",
        "description": "Enter a text",
        "saveFile": "${workspaceFolder}/.vscode/tmp-text.txt"
      }
    }
  ]

The user has to construct a file path to use.

When you use ${input:promptText} you get a OS file system file path that contains the text in UTF-8 format.

It will also be implemented for pickStringRemember

lublak commented 8 months ago

@rioj7 sry.

Yes this would one solution. Another solution would be: This would also be usefull

  "inputs": [
    {
      "id": "promptText",
      "type": "command",
      "command": "extension.commandvariable.promptStringRemember",
      "args": {
        "key": "text",
        "description": "Enter a text",
      }
    },
    {
      "id": "textTmpFile",
      "type": "command",
      "command": "extension.commandvariable.file.save",
      "args": {
           "key": "text",
           "file": "${workspaceFolder}/.vscode/tmp-text.txt"
       }
    }
  ]

This might also be useful if you need it outside of the prompt. That way it would be more modular.

rioj7 commented 8 months ago

@lublak Your textTmpFile input would duplicate the promptStringRemember behavior with the only difference that it saves to a file, why not add that feature to promptStringRemember. And it is not clear what is the GUI used to get the content of the file. Just like key is additional functionality of promptStringRemember to put the result in a semi persistent storage.

And when I save the file path the way it is done in pickFile you can use transform in remember to modify/pick parts of the path to use.

rioj7 commented 8 months ago

@lublak

This might also be useful if you need it outside of the prompt. That way it would be more modular.

I don't get these remarks.

Does file.save have a text argument that is the content of the file? If so I can add a file argument to commandvariable.transform.

What would be the functionality of commandvariable.file.save?

lublak commented 8 months ago

@rioj7 For me, it's perfectly adequate if it's prompt. But I've also thought a little further ahead if someone needs it to save the current file, for example.

  "inputs": [
    {
      "id": "textTmpFile",
      "type": "command",
      "command": "extension.commandvariable.file.save",
      "args": {
           "text": "${file}",
           "file": "${workspaceFolder}/.vscode/tmp-text.txt"
       }
    }
  ]
lublak commented 8 months ago

@lublak

This might also be useful if you need it outside of the prompt. That way it would be more modular.

I don't get these remarks.

Does file.save have a text argument that is the content of the file? If so I can add a file argument to commandvariable.transform.

What would be the functionality of commandvariable.file.save?

A file argument to the commandvariable.transform would be the same solution yes :)

I was just thinking about how to build it so that it would be useful for more than just prompts.

Unfortunately I'm not a native speaker of English, so I have a bit of difficulty expressing myself. I'm sorry :/.

rioj7 commented 8 months ago

@lublak try v1.63.0

Only the transform command has the saveToFile property.

If you want to use any other command as file content you have to wrap it in a transform and use variables.

An example input:

    {
      "id": "saveToFile",
      "type": "command",
      "command": "extension.commandvariable.transform",
      "args": {
        "saveToFile": "${workspaceFolder}/.vscode/temp-text.txt",
        "text": "${promptStringRemember:getContent}",
        "key": "tmpfile",
        "promptStringRemember": {
          "getContent": {
              "description": "What to store in the file",
              "key": "fileContent"
          }
        }
      }
    }
lublak commented 7 months ago

@rioj7 works fine :) ty!