vscode-phpsab
vscode-phpsab copied to clipboard
Single File Error
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?
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.
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.
@jonathanbossenger has there been any findings on this one? I too am receiving the same error recently.
Installed today this extension in VSC and get the same error
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.
@valeryan For now, maybe if we just add a note in the readme that this only works when opening PHP files in a directory?
@valeryan I am also getting this error, even when running inside a workspace.
Linting works, formatting does not work.
@jacobcassidy @michael-sumner @sephentos Is there a real-world use case where opening a single file without a folder/workspace is required? Currently, v0.0.20 completely prevents you doing this if it detects there is no workspace folders, with the error Unable to load configuration. Though perhaps this error could be improved to say there was no workspace detected...
As @valeryan said:
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.
So allowing single file mode would need considerable work to get working. Knowing of a use case (or multiple) would help in determining whether it's feasible developing it.
~This issue will be closed if no further information is provided or use cases put forward.~
Update:
Enabling single file mode is easier than I initially thought. So a complete fix is coming soon...
When in single file mode:
- The global user settings are used instead of workspace settings.
- The
autoRulesetSearchsetting is ignored, and will essentially act as if it was set tofalse.
A global composer setup is required:
-
Users must set the
executablePathCSandexecutablePathCBFsettings to the full absolute path of phpcs and phpcbf respectively, OR set them to empty strings to allow the extension to automatically find the global composer installation and resolve the paths to the globally installed phpcs/phpcbf. -
If users are setting the
phpsab.standardsetting to a ruleset file then they must use the full absolute path.