pucelle / vscode-run-on-save

Run configured shell commands when a file is saved in vscode, and output configured messages on status bar.
https://marketplace.visualstudio.com/items?itemName=pucelle.run-on-save
MIT License
50 stars 11 forks source link

Extends variable substitution capabilities #30

Closed jackwhelpton closed 9 months ago

jackwhelpton commented 10 months ago

An example of how I'm using this:

    "runOnSave.commands": [
        {
            // Match dotfiles
            "globMatch": "${env:XDG_DATA_HOME}/chezmoi/**",
            "command": "cfg apply",
            "runIn": "terminal",
            "runningStatusMessage": "Applying ${fileBasename}",
            "finishStatusMessage": "${fileBasename} applied"
        }
    ]

Previously using an environment variable in globMatch like this didn't work.

Another use case this PR supports is using the currently selected text:

    "runOnSave.commands": [
        {
            "command": "echo ${selectedText}",
            "runIn": "terminal"
        }
    ]

This PR provides almost complete support for VS Code variables; only {input:XXX} is unsupported. The reason for this is that the argument here links to an input control defined in tasks.json, and there appears to be no way to pull those programmatically at this time; parsing tasks.json manually may be a workaround, but feels ugly.

This PR also addresses the deprecated rootPath property.

For some reason I had to remove the postinstall step from package.json, which points at a command that (for me) didn't exist; I've consciously avoided committing that change.

Happy to make any changes required, just let me know what you need!

pucelle commented 9 months ago

Thanks very much, will merge it soon.

pucelle commented 9 months ago

Hi, jackwhelpton, I have merged your codes and released v1.7.0. But I made some changes:

  1. In variable substitute part, your code include a parameter scope. I find removing it doesn't affect much. So, did I misses something, Does the parameter scope have any special usage?