Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

202 the colon of some blocks jumps to the next line if there are spaces before it #204

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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