1

How can I control the execution order of multiCommand extension? It behaves like it executes them in parallel, while I want them to be executed one after another.

I have a project with the following structure:

/home/user/myproject/dir1/problem1.py
/home/user/myproject/dir1/problem1.txt
/home/user/myproject/dir1/problem2.py
/home/user/myproject/dir1/problem2.txt
...
/home/user/myproject/pointer.txt

The pointer.txt contains the text: dir1/problem2.

I want to press a shortcut, and do a sequence of actions:

  • Create next problem files pair
  • Modify a pointer.txt to point to new files
  • Open them in the editor

I setuped the following things.

In settings.json I defined the command sequence named "openPointedProblemLayout" (for being able to easily reuse it):

"multiCommand.commands": [
        {
            "command": "multiCommand.openPointedProblemLayout",
            "sequence": [
                {   "command": "htmlRelatedLinks.openFile",
                    "args": {
                        "file": "${command:mypointer}.py",
                        "method": "vscode.open",
                        "viewColumn": 1,
                        "command": {
                            "mypointer": {
                                "command": "extension.commandvariable.file.content",
                                "args": {
                                    "fileName": "${workspaceFolder}/pointer.txt"
                                }
                            }
                        }
                    }
                },
                {   "command": "htmlRelatedLinks.openFile",
                    "args": {
                        "file": "${command:mypointer}.txt",
                        "method": "vscode.open",
                        "viewColumn": 2,
                        "command": {
                            "mypointer": {
                                "command": "extension.commandvariable.file.content",
                                "args": {
                                    "fileName": "${workspaceFolder}/pointer.txt"
                                }
                            }
                        }
                    }
                },
            ]
    
        },
    ]

In tasks.json I created a shell command definition, that creates a new .py and .txt pair and also changes the pointer:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "create_new_problem_files_pair",
            "type": "shell",
            "command": "python /home/user/scripts/create_new_problem_files_pair.py \"${file}\""
        },
    ],
}

In keybindings.json I defined shortcut numpad2 that executes both actions (creates files and opens them) and a numpad5 (just opens them):

    {
        "key": "numpad2",
        "command": "extension.multiCommand.execute",
        "args": {
            "sequence": [
                {
                    "command": "workbench.action.tasks.runTask",
                    "args": "create_new_problem_files_pair"
                },
                {
                    "command": "multiCommand.openPointedProblemLayout"
                },
            ]
        }
    },
    {
        "key": "numpad5",
        "command": "extension.multiCommand.execute",
        "args": { "command": "multiCommand.openPointedProblemLayout" },
    },

Now, when I press numpad2, the two new files are created:

/home/user/myproject/dir1/problem3.py
/home/user/myproject/dir1/problem3.txt

And then two files are opened in layout (means the command actually runs), but wrong files. They are problem2.py and problem2.txt, i.e. the previous pointer is used.

I checked the content of the pointer.txt now, and it actually contains dir1/problem3. And when I press numpad5, they are opened correctly.

Why does the VS Codium uses previous content of pointer, while at the moment of command run, it should already take the new content? It looks like VS Code executes the command sequence in parallel, instead of sequence them.

Am I doing something wrong? Is that an issue with configuration or vs code itself or maybe in multiCommand extension?

10
  • You could try using the interval property of multi-command and see if it helps.
    – Mark
    Commented May 7, 2022 at 15:00
  • I did (added "interval": 500,), and it does not help unfortunately.
    – Ashark
    Commented May 7, 2022 at 15:07
  • I also added this question in the multiCommand project: github.com/ryuta46/vscode-multi-command/issues/54
    – Ashark
    Commented May 7, 2022 at 17:23
  • how large do you have to set the interval before it works, maybe the task starting is executed but not the full task end is waited for
    – rioV8
    Commented May 7, 2022 at 18:12
  • I see the documentation says the units are milliseconds. I wanted to set it to 5000 (5 sec). But currently I got a problem. I updated vscodium to 1.67.0, and it stopped working normally. When I press a shortcut, it says command 'extension.multiCommand.execute' not found, while the multiCommand extension is installed. Tried to downgrade to 1.66.2, and the problem persists. I am stuck now.
    – Ashark
    Commented May 7, 2022 at 18:55

1 Answer 1

2

I have solved the problem by avoiding usage of any extensions. A command sequence can be defined via Tasks. See https://stackoverflow.com/a/72201981/7869636

In keybindings.json I define:

    {
        "key": "numpad2",
        "command": "workbench.action.tasks.runTask",
        "args": "create_new_problem_files_pair_and_open_file_pair_in_layout"
    },

And in tasks.json I defined the whole things:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "create_new_problem_files_pair",
            "type": "shell",
            "command": "python /home/user/scripts/create_new_problem_files_pair.py \"${file}\""
        },
        {
            "label": "open_file_pair_in_layout",
            "dependsOrder": "sequence",
            "dependsOn": [
                "open_in_layout_left",
                "open_in_layout_right",
            ],
        },
        {
            "label": "create_new_problem_files_pair_and_open_file_pair_in_layout",
            "dependsOrder": "sequence",
            "dependsOn": [
                "create_new_problem_files_pair",
                "open_file_pair_in_layout",
            ],
        },
        {
            "label": "open_in_layout_left",
            "command": "${input:open_in_layout_left}",
        },
        {
            "label": "open_in_layout_right",
            "command": "${input:open_in_layout_right}",
        },
    ],
    "inputs": [
        {
            "id": "open_in_layout_left",
            "type": "command",
            "command": "htmlRelatedLinks.openFile",
            "args": {
                "file": "${command:mypointer}.py",
                "method": "vscode.open",
                "viewColumn": 1,
                "command": {
                    "mypointer": {
                        "command": "extension.commandvariable.file.content",
                        "args": {
                            "fileName": "${workspaceFolder}/pointer.txt"
                        }
                    }
                }
            }
        },
        {
            "id": "open_in_layout_right",
            "type": "command",
            "command": "htmlRelatedLinks.openFile",
            "args": {
                "file": "${command:mypointer}.txt",
                "method": "vscode.open",
                "viewColumn": 2,
                "command": {
                    "mypointer": {
                        "command": "extension.commandvariable.file.content",
                        "args": {
                            "fileName": "${workspaceFolder}/pointer.txt"
                        }
                    }
                }
            }
        }
    ]
}

This approach has a benefit that it defines these tasks in a scope of that project's workspace, and not globally in setting.json.

Not the answer you're looking for? Browse other questions tagged or ask your own question.