Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When does the next command executed (after first command finishes or in parallel)? #54

Open
Ashark opened this issue May 7, 2022 · 1 comment

Comments

@Ashark
Copy link

Ashark commented May 7, 2022

I have asked in s.o., but probably I get more lack asking this project directly.

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?

ryuta46 added a commit to ryuta46/vscode-multi-command-sandbox that referenced this issue Jul 3, 2022
@ryuta46
Copy link
Owner

ryuta46 commented Jul 3, 2022

I reproduced with small sample.

This extension waits until the previous command has finished, but the task "workbench.action.tasks.runTask" returned immediately and it seems to execute commands specified by the arguments in an internal thread.

I think your solution in SO is good.
Or, if you want to use the multi-command specified in settings.json, you can call it like ${command:***}

ex.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "write_file_with_delay",
            "type": "shell",
            "command": "python test.py",
        },
        {
            "label": "execute_command_after_write_file_with_delay",
            "command": "${command:multiCommand.showFileContent}",
            "dependsOrder": "sequence",
            "dependsOn": ["write_file_with_delay"]
        }
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants