valeryan / vscode-phpsab

Php Sniffer and Beautifier for VS Code
https://marketplace.visualstudio.com/items?itemName=ValeryanM.vscode-phpsab
MIT License
58 stars 12 forks source link

Single File Error #123

Open jacobcassidy opened 4 months ago

jacobcassidy commented 4 months ago

When opening a single PHP file in VSCode, running the PHPCBF: Fix this file command results in the following error: command 'fixer.fix' not found. The linter (phpcs) also does not work on single files. The following is logged in the output panel:

2024-05-11 21:09:27.667 [error] [valeryanm.vscode-phpsab] provider FAILED
2024-05-11 21:09:27.667 [error] undefined

All works as intended when adding a folder with the file in it to VSCode.

Is this the intended behavior, or is there a bug when not using project folders?

valeryan commented 4 months ago

Hey @jacobcassidy. I think it should work so I would call it a bug. I will have to look at the behavior but off the top of my head the reason will probably be that the vscode api that is used by the extension is only looking for workspace. More than likely with a single file the workspace is not present, breaking the extension. We will have to look at the behavior and see if that can be addressed.

jonathanbossenger commented 4 months ago

I was able to replicate this by selecting a single file in my file explorer, opening it with VS Code, and running the PHPCBF: Fix this file command.

I'll run this through the development version of the extension later today, and report back any findings.

michael-sumner commented 3 months ago

@jonathanbossenger has there been any findings on this one? I too am receiving the same error recently.

Nalci commented 2 months ago

Installed today this extension in VSC and get the same error

valeryan commented 2 months ago

Yes, this is a confirmed error. The extension uses VSCode's workspace API to access files and relies heavily on files in directory to work and none of that is available when VSCode is in single file mode. The extension requires composer and xml configuration files, and directory access, etc. at minimum it can handle this error gracefully and inform better why it doesn't work. If I have time to work on this I might get single file mode working but it will require global compose setup, and a global ruleset, etc.

jonathanbossenger commented 1 week ago

@valeryan For now, maybe if we just add a note in the readme that this only works when opening PHP files in a directory?