[英]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.我有一个自制的共享库,我将它包含在我的 Laravel 项目中。
This is how the autoload part in my composer.json
looks like:这就是我的composer.json
中的自动加载部分的样子:
"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;
我写下了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'.
在我的代码中,然后尝试使用User
模型,它运行良好,但代码一直显示错误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:只需在.vscode/settings.json
文件中添加以下 json 值:
{
"intelephense.environment.includePaths": [
"../../../.libraries/my-lib/packages/MyLib/Base/src/"
]
}
Not only the error disappears, but also the code completion starts to work!不仅错误消失了,代码补全也开始工作了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.