防止在VS Codium中执行命令序列的异步顺序

发布于 2025-01-27 11:03:35 字数 4065 浏览 4 评论 0 原文

我如何控制 multicommand 延伸?它的行为就像它并行执行,而我希望它们接一个地执行。

我有一个具有以下结构的项目:

/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

pointer.txt 包含文本: dir1/Quards2

我想按快捷方式,并执行一系列操作:

  • 创建下一个问题文件
  • 对修改指针。txt指向新文件,
  • 在我设置的编辑器中打开它们

settings.json 中我定义了名为“ OpenPointEdproblembaylayout”的命令序列(因为能够轻松重复使用它):

"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"
                                }
                            }
                        }
                    }
                },
            ]
    
        },
    ]

tasks.json 我创建了一个shell命令定义,创建了一个shell命令一个新的.py和.txt对,还更改了指针:

{
    "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定义了执行操作(创建文件并打开文件)和numpad5(仅打开它们)的快捷方式numpad2(仅打开它们):

    {
        "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" },
    },

现在,当我按NUMPAD2时,创建了两个新文件:

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

然后在布局中打开两个文件 (意味着命令实际运行),但错误的文件。它们是问题。

我现在检查了pointer.txt的内容,它实际上包含 dir1/Quards 3 。当我按NUMPAD5时,它们会正确打开。

为什么VS Codium使用指针的先前内容,而在运行命令时,它应该已经采用新内容?它看起来像VS代码并行执行命令序列,而不是序列它们。

我做错了吗?这是配置或VS代码本身的问题,还是在多功能扩展中的问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您的好友蓝忘机已上羡 2025-02-03 11:03:35

我通过避免使用任何扩展来解决问题。可以通过任务定义命令序列。参见 https://stackoverflow.com.com/a/72201981/7869636

in keybindings.json.json.json.json define:

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

并且在任务中

{
    "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"
                        }
                    }
                }
            }
        }
    ]
}

。代码>。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文