I'm trying to get custom stubs working for the different plugins we use within WordPress development.

I develop within the theme file directly and upload to a remote development server, and don't want to pull the full site to get context and linting that way.

I've managed to get ACF and WooCommerce ones working by add git repos for them via composer within the project. Since the stubs don't exist for the other stuff we work with, i've manually created them using the php-stubs generator. I've then added these to the vendor/php-stubs folder where the others were added. But it doesn't pick them up. After much trial and error it seemed to recognise it once, but then after 2 mins lost visibility of it and can't get it working again.

Any ideas? What's the standard practice for adding custom stubs?

Cheers

    5 days later

    iamchrishaigh Thank you for the question.

    vendor folder is treated "differently" - by default we only index files referenced by composer.json (or more precisely by vendor/composer/installed.json) - so anything copied over there is usually ignored.

    To add additional stubs, the best way (as you mentioned) is to use php-stubs composer packages, i.e. using:

    composer require --dev php-stubs/woocommerce-stubs

    Additional files may be added into vendor or anywhere else on your computer and referenced using "php.workspace.includePath" setting, i.e.:

    "php.workspace.includePath": "./vendor/php-stubs;"
      a year later

      JakubMisek what would be the best way to load stubs from php-stubs that are installed globally. I don't want to add those stubs to my project.

        6 days later

        @JakubMisek Sorry, I didn’t receive a notification for your reply. No, they are not part of my project, and that’s exactly what I want to avoid. My project is open source, and I feel that adding those dev dependencies would be too specific to my development setup. I’d prefer not to include those stubs as dependencies in my project.

          asumaran Then I would suggest using "php.workspace.includePath" setting with semi-colon separated list of paths. Paths can be absolute or relative to the workspace root. Example:

          "php.workspace.includePath": "path_to_stubs"

          I'm not sure if you can have a separate settings.json file, that would be excluded from git though

            Write a Reply...