mblode / vscode-twig-language

VS Code extension with snippets, syntax highlighting, hover, and formatting for Twig.
https://marketplace.visualstudio.com/items?itemName=mblode.twig-language
MIT License
42 stars 7 forks source link

Formatting issues... #6

Open jimblue opened 6 years ago

jimblue commented 6 years ago

this:

screen shot 2017-12-03 at 09 19 41

format into this:

screen shot 2017-12-03 at 09 19 50

Pretty hard to read!

jimblue commented 6 years ago

an other one, this:

screen shot 2017-12-03 at 12 30 57

format into this:

screen shot 2017-12-03 at 12 31 03

This is breaking...

dhensen commented 6 years ago

Awesome plugin! 👍 Unfortunately it also messes things up for me.

<form class="form form-login" action="{{ path("fos_user_security_check") }}" method="post">

Becomes:

<form class="form form-login" action="{{ path(" fos_user_security_check") }}"="fos_user_security_check") }}"" method="post">
masiorama commented 6 years ago

I have problem formatting switch loops.

jimblue commented 6 years ago

Any update about a fix?

mblode commented 6 years ago

I tried to contact the PrettyDiff developer but they have not gotten back to me. The developer of Atom-Beautify also hopped onto the issue and was explaining the problems he is having too.

Here is the issue on PrettyDiff https://github.com/prettydiff/prettydiff/issues/502 and maybe we can all jump on and raise all of the issue we are having so maybe the developer will be responsive

jimblue commented 6 years ago

Hi @mblode ! Seems that Prettydiff branch 3.0.0 solved a lot of issues tagged pretty diff here. Did you try to use this version?

mblode commented 6 years ago

Oh sweet! I'll check it out tomorrow 👍 Thanks for being on top of this

mblode commented 6 years ago

@jimblue I went through the codebase and I don't think PrettyDiff 3.0.0 is ready for production yet. Do you have any idea of the timeline?

jimblue commented 6 years ago

Hey @mblode, here is the answer to your question ✨✨✨

https://github.com/prettydiff/prettydiff/issues/511

jimblue commented 6 years ago

@mblode seem that prettydiff 3.0 development is pretty active! It should be release soon enough but it's already pretty solid :) !! Didn't you had a chance to try vscode-twig-language with prettydiff 3.0?

mblode commented 6 years ago

After some testing with pretty diff 3.0, I believe that some spacing issues are fixed but there are still major problems that break the code and which is not okay. I'll try to get in contact with Pretty Diff to see if the developer can fix these issues.

Fixed:

Fixed example 1:

{% for module in page.collection() if module.advanced.nav.enabled %}

Fixed example 2:

{% for value in ['foo', 'bar', 'baz'] %}

Fixed example 3:

{{var}}

Still broken:

Broken example 1:

<form class="form form-login" action="{{ path("fos_user_security_check") }}" method="post">

Becomes...

<form class="form form-login" action="{{ path(" fos_user_security_check") }}"="fos_user_security_check") }}"" method="post">

Broken example 2:

<p class="hello">Copyright {{ Testing }}{{ Testing }}</p>

Becomes...

<p class="hello">Copyright
    {{ Testing }}
    {{ Testing }}
</p>

Broken example 3:

<input type="hidden" name="test" value="{{ id["index"] }}">

Becomes...

<input type="hidden" name="test" value="{{ id[" index"] }}"="index"] }}"">

Broken example 4:

{% switch variable %}
  {% case "value1" %}
  {% case "value2" %}
  {% default %}
{% endswitch %}

{% some other statement %}

Becomes...

{% switch variable %}
{% case "value1" %}
    {% case "value2" %}
        {% default %}
        {% endswitch %}
        {% some other statement %}

Broken example 5:

<div>
Variable1: {{ variable1 }} / Variable2: {{ Variable2 }}
</div>

Becomes...

<div>
    Variable1:
    {{ variable1 }}
    / Variable2:
    {{ Variable2 }}
</div>
jimblue commented 6 years ago

Hey @mblode,

That's a very good idea to contact Pretty Diff while there still working on V3.0! It's the best time to let them know theses bugs 😄 !

Thank you so much for your help, I can't wait next version of vscode-twig-language!

mblode commented 5 years ago

Hey guys, I have just pushed an update to Twig Language with a brand new formatter using Prettydiff 3 which brings about some major bug fixes. The update has fixed broken example 1 and 3 and I am currently discussing with the lead developer of Pretttydiff about broken example 2 and 4.

Here is his response:

I will think about how to approach example [4]. This isn't a defect, but rather a design decision. I am providing the same spatial relationships to the template tags as I do to text and self-closing tags. Whitespace in XML/HTML rendering is tokenized by default which means in the rendering of output all adjacent white space is collapsed into a single space character. My design decision is to indent where text/self-closing tags are separated by space which helps in identifying tags among long paragraphs of text without regard for word wrap.

Sorry about the slow development speeds and sub-par communication but hopefully these updates have fixed some of your other problems.

masiorama commented 5 years ago

Nice to hear that! The update is not available yet, right? Thanks in advance.

mblode commented 5 years ago

@masiorama Prettydiff 3 is now being used on twig Language 1 and 2, which are both updated and available on the VS Code extension store. Please let me know if you are having any issues.

masiorama commented 5 years ago

This https://pasteboard.co/HVjGrIu.jpg is what I see from VSCode, thanks.

mblode commented 5 years ago

It's definitely bad practice, but I've fully neglected the change-log. I'll make sure everything is up to date on the changelog as soon as I can.

DenisVS commented 4 years ago

Hi! In php cs fixer we have very helpful function "auto-format on save". Would You like to do the same in Your project?