Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VsCode Go to definition not working #1543

Open
carlituxman opened this issue May 10, 2024 · 1 comment
Open

VsCode Go to definition not working #1543

carlituxman opened this issue May 10, 2024 · 1 comment
Labels

Comments

@carlituxman
Copy link

Versions:

  • ide-helper Version: 3.0.0
  • Laravel Version: 10.28
  • PHP Version: 8.1.26

Description:

VsCode with intelephense not detect definition for a function class

Steps To Reproduce:

I have this code:

//app/http/controllers/Api/ProcessController.php
namespace App\Http\Controllers\Api;
use App\Models\Center\Center;
$center = Center::where("uid", 1)->first();
$mySome = $center->getSome(); //No definition found for 'getSome()'

//app/models/Center/Center.php
namespace App\Models\Center;
class Center extends Model {
    public function getSome()
    {
        return "some";
    }
}

Then cmd+click or Go to definition "getSome()" on Center class throw: "Not definition found for ...."

@Tjaitil
Copy link

Tjaitil commented Aug 9, 2024

Hello,

I've tested this on Vscode, intelephense & Laravel 10.41.0. Although my version is slightly higher than yours I don't think it is relevant.

Although it is not provided in your code snippet, I'm assuming that you have generated docblocks for the App\Models\Center. Either way I tested this with generated docblocks and without.

With generated docblocks on App\Models\Center I'm getting that $center is either

\Illuminate\Database\Eloquent\Model|object|static|null
/** Fetched from Illuminate\Database\Concerns\BuildsQueries::first */ 

So it makes sense that 'go to type definition' doesn't work since intelliphense doesn't know that the variable is actually an instance of App\Models\Center

Without generated docblocks intelephense is reporting that $centeris mixed which again makes sense you are not getting a type definition.

Alternative approaches to get help out intelephense giving intellisense

  1. Use ->get() in combination of first().
$center = $center = Center::where("uid", 1)->get()->first();
$center->getSome(); // Gives you correct go to type definition
  1. Use instanceof to verify that the $center is actually App\Models\Center
$center = Center::where("uid", 1)->first();
if ($center instanceof \App\Models\Center) {
   $mySome = $center->getSome(); // Gives you correct go to type definition
}

TLDR; I don't think this a bug with laravel-ide-helper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants