diff --git a/package.json b/package.json index d5f3162..c5c9ceb 100644 --- a/package.json +++ b/package.json @@ -181,11 +181,11 @@ "default": "true", "description": "Enable USING formatting" }, - "AblFormatter.emptyBlockFormatting": { + "AblFormatter.bodyFormatting": { "order": 1000, "type": "boolean", "default": "true", - "description": "Enable EMPTY BLOCK formatting" + "description": "Enable BODY formatting" }, "AblFormatter.propertyFormatting": { "order": 1100, @@ -202,7 +202,7 @@ "AblFormatter.ifFunctionFormattingAddParentheses": { "order": 1201, "type": "string", - "default": "Yes", + "default": "No", "enum": [ "Yes", "No" diff --git a/resources/functionalTests/block/12for-block-end2/input.p b/resources/functionalTests/block/12for-block-end2-disabled/input.p similarity index 52% rename from resources/functionalTests/block/12for-block-end2/input.p rename to resources/functionalTests/block/12for-block-end2-disabled/input.p index 8dc92c9..37f0082 100644 --- a/resources/functionalTests/block/12for-block-end2/input.p +++ b/resources/functionalTests/block/12for-block-end2-disabled/input.p @@ -1,5 +1,6 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": false}*/ +/* { "AblFormatter.bodyFormatting": false, +"AblFormatter.forFormatting": false}*/ for each Customer no-lock: Customer.var += 1. diff --git a/resources/functionalTests/block/12for-block-end2/target.p b/resources/functionalTests/block/12for-block-end2-disabled/target.p similarity index 52% rename from resources/functionalTests/block/12for-block-end2/target.p rename to resources/functionalTests/block/12for-block-end2-disabled/target.p index 8dc92c9..37f0082 100644 --- a/resources/functionalTests/block/12for-block-end2/target.p +++ b/resources/functionalTests/block/12for-block-end2-disabled/target.p @@ -1,5 +1,6 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": false}*/ +/* { "AblFormatter.bodyFormatting": false, +"AblFormatter.forFormatting": false}*/ for each Customer no-lock: Customer.var += 1. diff --git a/resources/functionalTests/block/15for-block-inner2/input.p b/resources/functionalTests/block/15for-block-inner2-disabled/input.p similarity index 50% rename from resources/functionalTests/block/15for-block-inner2/input.p rename to resources/functionalTests/block/15for-block-inner2-disabled/input.p index 9718d0f..cc20aad 100644 --- a/resources/functionalTests/block/15for-block-inner2/input.p +++ b/resources/functionalTests/block/15for-block-inner2-disabled/input.p @@ -1,5 +1,6 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": false}*/ +/* { "AblFormatter.bodyFormatting": false, +"AblFormatter.forFormatting": false}*/ for each Customer no-lock: Customer.var += 1. diff --git a/resources/functionalTests/block/15for-block-inner2/target.p b/resources/functionalTests/block/15for-block-inner2-disabled/target.p similarity index 50% rename from resources/functionalTests/block/15for-block-inner2/target.p rename to resources/functionalTests/block/15for-block-inner2-disabled/target.p index 9718d0f..cc20aad 100644 --- a/resources/functionalTests/block/15for-block-inner2/target.p +++ b/resources/functionalTests/block/15for-block-inner2-disabled/target.p @@ -1,5 +1,6 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": false}*/ +/* { "AblFormatter.bodyFormatting": false, +"AblFormatter.forFormatting": false}*/ for each Customer no-lock: Customer.var += 1. diff --git a/resources/functionalTests/block/17for-block-inner4/input.p b/resources/functionalTests/block/17for-block-inner4-disabled/input.p similarity index 52% rename from resources/functionalTests/block/17for-block-inner4/input.p rename to resources/functionalTests/block/17for-block-inner4-disabled/input.p index 9ca202f..28b0aee 100644 --- a/resources/functionalTests/block/17for-block-inner4/input.p +++ b/resources/functionalTests/block/17for-block-inner4-disabled/input.p @@ -1,5 +1,6 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": false}*/ +/* { "AblFormatter.bodyFormatting": false, +"AblFormatter.forFormatting": false}*/ for each Customer no-lock: Customer.var += 1. diff --git a/resources/functionalTests/block/17for-block-inner4/target.p b/resources/functionalTests/block/17for-block-inner4-disabled/target.p similarity index 52% rename from resources/functionalTests/block/17for-block-inner4/target.p rename to resources/functionalTests/block/17for-block-inner4-disabled/target.p index 9ca202f..28b0aee 100644 --- a/resources/functionalTests/block/17for-block-inner4/target.p +++ b/resources/functionalTests/block/17for-block-inner4-disabled/target.p @@ -1,5 +1,6 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": false}*/ +/* { "AblFormatter.bodyFormatting": false, +"AblFormatter.forFormatting": false}*/ for each Customer no-lock: Customer.var += 1. diff --git a/resources/functionalTests/block/45repeat-block-end1/input.p b/resources/functionalTests/block/45repeat-block-end1/input.p index 11fc3bd..bac821e 100644 --- a/resources/functionalTests/block/45repeat-block-end1/input.p +++ b/resources/functionalTests/block/45repeat-block-end1/input.p @@ -3,4 +3,4 @@ repeat: define variable a as integer no-undo. - end. \ No newline at end of file + end. \ No newline at end of file diff --git a/resources/functionalTests/block/51do-for-block-inner1/input.p b/resources/functionalTests/block/51do-for-block-inner1/input.p index fc9a255..3da3c26 100644 --- a/resources/functionalTests/block/51do-for-block-inner1/input.p +++ b/resources/functionalTests/block/51do-for-block-inner1/input.p @@ -1,5 +1,6 @@ /* formattersettingsoverride */ -/* { "AblFormatter.blockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true, +"AblFormatter.forFormatting": false}*/ do transaction: for each Customer no-lock: diff --git a/resources/functionalTests/block/51do-for-block-inner1/target.p b/resources/functionalTests/block/51do-for-block-inner1/target.p index 90344ec..5c03e7c 100644 --- a/resources/functionalTests/block/51do-for-block-inner1/target.p +++ b/resources/functionalTests/block/51do-for-block-inner1/target.p @@ -1,5 +1,6 @@ /* formattersettingsoverride */ -/* { "AblFormatter.blockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true, +"AblFormatter.forFormatting": false}*/ do transaction: for each Customer no-lock: diff --git a/resources/functionalTests/block/51for-for-block-inner1/input.p b/resources/functionalTests/block/51for-for-block-inner1/input.p index 9b59fba..c19d971 100644 --- a/resources/functionalTests/block/51for-for-block-inner1/input.p +++ b/resources/functionalTests/block/51for-for-block-inner1/input.p @@ -1,5 +1,6 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true, +"AblFormatter.forFormatting": false}*/ for each A no-lock: for each B no-lock where A.id = B.id: diff --git a/resources/functionalTests/block/51for-for-block-inner1/target.p b/resources/functionalTests/block/51for-for-block-inner1/target.p index 097c6be..b0383df 100644 --- a/resources/functionalTests/block/51for-for-block-inner1/target.p +++ b/resources/functionalTests/block/51for-for-block-inner1/target.p @@ -1,5 +1,6 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true, +"AblFormatter.forFormatting": false}*/ for each A no-lock: for each B no-lock where A.id = B.id: diff --git a/resources/functionalTests/emptyBlock/10finally/input.p b/resources/functionalTests/emptyBlock/10finally/input.p index 64c1449..325f871 100644 --- a/resources/functionalTests/emptyBlock/10finally/input.p +++ b/resources/functionalTests/emptyBlock/10finally/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ finally: end finally. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/10finally/target.p b/resources/functionalTests/emptyBlock/10finally/target.p index c7ec459..2e4fe78 100644 --- a/resources/functionalTests/emptyBlock/10finally/target.p +++ b/resources/functionalTests/emptyBlock/10finally/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ finally: end finally. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/11for/input.p b/resources/functionalTests/emptyBlock/11for/input.p index e0c04cc..7d52f5d 100644 --- a/resources/functionalTests/emptyBlock/11for/input.p +++ b/resources/functionalTests/emptyBlock/11for/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.forFormatting": true}*/ for each Customer by Customer.CreditLimit by Customer.Name: end. diff --git a/resources/functionalTests/emptyBlock/11for/target.p b/resources/functionalTests/emptyBlock/11for/target.p index bfcf75d..f1b51da 100644 --- a/resources/functionalTests/emptyBlock/11for/target.p +++ b/resources/functionalTests/emptyBlock/11for/target.p @@ -1,5 +1,7 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.forFormatting": true}*/ -for each Customer by Customer.CreditLimit by Customer.Name: +for each Customer + by Customer.CreditLimit + by Customer.Name: end. diff --git a/resources/functionalTests/emptyBlock/12function/input.p b/resources/functionalTests/emptyBlock/12function/input.p index 2ffe1fd..f00916f 100644 --- a/resources/functionalTests/emptyBlock/12function/input.p +++ b/resources/functionalTests/emptyBlock/12function/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ function fun returns integer (): diff --git a/resources/functionalTests/emptyBlock/12function/target.p b/resources/functionalTests/emptyBlock/12function/target.p index 499c361..604749c 100644 --- a/resources/functionalTests/emptyBlock/12function/target.p +++ b/resources/functionalTests/emptyBlock/12function/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ function fun returns integer (): diff --git a/resources/functionalTests/emptyBlock/13method/input.p b/resources/functionalTests/emptyBlock/13method/input.p index 90f78bd..220ad1a 100644 --- a/resources/functionalTests/emptyBlock/13method/input.p +++ b/resources/functionalTests/emptyBlock/13method/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ class Class final: method public void mt(): diff --git a/resources/functionalTests/emptyBlock/13method/target.p b/resources/functionalTests/emptyBlock/13method/target.p index 7f8170c..35f1604 100644 --- a/resources/functionalTests/emptyBlock/13method/target.p +++ b/resources/functionalTests/emptyBlock/13method/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ class Class final: method public void mt(): diff --git a/resources/functionalTests/emptyBlock/14on_do/input.p b/resources/functionalTests/emptyBlock/14on_do/input.p index ba76ea1..50709d3 100644 --- a/resources/functionalTests/emptyBlock/14on_do/input.p +++ b/resources/functionalTests/emptyBlock/14on_do/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ on choose of b_next, b_prev do: end. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/14on_do/target.p b/resources/functionalTests/emptyBlock/14on_do/target.p index 218d2f0..b59acec 100644 --- a/resources/functionalTests/emptyBlock/14on_do/target.p +++ b/resources/functionalTests/emptyBlock/14on_do/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ on choose of b_next, b_prev do: end. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/15on1/input.p b/resources/functionalTests/emptyBlock/15on1/input.p index d111088..84fd9cf 100644 --- a/resources/functionalTests/emptyBlock/15on1/input.p +++ b/resources/functionalTests/emptyBlock/15on1/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ ON F1 GO. /* F1 will now perform the GO function */ ON F2 HELP. /* F2 will now perform the HELP function */ diff --git a/resources/functionalTests/emptyBlock/15on1/target.p b/resources/functionalTests/emptyBlock/15on1/target.p index d111088..84fd9cf 100644 --- a/resources/functionalTests/emptyBlock/15on1/target.p +++ b/resources/functionalTests/emptyBlock/15on1/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ ON F1 GO. /* F1 will now perform the GO function */ ON F2 HELP. /* F2 will now perform the HELP function */ diff --git a/resources/functionalTests/emptyBlock/16procedure/input.p b/resources/functionalTests/emptyBlock/16procedure/input.p index 5cd9706..6da2b3a 100644 --- a/resources/functionalTests/emptyBlock/16procedure/input.p +++ b/resources/functionalTests/emptyBlock/16procedure/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ procedure proc: end procedure. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/16procedure/target.p b/resources/functionalTests/emptyBlock/16procedure/target.p index ccf684d..f7f199e 100644 --- a/resources/functionalTests/emptyBlock/16procedure/target.p +++ b/resources/functionalTests/emptyBlock/16procedure/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ procedure proc: end procedure. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/17repeat/input.p b/resources/functionalTests/emptyBlock/17repeat/input.p index 0fa9768..dc8e954 100644 --- a/resources/functionalTests/emptyBlock/17repeat/input.p +++ b/resources/functionalTests/emptyBlock/17repeat/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ repeat: end. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/17repeat/target.p b/resources/functionalTests/emptyBlock/17repeat/target.p index 4bdeeea..fdd94d5 100644 --- a/resources/functionalTests/emptyBlock/17repeat/target.p +++ b/resources/functionalTests/emptyBlock/17repeat/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ repeat: end. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/1catch/input.p b/resources/functionalTests/emptyBlock/1catch/input.p index f091a4b..13fce1c 100644 --- a/resources/functionalTests/emptyBlock/1catch/input.p +++ b/resources/functionalTests/emptyBlock/1catch/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ catch oErr as MyErrorType: end catch. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/1catch/target.p b/resources/functionalTests/emptyBlock/1catch/target.p index 7e7fe38..547d1ac 100644 --- a/resources/functionalTests/emptyBlock/1catch/target.p +++ b/resources/functionalTests/emptyBlock/1catch/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ catch oErr as MyErrorType: end catch. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/2class/input.p b/resources/functionalTests/emptyBlock/2class/input.p index 4088a4f..760088c 100644 --- a/resources/functionalTests/emptyBlock/2class/input.p +++ b/resources/functionalTests/emptyBlock/2class/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ class A inherits B: end class. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/2class/target.p b/resources/functionalTests/emptyBlock/2class/target.p index 5ca6f69..a8a4fa6 100644 --- a/resources/functionalTests/emptyBlock/2class/target.p +++ b/resources/functionalTests/emptyBlock/2class/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ class A inherits B: end class. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/3constructor/input.p b/resources/functionalTests/emptyBlock/3constructor/input.p index a74777c..bf298b2 100644 --- a/resources/functionalTests/emptyBlock/3constructor/input.p +++ b/resources/functionalTests/emptyBlock/3constructor/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ class A inherits B: constructor private A(): diff --git a/resources/functionalTests/emptyBlock/3constructor/target.p b/resources/functionalTests/emptyBlock/3constructor/target.p index b91843f..b1217a0 100644 --- a/resources/functionalTests/emptyBlock/3constructor/target.p +++ b/resources/functionalTests/emptyBlock/3constructor/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ class A inherits B: constructor private A(): diff --git a/resources/functionalTests/emptyBlock/4destructor/input.p b/resources/functionalTests/emptyBlock/4destructor/input.p index a0af791..1f94d8e 100644 --- a/resources/functionalTests/emptyBlock/4destructor/input.p +++ b/resources/functionalTests/emptyBlock/4destructor/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ class A inherits B: destructor public A(): diff --git a/resources/functionalTests/emptyBlock/4destructor/target.p b/resources/functionalTests/emptyBlock/4destructor/target.p index 521236e..5429d8e 100644 --- a/resources/functionalTests/emptyBlock/4destructor/target.p +++ b/resources/functionalTests/emptyBlock/4destructor/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ class A inherits B: destructor public A(): diff --git a/resources/functionalTests/emptyBlock/5do/input.p b/resources/functionalTests/emptyBlock/5do/input.p index 51fdf74..1325d31 100644 --- a/resources/functionalTests/emptyBlock/5do/input.p +++ b/resources/functionalTests/emptyBlock/5do/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ do: end. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/5do/target.p b/resources/functionalTests/emptyBlock/5do/target.p index 513adc0..823c964 100644 --- a/resources/functionalTests/emptyBlock/5do/target.p +++ b/resources/functionalTests/emptyBlock/5do/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ do: end. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/6do_on/input.p b/resources/functionalTests/emptyBlock/6do_on/input.p index 969ec08..f2542a4 100644 --- a/resources/functionalTests/emptyBlock/6do_on/input.p +++ b/resources/functionalTests/emptyBlock/6do_on/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ do on error undo, throw: diff --git a/resources/functionalTests/emptyBlock/6do_on/target.p b/resources/functionalTests/emptyBlock/6do_on/target.p index 177b1b4..6dc8627 100644 --- a/resources/functionalTests/emptyBlock/6do_on/target.p +++ b/resources/functionalTests/emptyBlock/6do_on/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ do on error undo, throw: diff --git a/resources/functionalTests/emptyBlock/7do_to/input.p b/resources/functionalTests/emptyBlock/7do_to/input.p index b4b5ae7..c637924 100644 --- a/resources/functionalTests/emptyBlock/7do_to/input.p +++ b/resources/functionalTests/emptyBlock/7do_to/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ do iCount = iTotal to 5: end. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/7do_to/target.p b/resources/functionalTests/emptyBlock/7do_to/target.p index 835282d..285b123 100644 --- a/resources/functionalTests/emptyBlock/7do_to/target.p +++ b/resources/functionalTests/emptyBlock/7do_to/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ do iCount = iTotal to 5: end. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/8do_transaction/input.p b/resources/functionalTests/emptyBlock/8do_transaction/input.p index e63b26f..0bc58ec 100644 --- a/resources/functionalTests/emptyBlock/8do_transaction/input.p +++ b/resources/functionalTests/emptyBlock/8do_transaction/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ do transaction: end. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/8do_transaction/target.p b/resources/functionalTests/emptyBlock/8do_transaction/target.p index 8210da3..84706a5 100644 --- a/resources/functionalTests/emptyBlock/8do_transaction/target.p +++ b/resources/functionalTests/emptyBlock/8do_transaction/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ do transaction: end. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/9do_while/input.p b/resources/functionalTests/emptyBlock/9do_while/input.p index fef9498..c3d09d3 100644 --- a/resources/functionalTests/emptyBlock/9do_while/input.p +++ b/resources/functionalTests/emptyBlock/9do_while/input.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ do while i < 5: end. \ No newline at end of file diff --git a/resources/functionalTests/emptyBlock/9do_while/target.p b/resources/functionalTests/emptyBlock/9do_while/target.p index d13a096..1e32821 100644 --- a/resources/functionalTests/emptyBlock/9do_while/target.p +++ b/resources/functionalTests/emptyBlock/9do_while/target.p @@ -1,5 +1,5 @@ /* formatterSettingsOverride */ -/* { "AblFormatter.emptyBlockFormatting": true}*/ +/* { "AblFormatter.blockFormatting": true}*/ do while i < 5: end. \ No newline at end of file diff --git a/resources/functionalTests/for/1each-false/input.p b/resources/functionalTests/for/1each-false/input.p new file mode 100644 index 0000000..a8ac99f --- /dev/null +++ b/resources/functionalTests/for/1each-false/input.p @@ -0,0 +1,10 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": false, +"AblFormatter.forFormatting": false +}*/ + +for +each +Customer: + Customer.var += 1. +end. \ No newline at end of file diff --git a/resources/functionalTests/for/1each-false/target.p b/resources/functionalTests/for/1each-false/target.p new file mode 100644 index 0000000..a8ac99f --- /dev/null +++ b/resources/functionalTests/for/1each-false/target.p @@ -0,0 +1,10 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": false, +"AblFormatter.forFormatting": false +}*/ + +for +each +Customer: + Customer.var += 1. +end. \ No newline at end of file diff --git a/resources/functionalTests/for/2each-true/input.p b/resources/functionalTests/for/2each-true/input.p new file mode 100644 index 0000000..b554fef --- /dev/null +++ b/resources/functionalTests/for/2each-true/input.p @@ -0,0 +1,10 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": true, +"AblFormatter.forFormatting": true +}*/ + +for +each +Customer: + Customer.var += 1. +end. \ No newline at end of file diff --git a/resources/functionalTests/for/2each-true/target.p b/resources/functionalTests/for/2each-true/target.p new file mode 100644 index 0000000..dbbe313 --- /dev/null +++ b/resources/functionalTests/for/2each-true/target.p @@ -0,0 +1,8 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": true, +"AblFormatter.forFormatting": true +}*/ + +for each Customer: + Customer.var += 1. +end. \ No newline at end of file diff --git a/resources/functionalTests/for/3each-each/input.p b/resources/functionalTests/for/3each-each/input.p new file mode 100644 index 0000000..b16ddb7 --- /dev/null +++ b/resources/functionalTests/for/3each-each/input.p @@ -0,0 +1,8 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true, +"AblFormatter.blockFormatting": true, +"abl.completion.upperCase": true}*/ + +FOR EACH Customer NO-LOCK, EACH Order OF Customer NO-LOCK, EACH OrderLine OF Order NO-LOCK BY Order.PromiseDate BY Customer.CustNum BY OrderLine.LineNum: +DISPLAY Order.PromiseDate. +END. \ No newline at end of file diff --git a/resources/functionalTests/for/3each-each/target.p b/resources/functionalTests/for/3each-each/target.p new file mode 100644 index 0000000..12005a1 --- /dev/null +++ b/resources/functionalTests/for/3each-each/target.p @@ -0,0 +1,13 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true, +"AblFormatter.blockFormatting": true, +"abl.completion.upperCase": true}*/ + +FOR EACH Customer NO-LOCK, + EACH Order OF Customer NO-LOCK, + EACH OrderLine OF Order NO-LOCK + BY Order.PromiseDate + BY Customer.CustNum + BY OrderLine.LineNum: + DISPLAY Order.PromiseDate. +END. \ No newline at end of file diff --git a/resources/functionalTests/for/3each-where/input.p b/resources/functionalTests/for/3each-where/input.p new file mode 100644 index 0000000..7ddeb59 --- /dev/null +++ b/resources/functionalTests/for/3each-where/input.p @@ -0,0 +1,9 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true}*/ + +for each Customer where + Customer.var = 1: + Customer.var += 1. + Customer.var *= 2. + Customer.var /= 3. + end. \ No newline at end of file diff --git a/resources/functionalTests/for/3each-where/target.p b/resources/functionalTests/for/3each-where/target.p new file mode 100644 index 0000000..e46f0b5 --- /dev/null +++ b/resources/functionalTests/for/3each-where/target.p @@ -0,0 +1,9 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true}*/ + +for each Customer where + Customer.var = 1: + Customer.var += 1. + Customer.var *= 2. + Customer.var /= 3. +end. \ No newline at end of file diff --git a/resources/functionalTests/for/3first-by/input.p b/resources/functionalTests/for/3first-by/input.p new file mode 100644 index 0000000..06702de --- /dev/null +++ b/resources/functionalTests/for/3first-by/input.p @@ -0,0 +1,7 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true}*/ + +FOR FIRST Customer NO-LOCK + BY Customer.CreditLimit: + DISPLAY Customer. + END. \ No newline at end of file diff --git a/resources/functionalTests/for/3first-by/target.p b/resources/functionalTests/for/3first-by/target.p new file mode 100644 index 0000000..4b15a9b --- /dev/null +++ b/resources/functionalTests/for/3first-by/target.p @@ -0,0 +1,7 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true}*/ + +FOR FIRST Customer NO-LOCK + BY Customer.CreditLimit: + DISPLAY Customer. +END. \ No newline at end of file diff --git a/resources/functionalTests/for/4each-where3/input.p b/resources/functionalTests/for/4each-where3/input.p new file mode 100644 index 0000000..038c7ab --- /dev/null +++ b/resources/functionalTests/for/4each-where3/input.p @@ -0,0 +1,8 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": false, +"AblFormatter.forFormatting": true +}*/ + +for each Customer where 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/4each-where3/target.p b/resources/functionalTests/for/4each-where3/target.p new file mode 100644 index 0000000..3f9c1e4 --- /dev/null +++ b/resources/functionalTests/for/4each-where3/target.p @@ -0,0 +1,9 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": false, +"AblFormatter.forFormatting": true +}*/ + +for each Customer where + 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/5each-break-by/input.p b/resources/functionalTests/for/5each-break-by/input.p new file mode 100644 index 0000000..90dbf9b --- /dev/null +++ b/resources/functionalTests/for/5each-break-by/input.p @@ -0,0 +1,6 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true}*/ + +FOR EACH Employee NO-LOCK WHERE Employee.Salary > 50000 BREAK BY Employee.Department: + DISPLAY Employee.Department Employee.Name Employee.Salary. +END. diff --git a/resources/functionalTests/for/5each-break-by/target.p b/resources/functionalTests/for/5each-break-by/target.p new file mode 100644 index 0000000..2fcf9b2 --- /dev/null +++ b/resources/functionalTests/for/5each-break-by/target.p @@ -0,0 +1,8 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true}*/ + +FOR EACH Employee NO-LOCK WHERE + Employee.Salary > 50000 + BREAK BY Employee.Department: + DISPLAY Employee.Department Employee.Name Employee.Salary. +END. diff --git a/resources/functionalTests/for/6each-nested/input.p b/resources/functionalTests/for/6each-nested/input.p new file mode 100644 index 0000000..a0d2d32 --- /dev/null +++ b/resources/functionalTests/for/6each-nested/input.p @@ -0,0 +1,15 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true}*/ + +FOR EACH Department NO-LOCK: + DISPLAY Department.Name. + + FOR EACH Employee NO-LOCK WHERE Employee.Department = Department.DepartmentID BREAK BY Employee.JobTitle: + DISPLAY Employee.JobTitle Employee.Name Employee.Salary. + + FOR EACH Project NO-LOCK WHERE Project.EmployeeID = Employee.EmployeeID: + DISPLAY Project.ProjectName Project.StartDate Project.EndDate. + END. + END. +END. + diff --git a/resources/functionalTests/for/6each-nested/target.p b/resources/functionalTests/for/6each-nested/target.p new file mode 100644 index 0000000..ca26682 --- /dev/null +++ b/resources/functionalTests/for/6each-nested/target.p @@ -0,0 +1,18 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true}*/ + +FOR EACH Department NO-LOCK: + DISPLAY Department.Name. + + FOR EACH Employee NO-LOCK WHERE + Employee.Department = Department.DepartmentID + BREAK BY Employee.JobTitle: + DISPLAY Employee.JobTitle Employee.Name Employee.Salary. + + FOR EACH Project NO-LOCK WHERE + Project.EmployeeID = Employee.EmployeeID: + DISPLAY Project.ProjectName Project.StartDate Project.EndDate. + END. + END. +END. + diff --git a/resources/functionalTests/for/7each-complex/input.p b/resources/functionalTests/for/7each-complex/input.p new file mode 100644 index 0000000..1cacc72 --- /dev/null +++ b/resources/functionalTests/for/7each-complex/input.p @@ -0,0 +1,20 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true}*/ + +FOR EACH Customer NO-LOCK + WHERE (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 + BY Customer.State: + DISPLAY Customer.CustomerID + Customer.Name + Customer.Balance + Customer.Region + Customer.Status + Customer.City + Customer.State + Customer.LastOrderDate + Customer.CreditLimit + Customer.SalesRep. +END. diff --git a/resources/functionalTests/for/7each-complex/target.p b/resources/functionalTests/for/7each-complex/target.p new file mode 100644 index 0000000..b296aa1 --- /dev/null +++ b/resources/functionalTests/for/7each-complex/target.p @@ -0,0 +1,20 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.forFormatting": true}*/ + +FOR EACH Customer NO-LOCK WHERE + (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 + BY Customer.State: + DISPLAY Customer.CustomerID + Customer.Name + Customer.Balance + Customer.Region + Customer.Status + Customer.City + Customer.State + Customer.LastOrderDate + Customer.CreditLimit + Customer.SalesRep. +END. diff --git a/resources/functionalTests/if/10-then-same-do-same-else-do/input.p b/resources/functionalTests/if/10-then-same-do-same-else-do/input.p index 39b38c1..b6570f1 100644 --- a/resources/functionalTests/if/10-then-same-do-same-else-do/input.p +++ b/resources/functionalTests/if/10-then-same-do-same-else-do/input.p @@ -1,14 +1,12 @@ /* formatterSettingsOverride */ /* { "AblFormatter.ifFormatting": true, -"AblFormatter.blockFormatting": true, "AblFormatter.ifFormattingThenLocation": "Same", "AblFormatter.ifFormattingDoLocation": "Same"}*/ -if a = b then do: +if a = b then do: return a. end. - - else do: - return b. - end. +else do: + return b. + end. diff --git a/resources/functionalTests/if/10-then-same-do-same-else-do/target.p b/resources/functionalTests/if/10-then-same-do-same-else-do/target.p index 50d0f6c..9b81c0f 100644 --- a/resources/functionalTests/if/10-then-same-do-same-else-do/target.p +++ b/resources/functionalTests/if/10-then-same-do-same-else-do/target.p @@ -1,6 +1,5 @@ /* formatterSettingsOverride */ /* { "AblFormatter.ifFormatting": true, -"AblFormatter.blockFormatting": true, "AblFormatter.ifFormattingThenLocation": "Same", "AblFormatter.ifFormattingDoLocation": "Same"}*/ diff --git a/resources/functionalTests/ifFunction/10else-new-line-in-for/input.p b/resources/functionalTests/ifFunction/10else-new-line-in-for/input.p index 1a825bb..0642d9c 100644 --- a/resources/functionalTests/ifFunction/10else-new-line-in-for/input.p +++ b/resources/functionalTests/ifFunction/10else-new-line-in-for/input.p @@ -1,5 +1,6 @@ /* formatterSettingsOverride */ /* { "AblFormatter.ifFunctionFormatting": true, + "AblFormatter.forFormatting": true, "AblFormatter.ifFunctionFormattingAddParentheses": "No", "AblFormatter.ifFunctionFormattingElseLocation": "New"}*/ diff --git a/resources/functionalTests/ifFunction/10else-new-line-in-for/target.p b/resources/functionalTests/ifFunction/10else-new-line-in-for/target.p index 2830c70..a617cd7 100644 --- a/resources/functionalTests/ifFunction/10else-new-line-in-for/target.p +++ b/resources/functionalTests/ifFunction/10else-new-line-in-for/target.p @@ -1,10 +1,13 @@ /* formatterSettingsOverride */ /* { "AblFormatter.ifFunctionFormatting": true, + "AblFormatter.forFormatting": true, "AblFormatter.ifFunctionFormattingAddParentheses": "No", "AblFormatter.ifFunctionFormattingElseLocation": "New"}*/ -FOR EACH Customer NO-LOCK BY IF Customer.Balance > 10000 THEN 1 - ELSE (IF Customer.Balance > 1000 THEN 2 - ELSE 3) BY Customer.SalesRep: +FOR EACH Customer NO-LOCK + BY IF Customer.Balance > 10000 THEN 1 + 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/11else-new-line-in-for/input.p b/resources/functionalTests/ifFunction/11else-new-line-in-for/input.p new file mode 100644 index 0000000..a264da0 --- /dev/null +++ b/resources/functionalTests/ifFunction/11else-new-line-in-for/input.p @@ -0,0 +1,16 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.ifFunctionFormatting": true, + "AblFormatter.ifFunctionFormattingAddParentheses": "Yes", + "AblFormatter.ifFunctionFormattingElseLocation": "New"}*/ + +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 + BY IF Customer.SalesRep = "John" THEN 1 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/11else-new-line-in-for/target.p b/resources/functionalTests/ifFunction/11else-new-line-in-for/target.p new file mode 100644 index 0000000..0e156bf --- /dev/null +++ b/resources/functionalTests/ifFunction/11else-new-line-in-for/target.p @@ -0,0 +1,18 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.ifFunctionFormatting": true, + "AblFormatter.ifFunctionFormattingAddParentheses": "Yes", + "AblFormatter.ifFunctionFormattingElseLocation": "New"}*/ + +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)))) + BY (IF Customer.SalesRep = "John" THEN 1 + 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/12else-new-line-in-for/input.p b/resources/functionalTests/ifFunction/12else-new-line-in-for/input.p new file mode 100644 index 0000000..a9cdd45 --- /dev/null +++ b/resources/functionalTests/ifFunction/12else-new-line-in-for/input.p @@ -0,0 +1,16 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.ifFunctionFormatting": true, + "AblFormatter.ifFunctionFormattingAddParentheses": "No", + "AblFormatter.ifFunctionFormattingElseLocation": "New"}*/ + +FOR EACH Customer +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 + BY IF Customer.SalesRep = "John" THEN 1 ELSE + IF Customer.SalesRep = "Jane" THEN 2 ELSE + IF Customer.SalesRep = "Doe" THEN 3 ELSE 4 NO-LOCK: + DISPLAY Customer.SalesRep Customer.Balance Customer.Name. + END. + \ No newline at end of file diff --git a/resources/functionalTests/ifFunction/12else-new-line-in-for/target.p b/resources/functionalTests/ifFunction/12else-new-line-in-for/target.p new file mode 100644 index 0000000..8874b16 --- /dev/null +++ b/resources/functionalTests/ifFunction/12else-new-line-in-for/target.p @@ -0,0 +1,18 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.ifFunctionFormatting": true, + "AblFormatter.ifFunctionFormattingAddParentheses": "No", + "AblFormatter.ifFunctionFormattingElseLocation": "New"}*/ + +FOR EACH Customer + 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 + BY IF Customer.SalesRep = "John" THEN 1 + ELSE IF Customer.SalesRep = "Jane" THEN 2 + ELSE IF Customer.SalesRep = "Doe" THEN 3 + ELSE 4 NO-LOCK: + DISPLAY Customer.SalesRep Customer.Balance Customer.Name. +END. + \ 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 44acdd9..c3afc5d 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 @@ -3,8 +3,10 @@ "AblFormatter.ifFunctionFormattingAddParentheses": "Yes", "AblFormatter.ifFunctionFormattingElseLocation": "New"}*/ -FOR EACH Customer NO-LOCK BY (IF Customer.Balance > 10000 THEN 1 - ELSE (IF Customer.Balance > 1000 THEN 2 - ELSE 3)) BY Customer.SalesRep: +FOR EACH Customer NO-LOCK + BY (IF Customer.Balance > 10000 THEN 1 + 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/src/model/SyntaxNodeType.ts b/src/model/SyntaxNodeType.ts index 3b18843..c67cd04 100644 --- a/src/model/SyntaxNodeType.ts +++ b/src/model/SyntaxNodeType.ts @@ -31,10 +31,13 @@ export enum SyntaxNodeType { UndoStatement = "undo_statement", AssignStatement = "assign_statement", Assignment = "assignment", + Identifier = "identifier", SourceCode = "source_code", + ForPhrase = "for_phrase", ForStatement = "for_statement", QueryTuning = "query_tuning", SortClause = "sort_clause", + SortColumn = "sort_column", ComparisonExpression = "comparison_expression", TernaryExpression = "ternary_expression", ParenthesizedExpression = "parenthesized_expression", @@ -57,6 +60,7 @@ export enum SyntaxNodeType { // keywords WhenKeyword = "WHEN", + ByKeyword = "BY", ThenKeyword = "THEN", ElseKeyword = "ELSE", AndKeyword = "AND", @@ -80,6 +84,10 @@ export enum SyntaxNodeType { EachKeyword = "EACH", EndKeyword = "END", IfKeyword = "IF", + ForKeyword = "FOR", + DotKeyword = ".", + ColonKeyword = ":", + CommaKeyword = ",", DefineKeyword = "DEFINE", DefiKeyword = "DEFI", DefKeyword = "DEF", diff --git a/src/v2/formatterFramework/FormatterHelper.ts b/src/v2/formatterFramework/FormatterHelper.ts index 1874241..6887a56 100644 --- a/src/v2/formatterFramework/FormatterHelper.ts +++ b/src/v2/formatterFramework/FormatterHelper.ts @@ -79,6 +79,15 @@ export class FormatterHelper { return ""; } + public static getBodyText( + node: Readonly, + fullText: Readonly + ): string { + let text = this.getCurrentText(node, fullText); + let firstColonIndex = text.indexOf(":"); + return text.substring(firstColonIndex + 1); + } + public static getCurrentTextMultilineAdjust( node: Readonly, fullText: Readonly, diff --git a/src/v2/formatterFramework/enableFormatterDecorators.ts b/src/v2/formatterFramework/enableFormatterDecorators.ts index 168de2f..65a36d9 100644 --- a/src/v2/formatterFramework/enableFormatterDecorators.ts +++ b/src/v2/formatterFramework/enableFormatterDecorators.ts @@ -4,20 +4,22 @@ import { IfFormatter } from "../formatters/if/IfFormatter"; import { DefineFormatter } from "../formatters/define/DefineFormatter"; import { UsingFormatter } from "../formatters/using/UsingFormatter"; import { CaseFormatter } from "../formatters/case/CaseFormatter"; +import { ForFormatter } from "../formatters/for/ForFormatter"; import { IfFunctionFormatter } from "../formatters/ifFunction/IfFunctionFormatter"; -import { EmptyBlockFormatter } from "../formatters/emptyblock/EmptyBlockFormatter"; import { TempTableFormatter } from "../formatters/tempTable/TempTableFormatter"; import { PropertyFormatter } from "../formatters/property/PropertyFormatter"; +import { BodyFormatter } from "../formatters/body/BodyFormatter"; // needed just for enabling decorators. Decorators does not work if there is no usage of a class in the reachable code export function enableFormatterDecorators(): void { AssignFormatter; BlockFormater; + BodyFormatter; IfFormatter; DefineFormatter; UsingFormatter; CaseFormatter; - EmptyBlockFormatter; + ForFormatter; TempTableFormatter; PropertyFormatter; IfFunctionFormatter; diff --git a/src/v2/formatters/block/BlockFormatter.ts b/src/v2/formatters/block/BlockFormatter.ts index 35c18c3..8e8ca68 100644 --- a/src/v2/formatters/block/BlockFormatter.ts +++ b/src/v2/formatters/block/BlockFormatter.ts @@ -22,14 +22,17 @@ export class BlockFormater extends AFormatter implements IFormatter { this.settings = new BlockSettings(configurationManager); } - public match(node: Readonly): boolean { - let found: boolean = false; + match(node: Readonly): boolean { + if (!bodyBlockKeywords.hasFancy(node.type, "")) { + return false; + } - if (bodyBlockKeywords.hasFancy(node.type, "")) { - found = true; + let parent = node.parent; + if (parent === null || parent.type === SyntaxNodeType.ForStatement) { + return false; } - return found; + return true; } public parse( node: Readonly, diff --git a/src/v2/formatters/body/BodyFormatter.ts b/src/v2/formatters/body/BodyFormatter.ts new file mode 100644 index 0000000..7a13bc2 --- /dev/null +++ b/src/v2/formatters/body/BodyFormatter.ts @@ -0,0 +1,229 @@ +import { SyntaxNode } from "web-tree-sitter"; +import { RegisterFormatter } from "../../formatterFramework/formatterDecorator"; +import { IFormatter } from "../../formatterFramework/IFormatter"; +import { CodeEdit } from "../../model/CodeEdit"; +import { FullText } from "../../model/FullText"; +import { AFormatter } from "../AFormatter"; +import { BodySettings } from "./BodySettings"; +import { IConfigurationManager } from "../../../utils/IConfigurationManager"; +import { + bodyBlockKeywords, + SyntaxNodeType, +} from "../../../model/SyntaxNodeType"; +import { FormatterHelper } from "../../formatterFramework/FormatterHelper"; + +@RegisterFormatter +export class BodyFormatter extends AFormatter implements IFormatter { + public static readonly formatterLabel = "bodyFormatting"; + private readonly settings: BodySettings; + + public constructor(configurationManager: IConfigurationManager) { + super(configurationManager); + this.settings = new BodySettings(configurationManager); + } + + public match(node: Readonly): boolean { + if (!bodyBlockKeywords.hasFancy(node.type, "")) { + return false; + } + + let parent = node.parent; + if (parent === null || parent.type !== SyntaxNodeType.ForStatement) { + return false; + } + + return true; + } + public parse( + node: Readonly, + fullText: Readonly + ): CodeEdit | CodeEdit[] | undefined { + let indentationEdits: IndentationEdits[] = []; + + let parent = node.parent; + + if (parent === null) { + return undefined; + } + + let formattingOnStatement = false; + if (parent.type === SyntaxNodeType.DoBlock) { + const grandParent = parent.parent; + if ( + grandParent !== null && + grandParent.type === SyntaxNodeType.OnStatement + ) { + parent = grandParent; + formattingOnStatement = true; + } + } + + const parentIndentation = FormatterHelper.getActualStatementIndentation( + this.getParentIndentationSourceNode(parent), + fullText + ); + + const indentationStep = this.settings.tabSize(); + const blockStatementsStartRows = node.children + .filter((child) => { + if (child.type === ":") { + return false; + } + return true; + }) + .map( + (child) => + child.startPosition.row + + FormatterHelper.getActualTextRow( + FormatterHelper.getCurrentText(child, fullText), + fullText + ) + ); + + const codeLines = FormatterHelper.getBodyText(node, fullText).split( + fullText.eolDelimiter + ); + + let n = 0; + let lineChangeDelta = 0; + codeLines.forEach((codeLine, index) => { + const lineNumber = node.startPosition.row + index; + + // adjust delta + if (blockStatementsStartRows[n] === lineNumber) { + lineChangeDelta = + parentIndentation + + indentationStep - + FormatterHelper.getActualTextIndentation( + codeLine, + fullText + ); + + n++; + } + + if (lineChangeDelta !== 0) { + indentationEdits.push({ + line: index, + lineChangeDelta: lineChangeDelta, + }); + } + }); + + const lastLine = FormatterHelper.getCurrentText(parent, fullText) + .split(fullText.eolDelimiter) + .slice(-1)[0]; + + const parentOfEndNode = formattingOnStatement ? node.parent : parent; + if (parentOfEndNode !== null) { + const endNode = parentOfEndNode.children.find( + (node) => node.type === SyntaxNodeType.EndKeyword + ); + + if (endNode !== undefined) { + const endRowDelta = + parentIndentation - + FormatterHelper.getActualTextIndentation( + lastLine, + fullText + ); + + if (endRowDelta !== 0) { + indentationEdits.push({ + line: parent.endPosition.row - parent.startPosition.row, + lineChangeDelta: endRowDelta, + }); + } + } + } + + return this.getCodeEditsFromIndentationEdits( + node, + fullText, + indentationEdits + ); + } + + private getCodeEditsFromIndentationEdits( + node: SyntaxNode, + fullText: FullText, + indentationEdits: IndentationEdits[] + ): CodeEdit | CodeEdit[] | undefined { + const text = FormatterHelper.getCurrentText(node, fullText); + const newText = this.applyIndentationEdits( + text, + indentationEdits, + fullText + ); + + return this.getCodeEdit(node, text, newText, fullText); + } + + private applyIndentationEdits( + code: string, + edits: IndentationEdits[], + fullText: FullText + ): string { + // Split the code into lines + const lines = code.split(fullText.eolDelimiter); + + // Apply each edit + edits.forEach((edit) => { + const { line, lineChangeDelta } = edit; + + // Ensure the line number is within the range + if (line >= 0 && line < lines.length) { + const currentLine = lines[line]; + // Count current leading spaces + const currentLeadingSpaces = + RegExp(/^\s*/).exec(currentLine)?.[0].length || 0; + // Calculate new indentation + + const newLeadingSpaces = Math.max( + 0, + currentLeadingSpaces + lineChangeDelta + ); + + // Update the line with the new indentation + + lines[line] = + " ".repeat(newLeadingSpaces) + currentLine.trimStart(); + } + }); + + // Join the lines back into a single string + return lines.join(fullText.eolDelimiter); + } + + //refactor + private getParentIndentationSourceNode(node: SyntaxNode): SyntaxNode { + if ( + node.type === SyntaxNodeType.DoBlock && + node.parent?.type === SyntaxNodeType.IfStatement + ) { + return node.parent; + } else if ( + node.type === SyntaxNodeType.DoBlock && + (node.parent?.type === SyntaxNodeType.CaseWhenBranch || + node.parent?.type === SyntaxNodeType.CaseOtherwiseBranch) + ) { + return node.parent; + } else if ( + node.type === SyntaxNodeType.DoBlock && + (node.parent?.type === SyntaxNodeType.ElseIfStatement || + node.parent?.type === SyntaxNodeType.ElseStatement) + ) { + if (node.parent.parent === null) { + return node.parent; + } + + return node.parent.parent; + } + return node; + } +} + +interface IndentationEdits { + line: number; + lineChangeDelta: number; +} diff --git a/src/v2/formatters/body/BodySettings.ts b/src/v2/formatters/body/BodySettings.ts new file mode 100644 index 0000000..4423a0c --- /dev/null +++ b/src/v2/formatters/body/BodySettings.ts @@ -0,0 +1,8 @@ +import { ASettings } from "../ASettings"; + +export class BodySettings extends ASettings { + //empty block settings + public BodyFormatting() { + return !!this.configurationManager.get("bodyFormatting"); + } +} diff --git a/src/v2/formatters/emptyblock/EmptyBlockFormatter.ts b/src/v2/formatters/emptyblock/EmptyBlockFormatter.ts deleted file mode 100644 index 1557591..0000000 --- a/src/v2/formatters/emptyblock/EmptyBlockFormatter.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { SyntaxNode } from "web-tree-sitter"; -import { RegisterFormatter } from "../../formatterFramework/formatterDecorator"; -import { IFormatter } from "../../formatterFramework/IFormatter"; -import { CodeEdit } from "../../model/CodeEdit"; -import { FullText } from "../../model/FullText"; -import { AFormatter } from "../AFormatter"; -import { EmptyBlockSettings } from "./EmptyBlockSettings"; -import { IConfigurationManager } from "../../../utils/IConfigurationManager"; -import { SyntaxNodeType } from "../../../model/SyntaxNodeType"; -import { FormatterHelper } from "../../formatterFramework/FormatterHelper"; - -@RegisterFormatter -export class EmptyBlockFormatter extends AFormatter implements IFormatter { - public static readonly formatterLabel = "emptyBlockFormatting"; - private readonly settings: EmptyBlockSettings; - - public constructor(configurationManager: IConfigurationManager) { - super(configurationManager); - this.settings = new EmptyBlockSettings(configurationManager); - } - - match(node: Readonly): boolean { - // Special case for ON DO block - if (node.type === SyntaxNodeType.DoBlock) { - if ( - node.parent !== null && - node.parent.type === SyntaxNodeType.OnStatement - ) { - return false; - } - } - - // If the node is not a block type, do not match - if ( - node.type !== SyntaxNodeType.DoBlock && - node.type !== SyntaxNodeType.ClassStatement && - node.type !== SyntaxNodeType.CatchStatement && - node.type !== SyntaxNodeType.ConstructorDefinition && - node.type !== SyntaxNodeType.DestructorDefinition && - node.type !== SyntaxNodeType.ForStatement && - node.type !== SyntaxNodeType.FinallyStatement && - node.type !== SyntaxNodeType.OnStatement && - node.type !== SyntaxNodeType.RepeatStatement && - node.type !== SyntaxNodeType.MethodDefinition && - node.type !== SyntaxNodeType.FunctionStatement && - node.type !== SyntaxNodeType.ProcedureStatement && - node.type !== SyntaxNodeType.Getter && - node.type !== SyntaxNodeType.Setter - ) { - return false; - } - - // Do not match if there is a body inside the block - for (let child of node.children) { - if ( - child.type === SyntaxNodeType.Body || - child.type === SyntaxNodeType.CaseBody || - child.type === SyntaxNodeType.ClassBody - ) { - return false; - } - } - return true; - } - parse( - node: Readonly, - fullText: Readonly - ): CodeEdit | CodeEdit[] | undefined { - const text = FormatterHelper.getCurrentText(node, fullText); - - const statementIndentation = - FormatterHelper.getActualStatementIndentation(node, fullText); - - const lastLine = FormatterHelper.getCurrentText(node, fullText) - .split(fullText.eolDelimiter) - .slice(-1)[0]; - - let formattingOnStatement = false; - // Special case for ON DO block: to find the end keyword, we need to search for it from the start of the DO block - if (node.type === SyntaxNodeType.OnStatement) { - const doNode = node.children.find( - (child) => child.type === SyntaxNodeType.DoBlock - ); - if (doNode === undefined) { - return undefined; - } - node = doNode; - formattingOnStatement = true; - } - - const endNode = node.children.find( - (child) => child.type === SyntaxNodeType.EndKeyword - ); - - if (endNode === undefined) { - return undefined; - } - - if (formattingOnStatement) { - // REturn back to ON statement from the DO block - if (node.parent === null) { - return undefined; - } - node = node.parent; - } - - const endRowDelta = - statementIndentation - - FormatterHelper.getActualTextIndentation(lastLine, fullText); - - const indentationEdit: IndentationEdits = { - line: node.endPosition.row - node.startPosition.row, - lineChangeDelta: endRowDelta, - }; - - const newText = this.applyIndentationEdit( - text, - indentationEdit, - fullText - ); - - return this.getCodeEdit(node, text, newText, fullText); - } - - private applyIndentationEdit( - code: string, - indentationEdit: IndentationEdits, - fullText: FullText - ): string { - const lines = code.split(fullText.eolDelimiter); - - const currentLeadingSpaces = - RegExp(/^\s*/).exec(lines[indentationEdit.line])?.[0].length || 0; - const newLeadingSpaces = Math.max( - 0, - currentLeadingSpaces + indentationEdit.lineChangeDelta - ); - - lines[indentationEdit.line] = - " ".repeat(newLeadingSpaces) + - lines[indentationEdit.line].trimStart(); - - return lines.join(fullText.eolDelimiter); - } -} - -interface IndentationEdits { - line: number; - lineChangeDelta: number; -} diff --git a/src/v2/formatters/emptyblock/EmptyBlockSettings.ts b/src/v2/formatters/emptyblock/EmptyBlockSettings.ts deleted file mode 100644 index 4d8b3b6..0000000 --- a/src/v2/formatters/emptyblock/EmptyBlockSettings.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { ASettings } from "../ASettings"; - -export class EmptyBlockSettings extends ASettings { - //empty block settings - public emptyBlockFormatting() { - return !!this.configurationManager.get("emptyBlockFormatting"); - } -} diff --git a/src/v2/formatters/for/ForFormatter.ts b/src/v2/formatters/for/ForFormatter.ts new file mode 100644 index 0000000..9b5346a --- /dev/null +++ b/src/v2/formatters/for/ForFormatter.ts @@ -0,0 +1,284 @@ +import { SyntaxNode } from "web-tree-sitter"; +import { IFormatter } from "../../formatterFramework/IFormatter"; +import { SyntaxNodeType } from "../../../model/SyntaxNodeType"; +import { CodeEdit } from "../../model/CodeEdit"; +import { FullText } from "../../model/FullText"; +import { FormatterHelper } from "../../formatterFramework/FormatterHelper"; +import { AFormatter } from "../AFormatter"; +import { RegisterFormatter } from "../../formatterFramework/formatterDecorator"; +import { ForSettings } from "./ForSettings"; +import { IConfigurationManager } from "../../../utils/IConfigurationManager"; + +@RegisterFormatter +export class ForFormatter extends AFormatter implements IFormatter { + private startColumn = 0; + private forBodyValue = ""; + + public static readonly formatterLabel = "forFormatting"; + private readonly settings: ForSettings; + + public constructor(configurationManager: IConfigurationManager) { + super(configurationManager); + this.settings = new ForSettings(configurationManager); + } + + match(node: Readonly): boolean { + if (node.type === SyntaxNodeType.ForStatement) { + return true; + } + + return false; + } + + parse( + node: Readonly, + fullText: Readonly + ): CodeEdit | CodeEdit[] | undefined { + this.collectForStructure(node, fullText); + + return this.getCodeEdit( + node, + FormatterHelper.getCurrentText(node, fullText), + this.forBodyValue, + fullText + ); + } + + private collectForStructure( + node: SyntaxNode, + fullText: Readonly + ) { + this.startColumn = FormatterHelper.getActualStatementIndentation( + node, + fullText + ); + this.forBodyValue = this.getForStatementBlock(node, fullText); + } + + private getForStatementBlock( + node: SyntaxNode, + fullText: Readonly + ): string { + let resultString = ""; + let alignColumn = 0; + + node.children.forEach((child) => { + if (child.type === SyntaxNodeType.Identifier) { + alignColumn = this.startColumn + resultString.length; + } + resultString = resultString.concat( + this.getForExpressionString(child, fullText, alignColumn) + ); + }); + + return resultString; + } + + private getForExpressionString( + node: SyntaxNode, + fullText: Readonly, + alignColumn: number + ): string { + let newString = ""; + + switch (node.type) { + case SyntaxNodeType.ForKeyword: + case SyntaxNodeType.DotKeyword: + case SyntaxNodeType.ColonKeyword: + case SyntaxNodeType.CommaKeyword: + newString = FormatterHelper.getCurrentText( + node, + fullText + ).trim(); + break; + case SyntaxNodeType.WhereClause: + newString = this.getWhereClauseBlock( + node, + fullText, + alignColumn + ); + break; + case SyntaxNodeType.EndKeyword: + newString = + fullText.eolDelimiter + + " ".repeat(this.startColumn) + + FormatterHelper.getCurrentText(node, fullText).trim(); + break; + case SyntaxNodeType.SortClause: + newString = + fullText.eolDelimiter + + " ".repeat(alignColumn) + + this.getSortClauseText(node, fullText, alignColumn); + break; + case SyntaxNodeType.ForPhrase: + newString = this.getSortClauseBlock( + node, + fullText, + alignColumn + ); + break; + case SyntaxNodeType.Body: + newString = FormatterHelper.getCurrentText( + node, + fullText + ).trim(); + break; + default: + const text = FormatterHelper.getCurrentText( + node, + fullText + ).trim(); + newString = text.length === 0 ? "" : " " + text; + break; + } + + return newString; + } + + private getWhereClauseBlock( + node: SyntaxNode, + fullText: Readonly, + alignColumn: number + ): string { + let resultString = ""; + + node.children.forEach((child) => { + switch (child.type) { + case SyntaxNodeType.WhereKeyword: + resultString = resultString.concat( + " ", + FormatterHelper.getCurrentText(child, fullText).trim(), + fullText.eolDelimiter, + " ".repeat(alignColumn) + ); + break; + default: + const text = FormatterHelper.getCurrentText( + child, + fullText + ).trim(); + resultString = resultString.concat( + text.length === 0 ? "" : " " + text + ); + break; + } + }); + + return resultString; + } + + private getSortClauseText( + node: SyntaxNode, + fullText: Readonly, + alignColumn: number + ): string { + let resultString = ""; + + node.children.forEach((child) => { + resultString = resultString.concat( + this.getSortClauseChildText(child, fullText, alignColumn) + ); + }); + + return resultString; + } + + private getSortClauseChildText( + node: SyntaxNode, + fullText: Readonly, + alignColumn: number + ): string { + let newString = ""; + + switch (node.type) { + case SyntaxNodeType.SortColumn: + newString = ""; + node.children.forEach((child) => { + newString = newString.concat( + this.getSortColumnChildText( + child, + fullText, + alignColumn + ) + ); + }); + break; + default: + const text = FormatterHelper.getCurrentText( + node, + fullText + ).trim(); + newString = text.length === 0 ? "" : " " + text; + break; + } + + return newString; + } + + private getSortColumnChildText( + node: SyntaxNode, + fullText: Readonly, + alignColumn: number + ): string { + let newString = ""; + + switch (node.type) { + case SyntaxNodeType.TernaryExpression: + newString = + " " + + FormatterHelper.addIndentation( + FormatterHelper.getCurrentText(node, fullText).trim(), + -node.startPosition.column + alignColumn + 3, // this assumes that if the sort column contains a ternary expression, then it does not contain anything else + fullText.eolDelimiter + ).trim(); + break; + default: + const text = FormatterHelper.getCurrentText( + node, + fullText + ).trim(); + newString = text.length === 0 ? "" : " " + text; + break; + } + + return newString; + } + + private getSortClauseBlock( + node: SyntaxNode, + fullText: Readonly, + alignColumn: number + ): string { + let resultString = ""; + + node.children.forEach((child) => { + switch (child.type) { + case SyntaxNodeType.EachKeyword: + resultString = resultString.concat( + fullText.eolDelimiter, + " ".repeat(this.startColumn + this.settings.tabSize()), + FormatterHelper.getCurrentText(child, fullText).trim() + ); + break; + case SyntaxNodeType.SortClause: + resultString = resultString.concat( + fullText.eolDelimiter, + " ".repeat(alignColumn), + this.getSortClauseText(child, fullText, alignColumn) + ); + break; + default: + const text = FormatterHelper.getCurrentText( + child, + fullText + ).trim(); + resultString = resultString.concat( + text.length === 0 ? "" : " " + text + ); + break; + } + }); + + return resultString; + } +} diff --git a/src/v2/formatters/for/ForSettings.ts b/src/v2/formatters/for/ForSettings.ts new file mode 100644 index 0000000..9561209 --- /dev/null +++ b/src/v2/formatters/for/ForSettings.ts @@ -0,0 +1,8 @@ +import { ASettings } from "../ASettings"; + +export class ForSettings extends ASettings { + // token settings + public forFormatting() { + return this.configurationManager.get("forFormatting") ? true : false; + } +} \ No newline at end of file