在我今天得到的PHP Intelephense的最新更新之后,Intelephense一直显示我的路由(和其他类)的未定义符号的错误,以前没有这样的错误,它困扰着我。

以下是错误截图:

这是我的代码:

Route::group(['prefix' => 'user', 'namespace' => 'Membership', 'name' => 'user.'], function () {
    Route::get('profile', 'ProfileController@show')->name('profile.show');
    Route::patch('profile', 'ProfileController@update')->name('profile.update');
    Route::patch('change-password', 'ChangePasswordController@change')->name('change-password');
    Route::get('role', 'ProfileController@getRole')->name('profile.role');
    Route::get('summary', 'SummaryController@show')->name('summary');
    Route::get('reserved', 'AuctionController@reservedAuction')->name('reserved');
});

实际上,这段代码中没有错误,但intelephense一直显示错误,所以有办法解决这个问题吗?


当前回答

如果您在添加一个新的Vendor类后立即看到这种情况,请务必运行VScode命令(control-shift-P)索引工作区

其他回答

我也有同样的问题,下面的内容似乎已经解决了这个问题。

a)更新至最新版本1.3.5,并重新启用所有诊断设置。

我还在接收信息

b)将带有依赖库的vendor文件夹添加到工作区

这似乎解决了问题。

对于遇到这些问题并对禁用一整套检查感到不安的人来说,有一种方法可以将您自己的自定义签名传递给Intelephense。

摘自Intelephese repo的评论(来自@KapitanOczywisty): https://github.com/bmewburn/vscode-intelephense/issues/892#issuecomment-565852100

For single workspace it is very simple, you have to create .php file with all signatures and intelephense will index them. If you want add stubs globally, you still can, but I'm not sure if it's intended feature. Even if intelephense.stubs throws warning about incorrect value you can in fact put there any folder name. { "intelephense.stubs": [ // ... "/path/to/your/stub" ] } Note: stubs are refreshed with this setting change. You can take a look at build-in stubs here: https://github.com/JetBrains/phpstorm-stubs

在我的情况下,我需要dspec的描述,beforeEach,它…不被突出显示为错误,所以我只是包括签名/ directores_and_paths /app/vendor/bin/dspec文件在我的VSCode的工作空间设置,其中有我需要的函数声明:

function describe($description = null, \Closure $closure = null) {
}

function it($description, \Closure $closure) {
}

// ... and so on

在v1.7.1中也有同样的问题。它在内置函数上显示错误。但刚刚发现解决方案:去扩展设置@ext:bmewburn。vcode - Intelephense -client并逐个禁用Intelephense›Diagnostics:您将看到错误显示将停止。

自版本1.7.1以来,有其他解决方案

现在你可以知道intelephense应该在哪里寻找依赖项,例如vendor是最常见的。

"intelephense.environment.includePaths": [
    "vendor"
],

此外,它甚至绕过了VSCode规则

"files.exclude": {
    "**/vendor": true
},

你可以在这里阅读更多的更新日志

在你的web。php中

添加这行代码

use Illuminate\Support\Facades\Route;

然后你就完成了,如果你得到了认证错误,然后添加这行代码

use Illuminate\Support\Facades\Auth;

谢谢。