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?

rioV8
  • 24,506
  • 3
  • 32
  • 49
Ashark
  • 643
  • 7
  • 16
  • You could try using the `interval` property of multi-command and see if it helps. – Mark May 07 '22 at 15:00
  • I did (added `"interval": 500,`), and it does not help unfortunately. – Ashark May 07 '22 at 15:07
  • I also added this question in the multiCommand project: https://github.com/ryuta46/vscode-multi-command/issues/54 – Ashark May 07 '22 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 May 07 '22 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 May 07 '22 at 18:55
  • Also, when opening a py file, I get the message ` Cannot activate the 'Pylance' extension because it depends on the 'Python' extension, which is not loaded. Would you like to reload the window to load the extension?` – Ashark May 07 '22 at 18:59
  • Have they "fixed" the use of MarketPlace extensions in VSCodium – rioV8 May 07 '22 at 23:52
  • No. It seems that multiCommand extension is broken. Strange how it is possible, because it did not updated recently. But I did lots of experiments, installing different versions of code-oss, codium and even ms-vs-code-bin, and the result is the same. In this https://dae.me/blog/2603/vs-code-bind-one-key-to-multiple-commands-without-an-extension/ article I found an alternative extension called macros. It at least launches. I would even prefer to keep all this in tasks.json, to make it in project scope. But I did not found a way how to pass arguments to the commands in such case. – Ashark May 10 '22 at 16:35
  • Using [macros](https://marketplace.visualstudio.com/items?itemName=geddski.macros) extension leads to the same result. The layout is opened, but it tries to open previous pointed files. And I do not see any thing like "interval" in macros. Any advice? – Ashark May 10 '22 at 16:37
  • Looks like that is also a known issue in macros extension. Found this pr https://github.com/geddski/macros/pull/11, but it did not worked for me. – Ashark May 10 '22 at 17:21

1 Answers1

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.

Ashark
  • 643
  • 7
  • 16