From 9c97e8fc10dc9e8961e6d3fb6e2af5c853c21ca6 Mon Sep 17 00:00:00 2001 From: gmickus Date: Fri, 13 Sep 2024 12:09:41 +0300 Subject: [PATCH] Improve start block formatting --- .../functionalTests/block/6do-start/input.p | 5 +++++ .../functionalTests/block/6do-start/target.p | 6 ++++++ src/v2/formatters/block/BlockFormatter.ts | 20 +++++++++++-------- 3 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 resources/functionalTests/block/6do-start/input.p create mode 100644 resources/functionalTests/block/6do-start/target.p diff --git a/resources/functionalTests/block/6do-start/input.p b/resources/functionalTests/block/6do-start/input.p new file mode 100644 index 0000000..b9f5d48 --- /dev/null +++ b/resources/functionalTests/block/6do-start/input.p @@ -0,0 +1,5 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": true}*/ + +do while true: a = 3. +end. \ No newline at end of file diff --git a/resources/functionalTests/block/6do-start/target.p b/resources/functionalTests/block/6do-start/target.p new file mode 100644 index 0000000..a130272 --- /dev/null +++ b/resources/functionalTests/block/6do-start/target.p @@ -0,0 +1,6 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": true}*/ + +do while true: + a = 3. +end. \ No newline at end of file diff --git a/src/v2/formatters/block/BlockFormatter.ts b/src/v2/formatters/block/BlockFormatter.ts index cd31bd0..23c33eb 100644 --- a/src/v2/formatters/block/BlockFormatter.ts +++ b/src/v2/formatters/block/BlockFormatter.ts @@ -67,7 +67,7 @@ export class BlockFormater extends AFormatter implements IFormatter { let indexOfColon = -1; let blockStatementsStartRows = node.children .filter((child) => { - if (child.type === ":") { + if (child.type === SyntaxNodeType.ColonKeyword) { indexOfColon = child.startPosition.column; return false; } @@ -129,13 +129,17 @@ export class BlockFormater extends AFormatter implements IFormatter { // adjust delta if (blockStatementsStartRows[n] === lineNumber) { - lineChangeDelta = - parentIndentation + - indentationStep - - FormatterHelper.getActualTextIndentation( - codeLine, - fullText - ); + if (index === 0) { + lineChangeDelta = 0; + } else { + lineChangeDelta = + parentIndentation + + indentationStep - + FormatterHelper.getActualTextIndentation( + codeLine, + fullText + ); + } n++; }