Visual Studio 代码 运行 保存扩展名不是 运行

Visual Studio Code Run On Save Extension not running

我为 VS Code 安装了 运行 On Save 扩展。我给它做了一个工作区设置,如果我改变一个文件然后重新保存,它似乎没有运行。 "I run for all files" 没有出现在控制台或终端中。

当我选择在我的工作区设置中编辑命令配置时,它会自动编辑带有注释 "Place your settings in this file to overwrite default and user settings." 的文件,因此它看起来像这样:

// Place your settings in this file to overwrite default and user settings.
{
    "editor.mouseWheelZoom": false,
    "emeraldwalk.runonsave": {
        "commands": [
            {
                "match": ".*",
                "isAsync": true,
                "cmd": "echo 'I run for all files'"
            }
        ]
    }
}

我是配置 Workspace 设置的新手,所以我不确定这是否合适。我确保通过在命令面板上选择它来启用 运行 On Save。

这是扩展程序的站点:https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave

我遇到了完全相同的问题。我删除了那个扩展,现在改用这个:

https://marketplace.visualstudio.com/items?itemName=wk-j.save-and-run

它是基于 RunOnSave 的一个分支。当我在我的用户设置中设置它的配置然后 运行 命令 "Save and Run: Enable".

时,这个对我有用

这个使用内置的 powershell 终端。

HTH

为了查看控制台输出,您必须在 Output 选项卡和 select 下拉列表中的 Run On Save 选项。该扩展是在集成终端出现之前创建的,并且已经有一段时间没有看到重大更新了。

关于添加到您的配置的评论:

// Place your settings in this file to overwrite default and user settings.

与此特定扩展名无关。它只是 vscode 让您知道工作区级别配置的目的。它允许您覆盖更全局的用户/默认设置的子集。这允许您保留合理的默认首选项,但可以自定义任何给定工作区中的某些特定内容。

关于原始 RunOnSave 扩展,如果您有任何疑问或问题,请随时在此处提出问题 https://github.com/emeraldwalk/vscode-runonsave/issues。如果有人感兴趣,我也欢迎拉取请求。

除了我们亲爱的@bingles,我无意中发现应该将命令添加到 .vscode/settings.json 文件,而不是 plugin documentation[=15= 中所说的 .vscode/emeraldwalk.runonsave ]

将它添加到 settings.json,一切都会按预期工作。

要使扩展在 Workspace 上运行,您必须将 emeraldwalk.runonsave 放入设置中:

    {
        "settings": {
            "emeraldwalk.runonsave": {
                "commands": [
                    {
                         "match": ".*",
                         "isAsync": true,
                         "cmd": "echo 'I run for all files'"
                    }
                ]
            }
        }
    }

一个相关的:

之前我用的是RunOnSave,这次我用的是Code Runner

Code Runner - https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner

以下是我使用的设置:

File: %AppData%\Code\User\keybindings.json

{
    {
        "key": "ctrl+s",
        "command": "code-runner.run"
    }
}

File: .vscode\settings.json

{
    "code-runner.saveFileBeforeRun": true,
    "editor.codeActionsOnSave": [
        "code-runner.executorMap"
    ]
    "code-runner.executorMap": {
        "javascript": "node a.js"
    },
}

如果可能,您可以使用具有上述设置的 Code Runner,或对 RunOnSave 使用与上述设置类似的设置。

请注意,RunOnSave 有自己的选项卡,切换到另一个选项卡非常耗时。

使用 Code Runner,我可以在“输出”选项卡中看到输出,这是一件非常好的事情,可以节省时间。