google / bamboo-soy

An intellij plugin supporting Closure Template language (Soy)
Apache License 2.0
48 stars 27 forks source link

Expose "Hard wrap at" setting to avoid linebreaks with unintended side effects #163

Open orischwartz opened 5 years ago

orischwartz commented 5 years ago

Closure templates has a potentially dangerous white space collapsing policy:

Consecutive lines are joined according to the following heuristic: if the join location borders a template or HTML tag on either side, the lines are joined with no space. If the join location does not border a template or HTML tag on either side, the lines are joined with exactly one space.

Right now there's no way to disable hard-wrapping without changing the default IntelliJ setting in Editor >> Code Style >> Hard wrap at.

Example:

Before

Closure templates will render the end of this as:

... some text some text

{template .hardWrap}
<div>Welcome to Bamboo Soy page. Long text that will break at 120 columns by default some text some text some <strong>text</strong></div>
{/template}

After formatting

Closure templates will render this with a missing space:

... some text sometext

{template .hardWrap}
  <div>Welcome to Bamboo Soy page. Long text that will break at 120 columns by default some text some text some
    <strong>text</strong></div>
{/template}

Guessing the change would have to be somewhere here but I'm not sure:

https://github.com/google/bamboo-soy/blob/cc6227768fda0789a22a9d096fecdf5f898d5731/src/main/java/com/google/bamboo/soy/format/SoyCodeStyleSettingsProvider.java#L44-L46

johnlinp commented 5 years ago

+1 here.

johnlinp commented 5 years ago

IntelliJ IDEA has a Wrap text option for XML files:

Screen Shot 2019-06-24 at 16 33 08

If you turn it off, the formatter won't break long texts in XML files. I was expecting Bamboo Soy to have something like this. In the OP's example, I wish the formatter just give it an indent and don't wrap the long line:

{template .hardWrap}
  <div>Welcome to Bamboo Soy page. Long text that will break at 120 columns by default some text some text some <strong>text</strong></div>
{/template}