简体   繁体   English

PHP 在远程工作区的 VSCode 中格式化而不使用 Composer

[英]PHP formatting in VSCode on remote Workspace without using Composer

My Setup: Ubuntu 20 with PHP and Composer我的设置:Ubuntu 20 与 PHP 和作曲家
My Editor: VSCode with SSH FS extension to access remote workspace.我的编辑器:带有 SSH FS 扩展的 VSCode 以访问远程工作区。
My Task: do some PHP stuff, mainly Wordpress Themes我的任务:做一些 PHP 的东西,主要是 Wordpress 主题
My Problem: no PHP Formatter extension works on the remote Workspace我的问题:没有 PHP 格式化程序扩展适用于远程工作区

I tried to use: PHP-CS-fixer, Prettier with PHP plugin, phpfmt, phpcs, PHP Formatter...我尝试使用:PHP-CS-fixer, Prettier with PHP plugin, phpfmt, phpcs, PHP Formatter...
Some of them will even not work on my local Workspace.其中一些甚至无法在我的本地工作区上运行。

I can't install new Code on the remote Server (Composer), so i need a way to format PHP files just out of the Box like HTML or JS.我无法在远程服务器(Composer)上安装新代码,所以我需要一种方法来格式化 PHP 文件,就像 HTML 或 JS 一样。

But meanwhile i think, this is not possible.但同时我认为,这是不可能的。

Solution: use Ubuntu to connect to the server and mount that folder in workspace, let VSC think it is a real local folder:-)解决方案:使用 Ubuntu 连接到服务器并将该文件夹挂载到工作区中,让 VSC 认为它是一个真正的本地文件夹:-)

The problem with most formatting extensions is that they expect the files to be on a local drive, as in being mounted outside VS Code, including network shares by any NodeJS program (and therefore VS Code extensions).大多数格式化扩展的问题是他们希望文件位于本地驱动器上,就像在 VS Code 外部安装一样,包括任何 NodeJS 程序的网络共享(以及因此 VS Code 扩展)。 The extension uses the extension API's FileSystemProvider to provide FS access to VS Code.该扩展使用扩展 API 的 FileSystemProvider 提供对 VS Code 的 FS 访问。 It is only recently that they added a way for one extension to use file systems provided by other extensions, and it's even more recent that they started pushing extensions to make use of this.直到最近,他们才为一个扩展添加了一种使用其他扩展提供的文件系统的方法,而最近他们开始推动扩展以利用这一点。

Sadly enough, not every extension developer might start using it, and it's especially tricky for extension that use native/external programs.可悲的是,并不是每个扩展开发人员都可能开始使用它,而且对于使用本机/外部程序的扩展来说尤其棘手。 That includes most language-servers and formatters.这包括大多数语言服务器和格式化程序。

For your use case, there are two solutions though:对于您的用例,有两种解决方案:

  • Mount the folder on the OS level (eg sshfs ) and just open it as a regular directory in VS Code, as another answer suggested在操作系统级别安装文件夹(例如sshfs ),然后在 VS Code 中将其作为常规目录打开,正如另一个答案所建议的那样
  • Use VS Code's Remote SSH , which actually runs the extensions on the server, therefore skipping the whole "files aren't on a local drive" problem使用 VS Code 的Remote SSH ,它实际上在服务器上运行扩展,因此跳过了整个“文件不在本地驱动器上”的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM