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

[Twig] Support {% set %} together with {# @var #} #1303

Closed
ruudk opened this issue Apr 27, 2019 · 9 comments
Closed

[Twig] Support {% set %} together with {# @var #} #1303

ruudk opened this issue Apr 27, 2019 · 9 comments

Comments

@ruudk
Copy link
Contributor

ruudk commented Apr 27, 2019

When I set a variable in Twig using set and define the type with @var the plugin doesn't understand its type:

{# @var website \App\Website #}
{% set website = websites[1] %}

{{ website.id }}

Screenshot

You can see that the type of website is set instead of \App\Website:

Screenshot 2019-04-27 at 12 53 21

@ruudk
Copy link
Contributor Author

ruudk commented Nov 6, 2019

@Haehnchen Do you have an idea how to fix this? Can you maybe point me to where this "magic" happens, so that I can have a look at the code? If I can do it, I'd like to create a PR. But I might need some help setting building it. Thinking of it, it would be great if there was a step-by-step guide that teaches people how to build it 🙏

@Haehnchen
Copy link
Owner

that looks like a missing merge, where website "set" should extend with the type. understanding that is not easy.

first starting point for {{ web }}
https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/master/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java#L639 this is extracting set, as you see by right 2 usages one for navigatin and one for completion.

https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/master/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigTemplateCompletionContributor.java#L219 provides now the "set" in anycase.

the next "for(Map.Entry<String, PsiVariable> entry: TwigTypeResolveUtil.collectScopeVariables(parameters.getOriginalPosition()).entrySet()) {" is the doing the real Twig magic to find variables

maybe more important {{ website.i }}
the type trigger after a dot is inside. https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/master/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigTemplateCompletionContributor.java#L509. i would say this is more important then the first one. by following this code your target is then the core Twig variable resolving which is inside: fr.adrienbrault.idea.symfony2plugin.templating.util.TwigTypeResolveUtil#collectScopeVariables(com.intellij.psi.PsiElement, java.util.Set<com.intellij.openapi.vfs.VirtualFile>)

@Haehnchen
Copy link
Owner

but its maybe task for doing at this weekend, will see

@ruudk
Copy link
Contributor Author

ruudk commented Nov 6, 2019

Thanks for your reply. Maybe you have a hint on how to solve this:

Cannot download JetBrains Java Runtime jbr-11_0_3-osx-x64-b304.10
java.io.IOException: Failed to move temporary file '/Volumes/CS/www/idea-php-symfony2-plugin/build/download-task/jbr-11_0_3-osx-x64-b304.10.tar.gz3401429300806933779.part' to destination file '/Users/Ruud/.gradle/caches/modules-2/files-2.1/com.jetbrains/jbre/jbr-11_0_3-osx-x64-b304.10.tar.gz'.
	at de.undercouch.gradle.tasks.download.DownloadAction.streamAndMove(DownloadAction.java:355)
	at de.undercouch.gradle.tasks.download.DownloadAction.performDownload(DownloadAction.java:320)

I'm inside IntelliJ IDEA and trying to run the runIdle gradle task to launch it (i guess).

@Haehnchen
Copy link
Owner

looks like file permission issue. try checkout in same volume (suggest to use your /Users/... path). /Volumes/CS/ => /Users/Ruud/.

@ruudk
Copy link
Contributor Author

ruudk commented Nov 6, 2019

Wow, it worked! I'm able to run the plugin now. This is so cool. I'm going to have a look and see if I can get it to work 💪

@Haehnchen
Copy link
Owner

Haehnchen commented Jan 3, 2020

fixed via #1415, type name inside popover is still marked as "set", but type detection is working.

popover is now just a priority what should be taken when there are more then 1 type.

@ruudk
Copy link
Contributor Author

ruudk commented Jan 6, 2020

Tested it out, and it works when I specify it with {# @var variable FQCN #} (like I describe in the issue).

However, it would be even smarter if I didn't have to to the {# @var .. #} at all, since it already knows the type of websites variable. It's an array of \App\Website.

@drjayvee
Copy link

drjayvee commented Mar 5, 2021

This may not be related, but I'm a bit confused why the following doesn't work:

{# @var ob \Type #}

{{ ob.thing.prop }} works really well!

{% set thing = ob.thing %}
{{ thing.prop }} no type info

PHPStorm knows ob.thing's type, but not thing's.

@ruudk ruudk closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants