-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
I believe I've been able to improve some of the intellisense for model queries, please implement this (but maybe expand it first) #1536
Comments
Using templates certainly looks like a direction worth exploring, given nothing else breaks, including PhpStorm, phpstan, psalm, etc. Or at least have some sense of assessment if it causes collateral changes. |
Hello @Evertt Have you found a solution? Please can you tell me more about the extension you use to detect the scopes without the with?
|
@mreduar Well I'm starting to think that I should just completely and only rely on phpstan with larastan.
It seems I was mistaken. I just turned off the extension that I thought was making that work (which was this one), but it turns out that extension was not making the making possible, cause it still worked when I turned it off. Then I thought maybe phpstan / larastan was doing it, but I disabled those too and then it still worked. Turns out that somehow I think I'm making things very confusing for myself by having so many extensions and packages installed to improve VSCode's intellisense and now I find it hard to determine what extension or package is doing what exactly. EditBut in the end, I've been talking to the maintainers of larastan, and it seems like the features that they are missing (which laravel-ide-helper is currently complementing) is because some of their templates / stubs are a little out of date. But they intend to update them and then their thing should be able to offer all the intellisense that laravel-ide-helper is also offering. |
It doesn't: ide-helper finds The IDE (that file format was "invented" by IntelliJ for PhpStorm, other might/might not follow) then reads this file and off you go. Besides ide-helper being the generator, there's no "connection" that FWIW, IMHO it's recommended to not use the |
So I'm using VSCode with every extension I could install that gives my IDE the best possible understanding of how most of Laravel's magic methods work and what types they return. However, it's still not enough and luckily this package makes the autocompletion in my IDE better still.
However, I still found a scenario where my IDE doesn't understand what a certain method-call is referring to. Let me show you an example.
I have this model:
And then this in my
_ide_helper_models.php
file:Strictly speaking, I don't even need the line for
search
there, because one of my extensions is already smart enough to be able to linksearch()
toscopeSearch()
, but it's fine. So when I do this, things work completely fine:I can hover the
search()
call, and it will give me the desired type information and I can cmd + click on it and it will refer me directly toscopeSearch()
. However, that breaks as soon as I do this:Because
with()
simply returnsBuilder
and now neither my extensions nor your_ide_helper_models.php
file is able to make my IDE understand thatsearch()
is still available. I thought maybe runningphp artisan ide-helper:eloquent
and / orphp artisan ide-helper:generate
would fix that issue, but it didn't. However, I've been able to fix it myself! 😃 By adding the following lines at the top of_ide_helper_models.php
:And then changing docblock of IdeHelperTrainingDate to the following:
Now I can easily mix and match methods coming from
Builder
and scope methods coming fromTrainingDate
and my IDE will never forget that it can keep using both.Now of course, this was the quickest fix I was able to do, because I'm on a deadline and I'm sure there are lots of caveats here that I haven't thought of yet. And maybe the intellisense of IDEs could be expanded even more through methods similar to these.
So basically my request is, would you be willing to check out whether this approach is viable. As in, whether this doesn't create more problems than it solves. And if it does seem like a viable approach to extend IDE's intellisense then would you be willing to experiment what else could be improved with methods like these?
Edit
Okay after experimenting some more I'm now a bit confused. Because one of the things I was using to improve VSCode's understanding of my Laravel code was
phpstan
with an extension for it called larastan. And well, maybe some of all those many libraries and extensions have been feeding VSCode contradictory information or something? Because at some point, I was just disabling some extensions here and there to see whether I would lose important intellisense, but well, not always. Sometimes intellisense stayed the same and sometimes it even got a little better. And well now I'm not sure if my solution actually solved a problem that needed solving, if you know what I mean.Still I'd appreciate if anyone here would be willing to take a little time to experiment with this and see what's what. 😬 🙏
The text was updated successfully, but these errors were encountered: