Vscode-intelephense: After enabling this plugin PHP built-ins not recognised

Created on 14 Aug 2020  路  15Comments  路  Source: bmewburn/vscode-intelephense

Describe the bug
Uninstalled php intellisense as it's autocomplete wasn't recognising many php builtin functions
Installed this plugin
Disabled PHP Language Features and left PHP Language Basics enabled

Now all my php functions are redlining and intelephense is reporting them as undefined.

Screenshots
inteliphense

Platform and version
PHP intelephense v1.5.3
Win10 (up to date)
Version: 1.48.0 (user setup)
Commit: db40434f562994116e5b21c24015a2e40b2504e6
Date: 2020-08-13T07:50:42.600Z
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.19041

All 15 comments

Are they included in the project folder?

I don't understand?

Are they included in the project folder?

Are the wordpress functions included opened as well? Or are you just editing a theme?

Does your workspace / project folder look like this?
1.)

./wp-admin
    ...

./wp-content
    themes/
        your-theme/
            - functions.php <- current file
            ...

./wp-includes
    ...

./wp-config.php
...

2.)

your-theme/
    - functions.php <- current file
    ...

If it's 2.) then you have to use "intelephense.environment.includePaths" setting to set the root of the entire Wordpress project ie. where the wp-config.php lives. Including them lets intelephense know definitions of functions and classes of external files.

If you recently updated to 1.5.0 some changes may have effected your workflow.

It's the first one, 1.

Mhm, I guess you'll have to wait for the authors response then.

Mhm, I guess you'll have to wait for the authors response then.

thank you for trying to help.

Are you opening a folder or just a single file? Only symbol definitions found within the opened folder hierarchy will be indexed. If you need to link to a folder outside of the opened folder you can use the intelephense.environment.includePaths setting. Alternatively, there are also wordpress stubs distributed with the extension which can be enabled by adding wordpress to the intelephense.stubs setting.

Yes it was a folder structure.

Okay you've lost me there regarding symbol definitions.

Is it not just a matter of loading the VS Code plugin, following the plugin instructions (which I did) and then opening whatever folder you need to work on. Shouldn't the plugin work on any folder with PHP files?

As I say I've reverted back to the default plugin for php but I'd like to get your one working.

Okay you've lost me there regarding symbol definitions

The definitions of the functions/classes/methods etc. For example function wp_enqueue_style() { }. These must be within the opened folder hierarchy or linked to with intelephense.environment.includePaths.

Shouldn't the plugin work on any folder with PHP files?

Yes but it won't look outside of the opened folder for symbol definitions.

If the above does not help then It is hard to say what is wrong without a reproducible code example or other information like any errors in the intelephense output tab.

The definitions of the functions/classes/methods etc. For example function wp_enqueue_style() { }. These must be within the opened folder hierarchy or linked to with intelephense.environment.includePaths.

Okay but leaving the above aside, if PHP Intellisense works off the bat after re-installing it I am confused as to why I need to do anything beyond disabling PHP Language Features to get yours working. Esp in relation to your point below assuming both PHP Intellisense & PHP Intelephense would have the requirement below.

The definitions of the functions/classes/methods etc. For example function wp_enqueue_style() { }. These must be within the opened folder hierarchy or linked to with intelephense.environment.includePaths.

Is there any other troubleshooting I can try?

Okay but leaving the above aside

Are you saying the definitions are in the open folder hierarchy or not? If they're not then that's the issue.

Are you saying the definitions are in the open folder hierarchy or not? If they're not then that's the issue.

Okay please tell me how I would check this?

@GusGF

It's the first one, 1.

Are you absolutely sure that you have the whole Wordpress folder open in vscode? I am not too sure because your screenshot shows a breadcrumb trail with functions.php at the root. This seems to indicate you have a Wordpress theme open in vscode instead of the whole Wordpress folder. Here is relevant portion of your screenshot that I am referring to:

90229493-e836c280-de0f-11ea-8f9a-ea17f55152c8-png-1420脳836-

Notice how the breadcrumb trail only shows functions.php

I went ahead and downloaded Wordpress and opened the functions.php of one of the built-in themes (twentytwenty) and here is how the breadcrumb looks to me:

Screen Shot 2020-08-20 at 11 59 13 AM

Notice that it starts with wp-content at the beginning (which is supposed to be at the root level of your project) and it shows each folder in the path to functions.php.

Okay but leaving the above aside, if PHP Intellisense works off the bat after re-installing it I am confused as to why I need to do anything beyond disabling PHP Language Features to get yours working. Esp in relation to your point below assuming both PHP Intellisense & PHP Intelephense would have the requirement below.

It might be that the other extension you are using doesn't check that a function exists. You can test this theory by trying to call a random function which isn't defined like blahblahblah() and check if it actually highlights it as an undefined function. Also keep in mind that all those functions with errors like wp_enqueue_style are actually Wordpress functions, not PHP built-in functions, which is why you need the whole Wordpress folder open in vscode.

Now I feel really stupid but for not understanding the questions jellyNoone, corvusblack, bmewburn were asking me. Looking back what you were asking was pretty straightforward. I guess hindsight is everything and when you know, it all makes sense.

The only thing I can say in my defense is my ignorance of the inner workings of VSCode but I've learnt something from this. So thank you all for educating me and taking the time to reply.

:)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

umpirsky picture umpirsky  路  4Comments

aleksandervines picture aleksandervines  路  3Comments

superadmini picture superadmini  路  4Comments

dgunay picture dgunay  路  3Comments

zlianon picture zlianon  路  3Comments