izhangzhihao / intellij-rainbow-brackets

🌈Rainbow Brackets for IntelliJ based IDEs/Android Studio/HUAWEI DevEco Studio/Fleet
https://plugins.jetbrains.com/plugin/10080-rainbow-brackets
GNU General Public License v3.0
4.35k stars 202 forks source link

Jinja2 Template support #2677

Closed nliechti closed 6 months ago

nliechti commented 7 months ago

Please support us before creating a feature request, thanks for your support 😁

Please check

Your programming languages

Expected Behavior

Current Behavior

Code examples

{% if item.nginx_locations|default('') != '' %}
{% for location in item.nginx_locations %}

    location {{ location.path }} {
{% for location_option in location.options | default([]) %}
{% if location_option|regex_search('.*({|})$') %}
        {{ location_option }}
{% else %}
        {{ location_option }};
{% endif %}
{% endfor %}
{% if location.options_block|default('') != '' %}
        {{ location.options_block | indent(8) }}
{% endif %}
{% if location.in_path|default('') != '' %}
        location {{ location.in_path }} {
{% for in_opts in location.in_options %}
            {{ in_opts }};
{% endfor %}
      }
{% endif %}
    }
{% endfor %}
{% endif %}
izhangzhihao commented 6 months ago

I spent several days trying to implement support for Jinja2 templates and found that IntelliJ's support for the Jinja2 template language PSI tree is quite limited. Calculating element hierarchy on my own was a bit challenging, and it was difficult to achieve correctness without built-in IDE support. After trying various workarounds, I have finally found what seems to be a viable implementation. Please install it and provide me with feedback.

image

If it does not work, please config your IDE as follows: https://stackoverflow.com/a/53168017

Tested with Intellij 2020.3 and 2022.3 and 2023.2

nliechti commented 6 months ago

Hey man. Thank you very much for the work you are doing.

Seems to be working perfect on small to medium complex files. Large 150+ lines with dozens of if/for there seem to be some just left uncolored.

Doesn't bother me that much as it is "clearly" not working there and not wrongly colored.

Maybe we get better IDE Support in the future.

izhangzhihao commented 6 months ago

Just made some enhancements, and it looks great with HTML right now:

image