diff --git a/package.json b/package.json index acb7a8af..94815867 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "New", "Same" ], - "description": "Should assigns be located on same or new line after ASSIGN keyword?" + "description": "Should assigns be located on a new line or the same line as the ASSIGN keyword?" }, "AblFormatter.assignFormattingAlignRightExpression": { "order": 102, @@ -73,7 +73,7 @@ "New aligned", "Same" ], - "description": "Should end dot be located on same or new line after ASSIGN statement?" + "description": "Should end dot be located on a new line or the same line as the ASSIGN keyword?" }, "AblFormatter.findFormatting": { "order": 300, @@ -101,12 +101,12 @@ "New", "Same" ], - "description": "Should THEN clause be on a new line or the same line as the WHEN keyword?" + "description": "Should THEN clause be on a new line or the same line as the CASE keyword?" }, "AblFormatter.caseFormattingDoLocation": { "order": 502, "type": "string", - "default": "New", + "default": "Same", "enum": [ "New", "Same" @@ -213,7 +213,7 @@ "New", "Same" ], - "description": "Add a new line before the ELSE?" + "description": "Should ELSE clause be on a new line or the same line as the IF FUNCTION keyword?" }, "AblFormatter.enumFormatting": { "order": 1300, @@ -267,7 +267,7 @@ "AblFormatter.arrayAccessFormattingAddSpaceAfterComma": { "order": 1701, "type": "string", - "default": "No", + "default": "Yes", "enum": [ "Yes", "No" @@ -283,7 +283,7 @@ "AblFormatter.expressionFormattingLogicalLocation": { "order": 1801, "type": "string", - "default": "Same", + "default": "New", "enum": [ "New", "Same" diff --git a/resources/functionalTests/arrayAccess/4-array-literal/target.p b/resources/functionalTests/arrayAccess/4-array-literal/target.p index 51a2b9bc..19a16881 100644 --- a/resources/functionalTests/arrayAccess/4-array-literal/target.p +++ b/resources/functionalTests/arrayAccess/4-array-literal/target.p @@ -1,4 +1,4 @@ /* formatterSettingsOverride */ /* { "AblFormatter.arrayAccessFormatting": true}*/ -VAR INT[4] myArray = [10,11,12,13]. \ No newline at end of file +VAR INT[4] myArray = [10, 11, 12, 13]. \ No newline at end of file diff --git a/resources/functionalTests/arrayAccess/4-array-literal2/target.p b/resources/functionalTests/arrayAccess/4-array-literal2/target.p index 35a7fb8b..0b261bb3 100644 --- a/resources/functionalTests/arrayAccess/4-array-literal2/target.p +++ b/resources/functionalTests/arrayAccess/4-array-literal2/target.p @@ -1,6 +1,6 @@ /* formatterSettingsOverride */ /* { "AblFormatter.arrayAccessFormatting": true}*/ -DEFINE VARIABLE myArray AS INTEGER EXTENT 5 NO-UNDO INITIAL [10,11,12,13,14]. +DEFINE VARIABLE myArray AS INTEGER EXTENT 5 NO-UNDO INITIAL [10, 11, 12, 13, 14]. DISPLAY myArray[1 FOR 5]. \ No newline at end of file diff --git a/resources/functionalTests/arrayAccess/4-array-literal3-add-space/target.p b/resources/functionalTests/arrayAccess/4-array-literal3-add-space/target.p deleted file mode 100644 index b67c3b9d..00000000 --- a/resources/functionalTests/arrayAccess/4-array-literal3-add-space/target.p +++ /dev/null @@ -1,5 +0,0 @@ -/* formatterSettingsOverride */ -/* { "AblFormatter.arrayAccessFormatting": true, - "AblFormatter.arrayAccessFormattingAddSpaceAfterComma": "Yes"}*/ - -VAR INT[] monthlySalesQuotas = [100500, 125000, 125000, 175000, 150000, 155000, 145000]. \ No newline at end of file diff --git a/resources/functionalTests/arrayAccess/4-array-literal3-no-space/input.p b/resources/functionalTests/arrayAccess/4-array-literal3-no-space/input.p new file mode 100644 index 00000000..f7bbb127 --- /dev/null +++ b/resources/functionalTests/arrayAccess/4-array-literal3-no-space/input.p @@ -0,0 +1,5 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.arrayAccessFormatting": true, + "AblFormatter.arrayAccessFormattingAddSpaceAfterComma": "No"}*/ + +VAR INT[] monthlySalesQuotas = [ 100500, 125000, 125000, 175000, 150000, 155000, 145000]. \ No newline at end of file diff --git a/resources/functionalTests/arrayAccess/4-array-literal3-add-space/input.p b/resources/functionalTests/arrayAccess/4-array-literal3-no-space/target.p similarity index 69% rename from resources/functionalTests/arrayAccess/4-array-literal3-add-space/input.p rename to resources/functionalTests/arrayAccess/4-array-literal3-no-space/target.p index 27a5db5e..e88d780d 100644 --- a/resources/functionalTests/arrayAccess/4-array-literal3-add-space/input.p +++ b/resources/functionalTests/arrayAccess/4-array-literal3-no-space/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ /* { "AblFormatter.arrayAccessFormatting": true, - "AblFormatter.arrayAccessFormattingAddSpaceAfterComma": "Yes"}*/ + "AblFormatter.arrayAccessFormattingAddSpaceAfterComma": "No"}*/ VAR INT[] monthlySalesQuotas = [100500,125000,125000,175000,150000,155000,145000]. \ No newline at end of file diff --git a/resources/functionalTests/case/12nested-blockFormattingFalse/input.p b/resources/functionalTests/case/12nested/input.p similarity index 91% rename from resources/functionalTests/case/12nested-blockFormattingFalse/input.p rename to resources/functionalTests/case/12nested/input.p index ce29545e..0e6f09a1 100644 --- a/resources/functionalTests/case/12nested-blockFormattingFalse/input.p +++ b/resources/functionalTests/case/12nested/input.p @@ -1,29 +1,29 @@ -/* formatterSettingsOverride */ -/* { "abl.completion.upperCase": true, -"AblFormatter.caseFormatting": true, -"AblFormatter.blockFormatting": false}*/ - -PROCEDURE testCase: - DEFINE VARIABLE i AS INTEGER NO-UNDO. - DEFINE VARIABLE j AS INTEGER NO-UNDO. - - i = 1. - j = 2. - - CASE i: - WHEN 1 THEN DO: - CASE j: - WHEN 1 THEN - MESSAGE "i=1, j=1". - WHEN 2 THEN - MESSAGE "i=1, j=2". - OTHERWISE - MESSAGE "i=1, j=Other". - END CASE. - END. - WHEN 2 THEN - MESSAGE "i=2". - OTHERWISE - MESSAGE "i=Other". - END CASE. +/* formatterSettingsOverride */ +/* { "abl.completion.upperCase": true, +"AblFormatter.caseFormatting": true, +"AblFormatter.blockFormatting": true}*/ + +PROCEDURE testCase: + DEFINE VARIABLE i AS INTEGER NO-UNDO. + DEFINE VARIABLE j AS INTEGER NO-UNDO. + + i = 1. + j = 2. + + CASE i: + WHEN 1 THEN DO: + CASE j: + WHEN 1 THEN + MESSAGE "i=1, j=1". + WHEN 2 THEN + MESSAGE "i=1, j=2". + OTHERWISE + MESSAGE "i=1, j=Other". + END CASE. + END. + WHEN 2 THEN + MESSAGE "i=2". + OTHERWISE + MESSAGE "i=Other". + END CASE. END PROCEDURE. \ No newline at end of file diff --git a/resources/functionalTests/case/12nested-blockFormattingFalse/target.p b/resources/functionalTests/case/12nested/target.p similarity index 56% rename from resources/functionalTests/case/12nested-blockFormattingFalse/target.p rename to resources/functionalTests/case/12nested/target.p index 30d7ecc6..4dbbaad5 100644 --- a/resources/functionalTests/case/12nested-blockFormattingFalse/target.p +++ b/resources/functionalTests/case/12nested/target.p @@ -1,30 +1,29 @@ -/* formatterSettingsOverride */ -/* { "abl.completion.upperCase": true, -"AblFormatter.caseFormatting": true, -"AblFormatter.blockFormatting": false}*/ - -PROCEDURE testCase: - DEFINE VARIABLE i AS INTEGER NO-UNDO. - DEFINE VARIABLE j AS INTEGER NO-UNDO. - - i = 1. - j = 2. - - CASE i: - WHEN 1 THEN - DO: - CASE j: - WHEN 1 THEN - MESSAGE "i=1, j=1". - WHEN 2 THEN - MESSAGE "i=1, j=2". - OTHERWISE - MESSAGE "i=1, j=Other". - END CASE. - END. - WHEN 2 THEN - MESSAGE "i=2". - OTHERWISE - MESSAGE "i=Other". - END CASE. +/* formatterSettingsOverride */ +/* { "abl.completion.upperCase": true, +"AblFormatter.caseFormatting": true, +"AblFormatter.blockFormatting": true}*/ + +PROCEDURE testCase: + DEFINE VARIABLE i AS INTEGER NO-UNDO. + DEFINE VARIABLE j AS INTEGER NO-UNDO. + + i = 1. + j = 2. + + CASE i: + WHEN 1 THEN DO: + CASE j: + WHEN 1 THEN + MESSAGE "i=1, j=1". + WHEN 2 THEN + MESSAGE "i=1, j=2". + OTHERWISE + MESSAGE "i=1, j=Other". + END CASE. + END. + WHEN 2 THEN + MESSAGE "i=2". + OTHERWISE + MESSAGE "i=Other". + END CASE. END PROCEDURE. \ No newline at end of file diff --git a/resources/functionalTests/case/4nested-blockFormattingTrue/target.p b/resources/functionalTests/case/4nested-blockFormattingTrue/target.p index 3f93798d..a0e4a371 100644 --- a/resources/functionalTests/case/4nested-blockFormattingTrue/target.p +++ b/resources/functionalTests/case/4nested-blockFormattingTrue/target.p @@ -11,8 +11,7 @@ PROCEDURE testCase: j = 2. CASE i: - WHEN 1 THEN - DO: + WHEN 1 THEN DO: CASE j: WHEN 1 THEN MESSAGE "i=1, j=1". diff --git a/resources/functionalTests/defineVariable/2no-undo4/target.p b/resources/functionalTests/defineVariable/2no-undo4/target.p index 8ce16abd..b64eb544 100644 --- a/resources/functionalTests/defineVariable/2no-undo4/target.p +++ b/resources/functionalTests/defineVariable/2no-undo4/target.p @@ -6,7 +6,7 @@ DEFINE VARIABLE iAge AS INTEGER NO-UNDO LABEL "Age of Person" INITIAL 0. DEFINE VARIABLE dBirthDate AS DATE NO-UNDO FORMAT "99/99/9999" INITIAL TODAY. DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO INITIAL BUFFER Customer:HANDLE. DEFINE VARIABLE mData AS MEMPTR NO-UNDO INITIAL ?. -DEFINE VARIABLE cJson AS CHARACTER NO-UNDO EXTENT 5 INITIAL ["","","","",""]. +DEFINE VARIABLE cJson AS CHARACTER NO-UNDO EXTENT 5 INITIAL ["", "", "", "", ""]. DEFINE VARIABLE rAmount AS DECIMAL NO-UNDO FORMAT "->,>>>,>>9.99" INITIAL 0. DEFINE VARIABLE lFlag AS LOGICAL NO-UNDO INITIAL FALSE. DEFINE VARIABLE cXml AS LONGCHAR NO-UNDO INITIAL "". \ No newline at end of file diff --git a/resources/functionalTests/defineVariable/4define-protected/target.p b/resources/functionalTests/defineVariable/4define-protected/target.p index 801f242b..72577edb 100644 --- a/resources/functionalTests/defineVariable/4define-protected/target.p +++ b/resources/functionalTests/defineVariable/4define-protected/target.p @@ -6,5 +6,5 @@ define protected variable mBuffer as handle no-undo. define protected variable ValidRecordsPerBlockNumbers as char no-undo init "1,2,4,8,16,32,64,128,256". define protected variable ValidRecordsPerBlockString as char no-undo init "1, 2, 4, 8, 16, 32, 64, 128 and 256". /* area type names */ -define protected variable AreaTypeNames as char no-undo extent 7 init ["Undefined","Undefined","Recovery","Transaction log","Event log","Data","Rollforward recovery"]. +define protected variable AreaTypeNames as char no-undo extent 7 init ["Undefined", "Undefined", "Recovery", "Transaction log", "Event log", "Data", "Rollforward recovery"]. diff --git a/resources/functionalTests/find/2multipleConditions/target.p b/resources/functionalTests/find/2multipleConditions/target.p index fe069370..66537540 100644 --- a/resources/functionalTests/find/2multipleConditions/target.p +++ b/resources/functionalTests/find/2multipleConditions/target.p @@ -2,4 +2,6 @@ /* { "AblFormatter.findFormatting": true}*/ FIND Customer WHERE - Customer.CustNum = 5 AND Customer.CustNum = 6 OR Customer.CustNum = 8 no-lock no-error. \ No newline at end of file + Customer.CustNum = 5 AND + Customer.CustNum = 6 OR + Customer.CustNum = 8 no-lock no-error. \ No newline at end of file diff --git a/resources/functionalTests/find/3multipleConditions-()/target.p b/resources/functionalTests/find/3multipleConditions-()/target.p index 2cdc88aa..c01fd7c6 100644 --- a/resources/functionalTests/find/3multipleConditions-()/target.p +++ b/resources/functionalTests/find/3multipleConditions-()/target.p @@ -2,4 +2,6 @@ /* { "AblFormatter.findFormatting": true}*/ FIND Customer WHERE - (Customer.CustNum > 50 AND Customer.CustNum < 100) OR Customer.CustNum > 200 NO-ERROR. \ No newline at end of file + (Customer.CustNum > 50 AND + Customer.CustNum < 100) OR + Customer.CustNum > 200 NO-ERROR. \ No newline at end of file diff --git a/resources/functionalTests/find/4multipleConditions-()2/target.p b/resources/functionalTests/find/4multipleConditions-()2/target.p index 39b6cdf3..7d105d81 100644 --- a/resources/functionalTests/find/4multipleConditions-()2/target.p +++ b/resources/functionalTests/find/4multipleConditions-()2/target.p @@ -2,4 +2,7 @@ /* { "AblFormatter.findFormatting": true}*/ FIND Order WHERE - (Order.OrderStatus = "Shipped" AND (Order.ShipDate > TODAY - 7)) OR (Order.OrderStatus = "Pending" AND (Order.OrderDate = TODAY)) no-lock. \ No newline at end of file + (Order.OrderStatus = "Shipped" AND + (Order.ShipDate > TODAY - 7)) OR + (Order.OrderStatus = "Pending" AND + (Order.OrderDate = TODAY)) no-lock. \ No newline at end of file diff --git a/resources/functionalTests/find/6useIndex/target.p b/resources/functionalTests/find/6useIndex/target.p index 4b8db549..15e85a88 100644 --- a/resources/functionalTests/find/6useIndex/target.p +++ b/resources/functionalTests/find/6useIndex/target.p @@ -2,4 +2,5 @@ /* { "AblFormatter.findFormatting": true}*/ find Order where - Order.OrderStatus = "Shipped" and Order.ShipDate = today use-index OrderNum. \ No newline at end of file + Order.OrderStatus = "Shipped" and + Order.ShipDate = today use-index OrderNum. \ No newline at end of file diff --git a/resources/functionalTests/find/7of-table/target.p b/resources/functionalTests/find/7of-table/target.p index f840fb91..0fbadb50 100644 --- a/resources/functionalTests/find/7of-table/target.p +++ b/resources/functionalTests/find/7of-table/target.p @@ -2,4 +2,5 @@ /* { "AblFormatter.findFormatting": true}*/ FIND FIRST Order OF Customer WHERE - Customer.Country = "USA" AND Customer.Balance > 1000. \ No newline at end of file + Customer.Country = "USA" AND + Customer.Balance > 1000. \ No newline at end of file diff --git a/resources/functionalTests/for/4each-where3/target.p b/resources/functionalTests/for/4each-where3/target.p index 3f9c1e4c..50bcfb33 100644 --- a/resources/functionalTests/for/4each-where3/target.p +++ b/resources/functionalTests/for/4each-where3/target.p @@ -4,6 +4,8 @@ }*/ for each Customer where - Customer.var = 1 or Customer.var = 2 or Customer.var = 3: + Customer.var = 1 or + Customer.var = 2 or + Customer.var = 3: Customer.var += 1. end. \ No newline at end of file diff --git a/resources/functionalTests/for/7each-complex/target.p b/resources/functionalTests/for/7each-complex/target.p index b296aa14..4ef186fa 100644 --- a/resources/functionalTests/for/7each-complex/target.p +++ b/resources/functionalTests/for/7each-complex/target.p @@ -2,7 +2,10 @@ /* { "AblFormatter.forFormatting": true}*/ FOR EACH Customer NO-LOCK WHERE - (Customer.Balance > 10000 AND Customer.Region = "North") OR (Customer.Region = "South" AND Customer.Status = "Active") + (Customer.Balance > 10000 AND + Customer.Region = "North") OR + (Customer.Region = "South" AND + Customer.Status = "Active") BY Customer.LastName BY Customer.FirstName BREAK BY Customer.City diff --git a/resources/functionalTests/if/18-then-same-do-new/target.p b/resources/functionalTests/if/18-then-same-do-new/target.p index 2ba99ecb..4382a2c5 100644 --- a/resources/functionalTests/if/18-then-same-do-new/target.p +++ b/resources/functionalTests/if/18-then-same-do-new/target.p @@ -5,7 +5,8 @@ "AblFormatter.ifFormattingStatementLocation": "New", "AblFormatter.ifFormattingDoLocation": "New"}*/ -if something <> ? and something <> 0 then +if something <> ? and + something <> 0 then oObject:method(something). else if a = 3 then do: diff --git a/resources/functionalTests/if/19-then-same-do-new/target.p b/resources/functionalTests/if/19-then-same-do-new/target.p index ce610782..4a3d42d4 100644 --- a/resources/functionalTests/if/19-then-same-do-new/target.p +++ b/resources/functionalTests/if/19-then-same-do-new/target.p @@ -5,9 +5,11 @@ "AblFormatter.ifFormattingStatementLocation": "New", "AblFormatter.ifFormattingDoLocation": "New"}*/ -if something <> ? and something <> 0 then +if something <> ? and + something <> 0 then oObject:method(something). -else if something <> ? or something <> ? then +else if something <> ? or + something <> ? then do: oObject:method(something). end. diff --git a/resources/functionalTests/if/20-then-same-statement-new-do-new/target.p b/resources/functionalTests/if/20-then-same-statement-new-do-new/target.p index 3d9d5bb0..06b77524 100644 --- a/resources/functionalTests/if/20-then-same-statement-new-do-new/target.p +++ b/resources/functionalTests/if/20-then-same-statement-new-do-new/target.p @@ -5,7 +5,8 @@ "AblFormatter.ifFormattingStatementLocation": "New", "AblFormatter.ifFormattingDoLocation": "New"}*/ -if something <> ? and something <> 0 then +if something <> ? and + something <> 0 then oObject:method(something). else if a = 3 then do: diff --git a/resources/functionalTests/ifFunction/11else-new-line-in-for/target.p b/resources/functionalTests/ifFunction/11else-new-line-in-for/target.p index 0e156bf1..44c21f6f 100644 --- a/resources/functionalTests/ifFunction/11else-new-line-in-for/target.p +++ b/resources/functionalTests/ifFunction/11else-new-line-in-for/target.p @@ -5,14 +5,14 @@ FOR EACH Customer NO-LOCK BY (IF Customer.Balance > 10000 THEN 1 - ELSE (IF Customer.Balance > 5000 THEN 1.5 - ELSE (IF Customer.Balance > 1000 THEN 2 - ELSE (IF Customer.Balance > 500 THEN 2.5 - ELSE 3)))) + ELSE (IF Customer.Balance > 5000 THEN 1.5 + ELSE (IF Customer.Balance > 1000 THEN 2 + ELSE (IF Customer.Balance > 500 THEN 2.5 + ELSE 3)))) BY (IF Customer.SalesRep = "John" THEN 1 - ELSE (IF Customer.SalesRep = "Jane" THEN 2 - ELSE (IF Customer.SalesRep = "Doe" THEN 3 - ELSE 4))): + ELSE (IF Customer.SalesRep = "Jane" THEN 2 + ELSE (IF Customer.SalesRep = "Doe" THEN 3 + ELSE 4))): DISPLAY Customer.SalesRep Customer.Balance Customer.Name. END. \ No newline at end of file diff --git a/resources/functionalTests/ifFunction/3parentheses-expression-with-and/target.p b/resources/functionalTests/ifFunction/3parentheses-expression-with-and/target.p index 932a0352..28fb13a5 100644 --- a/resources/functionalTests/ifFunction/3parentheses-expression-with-and/target.p +++ b/resources/functionalTests/ifFunction/3parentheses-expression-with-and/target.p @@ -2,4 +2,5 @@ /* { "AblFormatter.ifFunctionFormatting": true, "AblFormatter.ifFunctionFormattingAddParentheses": "Yes"}*/ -a = (if Customer.Balance > 10000 and Customer.Country = "USA" then 1 else 2). \ No newline at end of file +a = (if Customer.Balance > 10000 and + Customer.Country = "USA" then 1 else 2). \ No newline at end of file diff --git a/resources/functionalTests/ifFunction/5parentheses-else-new-line/target.p b/resources/functionalTests/ifFunction/5parentheses-else-new-line/target.p index 96ce27ad..db2c8ab7 100644 --- a/resources/functionalTests/ifFunction/5parentheses-else-new-line/target.p +++ b/resources/functionalTests/ifFunction/5parentheses-else-new-line/target.p @@ -4,4 +4,4 @@ "AblFormatter.ifFunctionFormattingElseLocation": "New"}*/ a = (if Customer.Balance > 10000 then 1 - else 2). \ No newline at end of file + else 2). \ No newline at end of file diff --git a/resources/functionalTests/ifFunction/7parentheses-else-new-line-in-for/target.p b/resources/functionalTests/ifFunction/7parentheses-else-new-line-in-for/target.p index c3afc5d4..22c2db25 100644 --- a/resources/functionalTests/ifFunction/7parentheses-else-new-line-in-for/target.p +++ b/resources/functionalTests/ifFunction/7parentheses-else-new-line-in-for/target.p @@ -5,8 +5,8 @@ FOR EACH Customer NO-LOCK BY (IF Customer.Balance > 10000 THEN 1 - ELSE (IF Customer.Balance > 1000 THEN 2 - ELSE 3)) + ELSE (IF Customer.Balance > 1000 THEN 2 + ELSE 3)) BY Customer.SalesRep: DISPLAY Customer.SalesRep Customer.Balance Customer.Name. END. \ No newline at end of file diff --git a/resources/functionalTests/ifFunction/8parentheses-else-new-line-complex-expression/target.p b/resources/functionalTests/ifFunction/8parentheses-else-new-line-complex-expression/target.p index c2f6d078..93ba7acb 100644 --- a/resources/functionalTests/ifFunction/8parentheses-else-new-line-complex-expression/target.p +++ b/resources/functionalTests/ifFunction/8parentheses-else-new-line-complex-expression/target.p @@ -4,8 +4,8 @@ "AblFormatter.ifFunctionFormattingElseLocation": "New"}*/ result = (IF i > j THEN (IF j > k THEN "i > j > k" - ELSE (IF i > k THEN "i > k > j" - ELSE "k > i > j")) - ELSE (IF j > k THEN (IF i > k THEN "j > i > k" - ELSE "j > k > i") - ELSE "k > j > i")). + ELSE (IF i > k THEN "i > k > j" + ELSE "k > i > j")) + ELSE (IF j > k THEN (IF i > k THEN "j > i > k" + ELSE "j > k > i") + ELSE "k > j > i")). diff --git a/src/formatters/expression/ExpressionFormatter.ts b/src/formatters/expression/ExpressionFormatter.ts index 9c56e45c..ed147325 100644 --- a/src/formatters/expression/ExpressionFormatter.ts +++ b/src/formatters/expression/ExpressionFormatter.ts @@ -52,6 +52,7 @@ export class ExpressionFormatter extends AFormatter implements IFormatter { let newText = ""; if ( node.type === SyntaxNodeType.LogicalExpression && + node.parent?.type !== SyntaxNodeType.CaseCondition && this.settings.newLineAfterLogical() ) { newText = this.collectLogicalStructure(node, fullText); @@ -76,11 +77,19 @@ export class ExpressionFormatter extends AFormatter implements IFormatter { this.settings.newLineAfterLogical() && !this.hasLogicalExpressionParent(node) ) { - resultString = FormatterHelper.addIndentation( - resultString, - node.startPosition.column, - fullText.eolDelimiter - ); + const parent = node.parent; + if ( + parent !== null && + parent.type === SyntaxNodeType.CaseCondition + ) { + resultString = resultString.trim(); + } else { + resultString = FormatterHelper.addIndentation( + resultString, + node.startPosition.column, + fullText.eolDelimiter + ); + } } return resultString; diff --git a/src/formatters/find/FindFormatter.ts b/src/formatters/find/FindFormatter.ts index c69076df..8161b23d 100644 --- a/src/formatters/find/FindFormatter.ts +++ b/src/formatters/find/FindFormatter.ts @@ -86,6 +86,11 @@ export class FindFormatter extends AFormatter implements IFormatter { fullText, alignColumn ); + newString = FormatterHelper.alignIndentation( + newString, + alignColumn + 1, + fullText.eolDelimiter + ); break; case SyntaxNodeType.Error: newString = FormatterHelper.getCurrentText(node, fullText); diff --git a/src/formatters/functionParameter/FunctionParameterFormatter.ts b/src/formatters/functionParameter/FunctionParameterFormatter.ts index d71edd28..a3a4f941 100644 --- a/src/formatters/functionParameter/FunctionParameterFormatter.ts +++ b/src/formatters/functionParameter/FunctionParameterFormatter.ts @@ -53,8 +53,6 @@ export class FunctionParameterFormatter return undefined; } - // console.log("Parameters: " + numberOfFunctionParameters); - // console.log("nodeParent: " + node.type); if ( node.parent !== null && node.parent.type === SyntaxNodeType.FunctionStatement && @@ -64,16 +62,9 @@ export class FunctionParameterFormatter return undefined; return this.getCodeEdit(node, oldText, oldText, fullText); } - node.children.forEach((child) => { - // console.log("childType: " + child.type); - }); this.collectStructure(node, fullText); - // console.log("alignType: " + this.alignType); - // console.log("alignParameterType: " + this.alignParameterType); const newText = this.collectString(node, fullText); - // console.log("oldText: " + oldText); - // console.log("newText: " + newText); return this.getCodeEdit(node, oldText, newText, fullText); } diff --git a/src/formatters/ifFunction/IfFunctionFormatter.ts b/src/formatters/ifFunction/IfFunctionFormatter.ts index 1a22c938..49830622 100644 --- a/src/formatters/ifFunction/IfFunctionFormatter.ts +++ b/src/formatters/ifFunction/IfFunctionFormatter.ts @@ -41,6 +41,18 @@ export class IfFunctionFormatter extends AFormatter implements IFormatter { parent.type !== SyntaxNodeType.ParenthesizedExpression ) { newText = this.addParenthesesAroundExpression(newText); + if (!this.hasTernaryExpressionParent(node)) { + /* + The expression gets pushed by 1 space since the '(' is added at the start + */ + const delta = + 1 + (this.settings.newLineBeforeElse() ? 1 : 0); + newText = FormatterHelper.addIndentation( + newText, + delta, + fullText.eolDelimiter + ); + } } } @@ -63,13 +75,17 @@ export class IfFunctionFormatter extends AFormatter implements IFormatter { this.settings.newLineBeforeElse() && !this.hasTernaryExpressionParent(node) ) { + const delta = + node.startPosition.column + + FormatterHelper.getActualTextIndentation( + resultString, + fullText + ) - + (this.settings.addParentheses() ? 1 : 0); + resultString = FormatterHelper.addIndentation( resultString, - node.startPosition.column + - FormatterHelper.getActualTextIndentation( - resultString, - fullText - ), + delta, fullText.eolDelimiter ); } diff --git a/src/model/SyntaxNodeType.ts b/src/model/SyntaxNodeType.ts index f8b0ec87..3c1baf8a 100644 --- a/src/model/SyntaxNodeType.ts +++ b/src/model/SyntaxNodeType.ts @@ -5,6 +5,7 @@ export enum SyntaxNodeType { AvailableExpression = "available_expression", CaseStatement = "case_statement", + CaseCondition = "case_conditon", CaseBody = "case_body", CaseWhenBranch = "case_when_branch", CaseOtherwiseBranch = "case_otherwise_branch", diff --git a/src/utils/ConfigurationManager.ts b/src/utils/ConfigurationManager.ts index 462ca086..f0d86f54 100644 --- a/src/utils/ConfigurationManager.ts +++ b/src/utils/ConfigurationManager.ts @@ -19,7 +19,6 @@ export class ConfigurationManager implements IConfigurationManager { "ABL Formatter settings were changed!" ); } - if (e.affectsConfiguration("abl.completion")) { this.reloadExternalConfig = true; window.showInformationMessage(