0

I'd like to develop Joomla components with VS Code. With PHP Intelephense enabled, all my file show errors because I use Joomla classes and functions. (And it would also be convenient to have auto complete for Joomla functions)

To solve the same problem with WordPress, one can just add wordpress to the intelephense.stubs array in the settings. Unfortunately there are no stubs for Joomla, but it is possible to add your own stub files.

Is there a way to generate a stubs file for Joomla, or does it already exist and can be downloaded?

Additional remark

I develop the extension in a separate directory, so I have all of the files in one place and the editor and git is not cluttered with the Joomla files. Therefore the editor doesn't see the Joomla classes and functions. The setting intelephense.environment.includePaths seems to be a solution for this issue.
But I'm still wondering if there is a way to do via the stubs approach (the way it's solved for WordPress), so I don't have to add the includePaths for every project.

Update

Running build/stubGenerator.php script results in this error (on Linux)

Error: Failed to start application: Class Joomla\CMS\Filesystem\Support\StringController does not exist% 

If I change the file name of ./joomla-cms-staging/libraries/src/Filesystem/Support/Stringcontroller.php to StringController.php, the script finishes without an error. But the generated file (stubs.php) doesn't appear to be complete (at least to me). Every entry looks like this (total of 1877 lines):

/**
 * @deprecated 5.0 Use Joomla\... instead.
 */
class ... extends Joomla\... {}
1

When running Joomla from git clone you can use build/stubGenerator.php script. It will generate stubs.php file in Joomla's root directory.

5
  • I tried that, but I get an error. See update in question.
    – jost21
    Nov 3 '20 at 12:47
  • This is a known issue caused by incorrectly cased file. It hasn't been fixed in core yet. As a workaround you can rename Stringcontroller.php in libraries/src/Filesystem/Support to StringController.php.
    – Sharky
    Nov 4 '20 at 6:42
  • I already did that, but there are only @deprecated classes (375 of them) in the stubs.php file (more details in the question update). I'm not sure but it doesn't feel like that is what it should be, is it?
    – jost21
    Nov 4 '20 at 8:41
  • Yes, that's what the script does. Other classes should be picked up automatically by your editor.
    – Sharky
    Nov 5 '20 at 8:42
  • Sorry, maybe I should have been more clear. I develop my extension in a separate directory, the Joomla installation is in a different location and the editor doesn't have access to it. I found the setting intelephense.environment.includePaths yesterday, that seems to solve the problem. But I'm still wondering if there is a similar approach than there is for WordPress, for which you just add stubs.
    – jost21
    Nov 5 '20 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.