vscode-phpsab icon indicating copy to clipboard operation
vscode-phpsab copied to clipboard

Single File Error

Open jacobcassidy opened this issue 1 year ago • 7 comments

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?

jacobcassidy avatar May 11 '24 14:05 jacobcassidy

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.

valeryan avatar May 14 '24 21:05 valeryan

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 avatar May 15 '24 07:05 jonathanbossenger

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

michael-sumner avatar Jun 29 '24 15:06 michael-sumner

Installed today this extension in VSC and get the same error

Nalci avatar Jul 22 '24 13:07 Nalci

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 avatar Jul 22 '24 14:07 valeryan

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

jonathanbossenger avatar Sep 23 '24 17:09 jonathanbossenger

@valeryan I am also getting this error, even when running inside a workspace.

Linting works, formatting does not work.

image

image

sephentos avatar Nov 26 '24 19:11 sephentos

@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.~

yCodeTech avatar Sep 18 '25 04:09 yCodeTech

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 autoRulesetSearch setting is ignored, and will essentially act as if it was set to false.

A global composer setup is required:

  • Users must set the executablePathCS and executablePathCBF settings 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.standard setting to a ruleset file then they must use the full absolute path.

yCodeTech avatar Sep 24 '25 08:09 yCodeTech