简体   繁体   中英

VsCode composer psr-4 autoload of external libraries does not perform code completion

I have a self-made shared library that I am including in my Laravel project.

This is how the autoload part in my composer.json looks like:

    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/",
            "MyLib\\Base\\": "../../../.libraries/my-lib/packages/MyLib/Base/src/" <- NOTE THIS
        }
    },

I cannot autocomplete the names of the classes (or anything) when I am typing the code.

I wrote down use MyLib\Base\Model\User; in my code and then tried to use User model and it worked perfectly, but the code keep showing the error Undefined type 'MyLib\Base\Model\User'. and highlights it with red underline as an error.

Therefore I understand that the intelliphense is not able to recognize the shared library classes although they work fine!

Any way to get around this?

Found this solution somewhere while I was trying a lot of things and this worked!

Just add this below json value in .vscode/settings.json file:

{
    "intelephense.environment.includePaths": [
        "../../../.libraries/my-lib/packages/MyLib/Base/src/"
    ]
}

Not only the error disappears, but also the code completion starts to work!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM