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

How to run in sequence? #21

Closed manoharreddyporeddy closed 2 years ago

manoharreddyporeddy commented 2 years ago

The docs does not talk about running in parallel or in sequence Looks like all are parallel

What if i want to run in sequence, below commands are same but run it two times (or, two different commands), in sequence How to do this?

"runOnSave.commands": [
        {
            "match": ".*\\.*",
            "command": "editor.action.formatDocument",
            "runIn": "vscode"
        },
        {
            "match": ".*\\.*",
            "command": "editor.action.formatDocument",
            "runIn": "vscode"
        }
]
manoharreddyporeddy commented 2 years ago

@pucelle @davidolrik @BitFis

pucelle commented 2 years ago

Yes, this plugin doesn't care about sequence, in fact all commands are started immediately, and in a parallel.

It seems easy to support command sequence. so, you may provide your scenarios, we can talk about it here.

manoharreddyporeddy commented 2 years ago

Thanks for the reply.

Scenario:

On save

  1. Format document
  2. then Stage the changes in Git ( this should be in sequence, not parallel )

Expected ( but - should be in parallel - an option is needed)

{
    "runOnSave.statusMessageTimeout": 3000,
    "runOnSave.commands": [
        {
            "match": ".*\\.*",
            "command": "editor.action.formatDocument",
            "runIn": "vscode"
        },
        {
            "match": ".*\\.*",
            "command": "git.stageAll",
            "runIn": "vscode"
        }
    ]
}

I am forced to do below: Actual - currently i have this working, works fine but not optimal, as it runs outside the visual studio:

{
    "runOnSave.statusMessageTimeout": 3000,
    "runOnSave.commands": [
        {
            "match": ".*\\.*",
            "command": "editor.action.formatDocument",
            "runIn": "vscode"
        },
        {
            "match": ".*\\.*",
            "command": "ping -n 5 127.0.0.1 > nul 2>&1 && git add * > nul 2>&1",
            "runIn": "backend"
        }
    ]
}

Please let me know if you need more details.

pucelle commented 2 years ago

Next step should be the configuration json, what type of json format you would prefer?

manoharreddyporeddy commented 2 years ago

One of the below ways looks fine for me:

Solution Proposal 1

We could add an additional param async: true/false like below ( this is similar to other run on save extensions )

{
    "runOnSave.statusMessageTimeout": 3000,
    "runOnSave.async": true,  // <----------------------- parallel ( all below cmds will run at once )
    "runOnSave.commands": [
        {
            "match": ".*\\.*",
            "command": "editor.action.formatDocument",
            "runIn": "vscode"
        },
        {
            "match": ".*\\.*",
            "command": "ping -n 5 127.0.0.1 > nul 2>&1 && git add * > nul 2>&1",
            "runIn": "backend"
        }
    ]
}
{
    "runOnSave.statusMessageTimeout": 3000,
    "runOnSave.async": false,  // <----------------------- sequence ( all below cmds will run one by one / one after another )
    "runOnSave.commands": [
        {
            "match": ".*\\.*",
            "command": "editor.action.formatDocument",
            "runIn": "vscode"
        },
        {
            "match": ".*\\.*",
            "command": "ping -n 5 127.0.0.1 > nul 2>&1 && git add * > nul 2>&1",
            "runIn": "backend"
        }
    ]
}

==================

Solution Proposal 2

Instead of point 1 above, we could just add a runInSequence: true which will run the commands in sequence

{
    "runOnSave.statusMessageTimeout": 3000,
    "runOnSave.runInSequence": true,  // <----------------------- sequence ( all below cmds will run one by one / one after another )
    "runOnSave.commands": [
        {
            "match": ".*\\.*",
            "command": "editor.action.formatDocument",
            "runIn": "vscode"
        },
        {
            "match": ".*\\.*",
            "command": "ping -n 5 127.0.0.1 > nul 2>&1 && git add * > nul 2>&1",
            "runIn": "backend"
        }
    ]
}

===================

pucelle commented 2 years ago

I would prefer the option 1, will implement it soon.

manoharreddyporeddy commented 2 years ago

@pucelle thanks also we may need to consider the possibility of mixing both (parallel & sequence in a mix) just adding to keep in mind - can be added later

manoharreddyporeddy commented 2 years ago

Just for design ideas, if any required:


Here we can assume parallel/concurrent are same for our purposes: . https://stackoverflow.com/a/46086037/984471

Previously I used to use a library that has series & parallel: . https://caolan.github.io/async/v3/docs.html#series . https://caolan.github.io/async/v3/docs.html#parallel


Parallel & sequence in a mix ( but per command ):

async is per object by other run on save: (if prese) . https://github.com/emeraldwalk/vscode-runonsave/blob/master/README.md#sample-config


manoharreddyporeddy commented 2 years ago

I would prefer the option 1, will implement it soon.

@pucelle When it's done, please leave a comment here. thanks

pucelle commented 2 years ago

Sure.

pucelle commented 2 years ago

Released 1.5.0, should support async configuration. Sorry for the late fix and Thanks for your comments again.

lordmcfuzz commented 2 years ago

This really helped me! well appreciated!