Skip to content

Commit

Permalink
Improve start block formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gmickus committed Sep 13, 2024
1 parent c317e9a commit 9c97e8f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions resources/functionalTests/block/6do-start/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

do while true: a = 3.
end.
6 changes: 6 additions & 0 deletions resources/functionalTests/block/6do-start/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

do while true:
a = 3.
end.
20 changes: 12 additions & 8 deletions src/v2/formatters/block/BlockFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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++;
}
Expand Down

0 comments on commit 9c97e8f

Please sign in to comment.