Skip to content

Commit

Permalink
Merge pull request #204 from BalticAmadeus/202-the-colon-of-some-bloc…
Browse files Browse the repository at this point in the history
…ks-jumps-to-the-next-line-if-there-are-spaces-before-it

202 the colon of some blocks jumps to the next line if there are spaces before it
  • Loading branch information
PauliusKu authored Sep 16, 2024
2 parents f27b91f + 0d98a6e commit 248e7c6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions resources/functionalTests/block/10finally-block-colon/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

finally :
message "Inside FINALLY block." view-as alert-box.
end finally.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

finally :
message "Inside FINALLY block." view-as alert-box.
end finally.
7 changes: 7 additions & 0 deletions resources/functionalTests/block/54catch/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

catch oFunkyError as Progress.Lang.AppError : oGroovyResponse:errorStatus = true.
oGroovyResponse:addMessage(oFunkyError:GetMessage(1)).
return oGroovyResponse.
end catch.
8 changes: 8 additions & 0 deletions resources/functionalTests/block/54catch/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

catch oFunkyError as Progress.Lang.AppError:
oGroovyResponse:errorStatus = true.
oGroovyResponse:addMessage(oFunkyError:GetMessage(1)).
return oGroovyResponse.
end catch.
13 changes: 10 additions & 3 deletions src/v2/formatters/block/BlockFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,21 @@ export class BlockFormater extends AFormatter implements IFormatter {
if (indexOfColon !== -1) {
// indexOfColon += parentIndentation;
indexOfColon -= parent.startPosition.column;
for (let i = indexOfColon + 1; i >= indexOfColon - 1; i--) {
if (firstLine[i] === ":") {
indexOfColon = i;
break;
}
}
const partAfterColon = firstLine
.slice(indexOfColon + 1)
.trimStart();
const statementWithColon =
firstLine.slice(0, indexOfColon).trimEnd() + ":";
// If the part after the colon is not only whitespace, put it on the next line
if (partAfterColon.trim().length !== 0) {
const firstPart = firstLine.slice(0, indexOfColon + 1);
if (partAfterColon.trim().length !== 0 && partAfterColon !== ":") {
codeLines.shift(); // pop from the start of the list
codeLines.unshift(firstPart, partAfterColon);
codeLines.unshift(statementWithColon, partAfterColon);
const firstBlockStatementRow = blockStatementsStartRows[0];
blockStatementsStartRows.shift();
blockStatementsStartRows.unshift(
Expand Down

0 comments on commit 248e7c6

Please sign in to comment.