Skip to content

Commit

Permalink
Auto-format commas #187
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Dec 17, 2023
1 parent f9a13cd commit 23bad79
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/main/java/intellij_awk/AwkFormattingModelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.tree.TokenSet;
import intellij_awk.psi.AwkTypes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -43,6 +44,7 @@ public class AwkFormattingModelBuilder implements FormattingModelBuilder {

private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
TokenSet ternaryExpr = TokenSet.create(TERNARY_EXPR, TERNARY_PRINT_EXPR);
TokenSet commaParents = TokenSet.create(GAWK_FUNC_CALL_LIST, EXPR_LST);
return new SpacingBuilder(settings, AwkLanguage.INSTANCE)
.around(binaryOps)
.spaces(1)
Expand Down Expand Up @@ -84,10 +86,10 @@ private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
.spaces(1)
.between(RPAREN, TokenSet.create(STATEMENT, ACTION)) // ) {
.spaces(1)
// .before(COMMA) // TODO taking into account function local params
// .none()
// .after(COMMA)
// .spaces(1)
.beforeInside(COMMA, commaParents)
.none()
.afterInside(COMMA, commaParents)
.spaces(1)
.after(TokenSet.create(PRINT, PRINTF))
.spaces(1)
.between(SIMPLE_PRINT_STATEMENT, OUTPUT_REDIRECTION)
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/intellij_awk/AwkAutoFormatTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class AwkAutoFormatTests extends BasePlatformTestCase {
public void testFile13_2(){ checkByFile(); }
public void testGawk_switch1(){ checkByFile(); }
public void testGawk_switch2(){ checkByFile(); }
public void testCommaInArrIndex(){ checkByFile(); }
public void testCommaInFuncCall(){ checkByFile(); }
public void testCommaInIfIn(){ checkByFile(); }
public void testCommaInFuncParamsNoChange(){ checkByFile(); }
public void testIssue100(){ checkByFile(); }

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/test/testData/auto_format/commaInArrIndex.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
A[a ,b, c]
}
3 changes: 3 additions & 0 deletions src/test/testData/auto_format/commaInArrIndexAfter.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
A[a, b, c]
}
3 changes: 3 additions & 0 deletions src/test/testData/auto_format/commaInFuncCall.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
ff(a ,b, c)
}
3 changes: 3 additions & 0 deletions src/test/testData/auto_format/commaInFuncCallAfter.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
ff(a, b, c)
}
2 changes: 2 additions & 0 deletions src/test/testData/auto_format/commaInFuncParamsNoChange.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
function f(a ,b, c) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
function f(a ,b, c) {
}
3 changes: 3 additions & 0 deletions src/test/testData/auto_format/commaInIfIn.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
if ((a ,b, c) in A) {}
}
3 changes: 3 additions & 0 deletions src/test/testData/auto_format/commaInIfInAfter.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
if ((a, b, c) in A) {}
}
2 changes: 1 addition & 1 deletion src/test/testData/inspection/enforceGlobalVarNaming3.awk
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ BEGIN {
arr["key3"] = "val3"
}
function f() {
split("",arr)
split("", arr)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ BEGIN {
Arr["key3"] = "val3"
}
function f() {
split("",Arr)
split("", Arr)
}

0 comments on commit 23bad79

Please sign in to comment.