You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Vim] Tell me how to use Laravel IDE Helper with phpactor? #611
Now that the above mentioned PR is done, how likely is it to see support for this soon? 😍 If you gave me some direction I might take a crack at adding support for this!
The PR above enables virtual methods, i.e. it supports the @method Foobar bar() annotations. It doesn't support properties yet. What needs to be done in order to support this? (e.g. what is an _ide_helper.php file?)
Here's an example _ide_helper.php I found. It looks like for the most part it's just extending the classes and adding very simple function definitions on it.
I believe that Laravel 5.6+ use a lot of virtual method stuff in the docblocks so this PR should just natively pick those up :)
I guess the easiest way would be to add a new StubSourceLocator, like this.
☝️ the "dir" would just need to be the directory containing _ide_helper.php (and it looks like we also need to specify the name of the cache file, as I guess it will currently overwrite the same on when we have multiple).
You can then even create a new Phpactor Extension (e.g. laravel-extension) (and/or we can make it possible to configure multiple stub locators, although the laravel extension could maybe include the necessary stub file ??)
The only problem I see is if the Laravel class / method can be found with the Composer source locator, in which case we would need to ensure the new stub locator has a higher priority (and probably I can add a feature to specify a priority)
So in this case version() exists on the class that the App facade resolves to, which is \Illuminate\Foundation\Application. Facades forward calls on to the resolved class via __callStatic.
In this case the App facade doesn't a static version() method defined. __callStatic is invoked and that method will pull \Illuminate\Foundation\Application from the dependency container and call that method on that object.
RE: Composer vs IDE Helper priority: Is this a priority of which they show up in the list, or does this mean if it's found via one locator the other locator won't attempt to find it?
I'll take a look at making an extension but I expect to have a lot of questions based off the quick glance I just took.
Composer vs IDE Helper priority: Is this a priority of which they show up in the list, or does this mean if it's found via one locator the other locator won't attempt to find it?
We are strictly talking about how the reflection code (worse reflection) is able to locate the class definition. If the composer locator gets there first, you will only see the members defined in that file (probably nothing I guess?) but if a stub locator got there first it would resolve to the version defined in _ide_helper.php.
The extension in-itself would be quite simple (and should really be only plumbing -- we already have the code for this, but it might need some tweaking ... :) )
This method would also mean that if you "jump to definition" on Illuminate\Support\Facades\App you will land in the _ide_helper.php file.
Oh, I see, so this is similar to when I want to "Find References" and it asks if I want to use git, composer, etc?
probably nothing I guess?
That depends on which Laravel version. Somewhere around 5.5 or 5.6 people started adding @method docblocks to some Facade classes in PRs, such as the App facade has this:
That's not a complete list, though, and not all Facades have them, so I would definitely prefer for the IDE Helper locator to do the searching instead of composer, at least for now until more of these annotations get added.
Oh, I see, so this is similar to when I want to "Find References" and it asks if I want to use git, composer, etc?
No this is different, "find references" needs a list of all the files in your project (and it can use some different strategies to do that). For the most part WorseRefelection can guess very quickly where to find a particular class based on the fully qualified name of the class.
If the facade has those annotations then that should indeed work fine now.
I guess it would make sense to allow additional stub files / directories to be specified, and then adding priority if necessary (if it's just configuration, then it can be in config order). If that worked really well, then maybe it would make sense to have a Laravel Extension which helped with that.
The annotations do work great for Laravel 5.6+, but again, it doesn't capture everything. It also doesn't include model attributes (though I could add those myself) or Query Builder methods (where, orWhere, etc, those all go through __call) and adding those myself would be tedious.
So this "priority" concept - does the higher priority thing become what searches, or do they both get searched but the results are sorted via priority?
I guess it would make sense to allow additional stub files / directories to be specified, and then adding priority if necessary (if it's just configuration, then it can be in config order). If that worked really well, then maybe it would make sense to have a Laravel Extension which helped with that.
Yeah, I think that would be a really easy solution to the problem if the supporting changes are easy enough.
I unfortunately need to work with Laravel right now (first time) and… Wow. It's hard to understand where all the magic happens. Really struggling. Implementing this laravel-ide-helper could really help me, because I need to switch to PHPStorm right now to understand the code.
I have never used Laravel, so it's difficult for me to help directly -- but it might be possible to try a potential fix easily:
try composer require the laravel-ide-helper package
set the stub_dir from "worse_reflection.stub_dir": "%application_root%\/vendor\/jetbrains\/phpstorm-stubs" to point to the laravel ide stubs
clear the cache
this will replace the PHP built-in stubs with the laravel ones, not sure to what extent this will work, but might yield interesting results and subsequetly supporing multiple stub dirs would be easy I guess.
IIRC Laravel also overrides the autoloader, to provide "convenient" shortcuts. In this case the existing source location methods might not work as expected, which could possibly be addressed with a new location strategy similar to this hack in BetterReflection.
Activity
dantleech commentedon Oct 9, 2018
hi,
support for this might come in the future (there is a PR for virtual methods which would easily extend to virtual propertes.
But not sure eactly how the IDE helper stubs work for laravel, it shouldn't be too hard to implement given the above PR.
maamo888 commentedon Oct 9, 2018
Thank you for reply.
I look forward to future updates.
FatBoyXPC commentedon Mar 2, 2019
Now that the above mentioned PR is done, how likely is it to see support for this soon? 😍 If you gave me some direction I might take a crack at adding support for this!
dantleech commentedon Mar 2, 2019
The PR above enables virtual methods, i.e. it supports the
@method Foobar bar()annotations. It doesn't support properties yet. What needs to be done in order to support this? (e.g. what is an _ide_helper.php file?)FatBoyXPC commentedon Mar 2, 2019
Here's an example
_ide_helper.phpI found. It looks like for the most part it's just extending the classes and adding very simple function definitions on it.I believe that Laravel 5.6+ use a lot of virtual method stuff in the docblocks so this PR should just natively pick those up :)
dantleech commentedon Mar 3, 2019
hmm. So does the method
Illuminate\Support\Facades::version()(for example) exist? or all of these "magic" non-existing classes?dantleech commentedon Mar 3, 2019
I guess the easiest way would be to add a new
StubSourceLocator, like this.☝️ the "dir" would just need to be the directory containing
_ide_helper.php(and it looks like we also need to specify the name of the cache file, as I guess it will currently overwrite the same on when we have multiple).You can then even create a new Phpactor Extension (e.g.
laravel-extension) (and/or we can make it possible to configure multiple stub locators, although the laravel extension could maybe include the necessary stub file ??)The only problem I see is if the Laravel class / method can be found with the Composer source locator, in which case we would need to ensure the new stub locator has a higher priority (and probably I can add a feature to specify a priority)
FatBoyXPC commentedon Mar 3, 2019
So in this case
version()exists on the class that theAppfacade resolves to, which is\Illuminate\Foundation\Application. Facades forward calls on to the resolved class via__callStatic.Given this code:
In this case the
Appfacade doesn't a staticversion()method defined.__callStaticis invoked and that method will pull\Illuminate\Foundation\Applicationfrom the dependency container and call that method on that object.RE: Composer vs IDE Helper priority: Is this a priority of which they show up in the list, or does this mean if it's found via one locator the other locator won't attempt to find it?
I'll take a look at making an extension but I expect to have a lot of questions based off the quick glance I just took.
dantleech commentedon Mar 3, 2019
We are strictly talking about how the reflection code (worse reflection) is able to locate the class definition. If the composer locator gets there first, you will only see the members defined in that file (probably nothing I guess?) but if a stub locator got there first it would resolve to the version defined in
_ide_helper.php.The extension in-itself would be quite simple (and should really be only plumbing -- we already have the code for this, but it might need some tweaking ... :) )
This method would also mean that if you "jump to definition" on
Illuminate\Support\Facades\Appyou will land in the_ide_helper.phpfile.FatBoyXPC commentedon Mar 3, 2019
Oh, I see, so this is similar to when I want to "Find References" and it asks if I want to use git, composer, etc?
That depends on which Laravel version. Somewhere around 5.5 or 5.6 people started adding
@methoddocblocks to some Facade classes in PRs, such as theAppfacade has this:That's not a complete list, though, and not all Facades have them, so I would definitely prefer for the IDE Helper locator to do the searching instead of composer, at least for now until more of these annotations get added.
dantleech commentedon Mar 3, 2019
No this is different, "find references" needs a list of all the files in your project (and it can use some different strategies to do that). For the most part WorseRefelection can guess very quickly where to find a particular class based on the fully qualified name of the class.
If the facade has those annotations then that should indeed work fine now.
I guess it would make sense to allow additional stub files / directories to be specified, and then adding priority if necessary (if it's just configuration, then it can be in config order). If that worked really well, then maybe it would make sense to have a Laravel Extension which helped with that.
FatBoyXPC commentedon Mar 3, 2019
The annotations do work great for Laravel 5.6+, but again, it doesn't capture everything. It also doesn't include model attributes (though I could add those myself) or Query Builder methods (
where,orWhere, etc, those all go through__call) and adding those myself would be tedious.So this "priority" concept - does the higher priority thing become what searches, or do they both get searched but the results are sorted via priority?
FatBoyXPC commentedon Mar 3, 2019
Yeah, I think that would be a really easy solution to the problem if the supporting changes are easy enough.
einenlum commentedon Jul 15, 2019
I unfortunately need to work with Laravel right now (first time) and… Wow. It's hard to understand where all the magic happens. Really struggling. Implementing this laravel-ide-helper could really help me, because I need to switch to PHPStorm right now to understand the code.
dantleech commentedon Jul 15, 2019
I have never used Laravel, so it's difficult for me to help directly -- but it might be possible to try a potential fix easily:
laravel-ide-helperpackagestub_dirfrom"worse_reflection.stub_dir": "%application_root%\/vendor\/jetbrains\/phpstorm-stubs"to point to the laravel ide stubsthis will replace the PHP built-in stubs with the laravel ones, not sure to what extent this will work, but might yield interesting results and subsequetly supporing multiple stub dirs would be easy I guess.
dantleech commentedon Jul 15, 2019
IIRC Laravel also overrides the autoloader, to provide "convenient" shortcuts. In this case the existing source location methods might not work as expected, which could possibly be addressed with a new location strategy similar to this hack in BetterReflection.
einenlum commentedon Jul 15, 2019
@dantleech Indeed, it uses "aliases" in the
config/app.phpfile, that are not loaded by composer's autoload, but that Laravel can find however.Allowing
\Authanywhere in the code.Thanks for the above comment about the stub, gonna try when I have some time.