如何在VSCode中文件保存时自动运行Laravel Pint?

huangapple go评论67阅读模式
英文:

How to automatically run Laravel Pint on file save in VSCode?

问题

Laravel Pint文档 指定您可以通过调用位于 vendor/bin 目录中的二进制文件来运行 Pint,如下所示:

./vendor/bin/pint

我想在VSCode中设置这样的功能,以便在保存特定文件时自动运行 Pint。我该如何实现这一目标?

英文:

The Laravel Pint docs specifies that you can run Pint by invoking the binary located in the vendor/bin directory like this:

./vendor/bin/pint

I would like to set this up in VSCode so that it automatically runs Pint when a specific file is saved. How can I achieve this?

答案1

得分: 3

一个可能的解决方案是使用一个允许你在文件保存时运行命令的扩展:

例如,你可以使用 Run on Save 扩展,然后在 settings.json 中(最好是本地的),添加以下命令:

"emeraldwalk.runonsave": {
  "commands": [
    {
      "match": "\\.php$",
      "cmd": "${workspaceFolder}/vendor/bin/pint ${file}"
    }
  ]
}

这将仅在保存特定文件时调用 Pint。

英文:

One possible solution is to use an extension that let's you run commands on file saves:

For example, you can use the Run on Save extension, then in the settings.json (preferably the local one), add the following command:

"emeraldwalk.runonsave": {
  "commands": [
    {
      "match": "\\.php$",
      "cmd": "${workspaceFolder}/vendor/bin/pint ${file}"
    }
  ]
}

This should invoke Pint only on the specific file that was saved.

huangapple
  • 本文由 发表于 2023年5月25日 07:03:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76327911.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定