Skip to content

Commit

Permalink
Added wrap/align settings for qw lists
Browse files Browse the repository at this point in the history
  • Loading branch information
hurricup committed Dec 27, 2017
1 parent 8f9c349 commit ec30a64
Show file tree
Hide file tree
Showing 16 changed files with 247 additions and 30 deletions.
2 changes: 1 addition & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<li>aligning comments inside lists, enabled by default, <a href="https://github.com/Camelcade/Perl5-IDEA/issues/1676">#1676</a></li>
<li>wrapping and alignment of ternary expression</li>
<li>wrapping and alignment of variable declarations lists</li>
<li>wrapping and alignment of <code>qw</code> lists elements</li>
</ul>
<li>Formatting for anon subs, hashes, arrays and lists is much better now, by <a href="https://github.com/Camelcade/Perl5-IDEA/issues/1525">@aptituz</a></li>
<li><code>qw</code> list is now formatted like a block, meaning quotes being formatted same way as braces, <a href="https://github.com/Camelcade/Perl5-IDEA/issues/1678">#1678</a></li>
<li><code>qw</code> contents is now wrapped on long lines string or closing quote may be moved to the next line</li>
</ul>
</p>
<p>Fixes:
Expand Down
3 changes: 1 addition & 2 deletions resources/codeStyle/preview/wrapping.code
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ if($a){

my @list = qw/
this is a list
of some cool strings
/;
of some cool strings which should be wrapped somehow /;

say $a == 42 ? 'long true' : 'long expression meaning false';
$a ? $a : $b;
Expand Down
5 changes: 2 additions & 3 deletions resources/messages/PerlBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,13 @@ perl.formatting.sub.signature=Sub signature/prototype
perl.formatting.signature.parentheses=Sub signature/prototype parentheses
perl.formatting.empty.signature.parentheses=Empty sub signature/prototype parentheses
perl.formatting.attribute=Before sub attribute
perl.formatting.group.alignment=Alignment
perl.formatting.align.list.elements=Comma-separated list
perl.formatting.wrap.dereference=Chained dereference
perl.formatting.align.comments.in.list=Align in lists
perl.formatting.align.fat.comma=Align fat commas
perl.formatting.align.qw.elements=qw// elements
perl.formatting.align.qw.elements=Align elements
perl.formatting.align.ternary=? and : in ternary expression
perl.formatting.space.inside.qw=qw// list
perl.qw.list=qw// list
perl.formatting.after.my=After my/our/local/state
perl.formatting.within.hash=Anon hash
perl.formatting.within.array=Anon array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ else if (parentNodeType == COMMA_SEQUENCE_EXPR && childNodeType != COMMA && chil
}
else if (( parentNodeType == STRING_LIST || parentNodeType == LP_STRING_QW) &&
( childNodeType == STRING_CONTENT || childNodeType == QUOTE_SINGLE_CLOSE)) {
return getWrap(parentNode, NORMAL, false);
return getWrapBySettings(parentNode, myPerlSettings.QW_LIST_WRAP, false);
}
else if (childNodeType == VARIABLE_DECLARATION_ELEMENT ||
( childNodeType == RESERVED_UNDEF && VARIABLE_DECLARATIONS.contains(parentNodeType) )) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public class PerlCodeStyleSettings extends CustomCodeStyleSettings {
public boolean SPACE_BEFORE_ATTRIBUTE = true;

public boolean ALIGN_FAT_COMMA = true;

public int QW_LIST_WRAP = DO_NOT_WRAP;
public boolean ALIGN_QW_ELEMENTS = false;

public boolean ALIGN_COMMENTS_IN_LIST = true;

public int BRACE_STYLE_NAMESPACE = SAME_LINE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* Created by hurricup on 03.09.2015.
*/
public class PerlLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider {
private static final String GROUP_ALIGNMENT = PerlBundle.message("perl.formatting.group.alignment");
private static final String GROUP_QW = PerlBundle.message("perl.qw.list");
private static final String GROUP_QUOTATION = PerlBundle.message("perl.formatting.group.optional.quotation");
private static final String GROUP_DEREFERENCE = PerlBundle.message("perl.formatting.group.dereferencing");
private static final String GROUP_PARENTHESES = PerlBundle.message("perl.formatting.group.optional.parentheses");
Expand Down Expand Up @@ -143,7 +143,7 @@ public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer, @

consumer.showCustomOption(PerlCodeStyleSettings.class,
"SPACE_WITHIN_QW_QUOTES",
PerlBundle.message("perl.formatting.space.inside.qw"),
PerlBundle.message("perl.qw.list"),
SPACES_WITHIN);
}
else if (settingsType == WRAPPING_AND_BRACES_SETTINGS) {
Expand Down Expand Up @@ -223,10 +223,18 @@ else if (settingsType == WRAPPING_AND_BRACES_SETTINGS) {
PerlBundle.message("perl.formatting.align.fat.comma"),
GROUP_LIST);

consumer.showCustomOption(PerlCodeStyleSettings.class,
"QW_LIST_WRAP",
GROUP_QW,
null,
AFTER, "ARRAY_INITIALIZER_WRAP",
WRAP_OPTIONS, WRAP_VALUES
);
consumer.showCustomOption(PerlCodeStyleSettings.class,
"ALIGN_QW_ELEMENTS",
PerlBundle.message("perl.formatting.align.qw.elements"),
GROUP_ALIGNMENT);
GROUP_QW);

}
else if (settingsType == LANGUAGE_SPECIFIC) {

Expand Down
21 changes: 20 additions & 1 deletion test/formatter/PerlFormatterWrapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,26 @@ private void doTestTernary(int wrapType, boolean signNewLine) {
doWrappingTestSingleSource("ternary");
}

public void testQwWrapping() {doFormatTest();}
public void testQwListNever() {
doTestQwList(DO_NOT_WRAP);
}

public void testQwListAlways() {
doTestQwList(WRAP_ALWAYS);
}

public void testQwListLong() {
doTestQwList(WRAP_AS_NEEDED);
}

public void testQwListChomp() {
doTestQwList(WRAP_ON_EVERY_ITEM);
}

private void doTestQwList(int wrapType) {
getCustomSettings().QW_LIST_WRAP = wrapType;
doWrappingTestSingleSource("qwList");
}


public void testCommentsWrapTrue() {
Expand Down
3 changes: 1 addition & 2 deletions testData/formatter/perl/spacing/spacingInQwFalse.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
qw/some string here/;
qw/some string here some string here some string here some string here some string here some string here some string
here/;
qw/some string here some string here some string here some string here some string here some string here some string here/;
3 changes: 1 addition & 2 deletions testData/formatter/perl/spacing/spacingInQwTrue.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
qw/ some string here /;
qw/ some string here some string here some string here some string here some string here some string here some string
here /;
qw/ some string here some string here some string here some string here some string here some string here some string here /;
11 changes: 11 additions & 0 deletions testData/formatter/perl/wrap/qwList.code
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Lazy
my @list = qw/
this is a list
of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings/;

my @list = qw/
this is a list
of different strings this /;

my @list = qw/
this is a /;
75 changes: 75 additions & 0 deletions testData/formatter/perl/wrap/qwListAlways.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Lazy
my @list = qw/
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings/;

my @list = qw/
this
is
a
list
of
different
strings
this
/;

my @list = qw/
this
is
a
/;
72 changes: 72 additions & 0 deletions testData/formatter/perl/wrap/qwListChomp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Lazy
my @list = qw/
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings
this
is
a
list
of
different
strings/;

my @list = qw/
this
is
a
list
of
different
strings
this
/;

my @list = qw/
this is a/;
37 changes: 37 additions & 0 deletions testData/formatter/perl/wrap/qwListLong.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Lazy
my @list = qw/
this is a
list
of different
strings this
is a list of
different
strings this
is a list of
different
strings this
is a list of
different
strings this
is a list of
different
strings this
is a list of
different
strings this
is a list of
different
strings this
is a list of
different
strings/;

my @list = qw/
this is a
list
of different
strings this
/;

my @list = qw/
this is a/;
11 changes: 11 additions & 0 deletions testData/formatter/perl/wrap/qwListNever.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Lazy
my @list = qw/
this is a list
of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings/;

my @list = qw/
this is a list
of different strings this/;

my @list = qw/
this is a/;
6 changes: 0 additions & 6 deletions testData/formatter/perl/wrap/qwWrapping.code

This file was deleted.

9 changes: 0 additions & 9 deletions testData/formatter/perl/wrap/qwWrapping.txt

This file was deleted.

0 comments on commit ec30a64

Please sign in to comment.