From a3bd71020cd4d581961ef0ecb9b95d413023a68b Mon Sep 17 00:00:00 2001 From: gmickus Date: Mon, 16 Sep 2024 12:36:34 +0300 Subject: [PATCH 1/2] Update block formatter for colon formatting --- .../block/10finally-block-colon/input.p | 6 ++++++ .../block/10finally-block-colon/target.p | 6 ++++++ resources/functionalTests/block/54catch/input.p | 7 +++++++ resources/functionalTests/block/54catch/target.p | 8 ++++++++ src/v2/formatters/block/BlockFormatter.ts | 16 +++++++++++++--- 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 resources/functionalTests/block/10finally-block-colon/input.p create mode 100644 resources/functionalTests/block/10finally-block-colon/target.p create mode 100644 resources/functionalTests/block/54catch/input.p create mode 100644 resources/functionalTests/block/54catch/target.p diff --git a/resources/functionalTests/block/10finally-block-colon/input.p b/resources/functionalTests/block/10finally-block-colon/input.p new file mode 100644 index 0000000..97b1c4e --- /dev/null +++ b/resources/functionalTests/block/10finally-block-colon/input.p @@ -0,0 +1,6 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": true}*/ + +finally : + message "Inside FINALLY block." view-as alert-box. +end finally. \ No newline at end of file diff --git a/resources/functionalTests/block/10finally-block-colon/target.p b/resources/functionalTests/block/10finally-block-colon/target.p new file mode 100644 index 0000000..97b1c4e --- /dev/null +++ b/resources/functionalTests/block/10finally-block-colon/target.p @@ -0,0 +1,6 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": true}*/ + +finally : + message "Inside FINALLY block." view-as alert-box. +end finally. \ No newline at end of file diff --git a/resources/functionalTests/block/54catch/input.p b/resources/functionalTests/block/54catch/input.p new file mode 100644 index 0000000..9df3099 --- /dev/null +++ b/resources/functionalTests/block/54catch/input.p @@ -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. \ No newline at end of file diff --git a/resources/functionalTests/block/54catch/target.p b/resources/functionalTests/block/54catch/target.p new file mode 100644 index 0000000..72bdc13 --- /dev/null +++ b/resources/functionalTests/block/54catch/target.p @@ -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. \ No newline at end of file diff --git a/src/v2/formatters/block/BlockFormatter.ts b/src/v2/formatters/block/BlockFormatter.ts index 23c33eb..2b2bba1 100644 --- a/src/v2/formatters/block/BlockFormatter.ts +++ b/src/v2/formatters/block/BlockFormatter.ts @@ -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( @@ -119,6 +126,9 @@ export class BlockFormater extends AFormatter implements IFormatter { blockStatementsStartRows = blockStatementsStartRows.map( (currentRow) => currentRow + 1 ); + } else { + // This is a way to ensure that there is no whitespace between the statement and the colon + codeLines[0] = statementWithColon + " " + partAfterColon; } } From 0d98a6e7cc6074348a2c33d80052511a7b1bff34 Mon Sep 17 00:00:00 2001 From: gmickus Date: Mon, 16 Sep 2024 12:43:52 +0300 Subject: [PATCH 2/2] Update colon support --- resources/functionalTests/block/10finally-block-colon/target.p | 2 +- src/v2/formatters/block/BlockFormatter.ts | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/resources/functionalTests/block/10finally-block-colon/target.p b/resources/functionalTests/block/10finally-block-colon/target.p index 97b1c4e..21eca43 100644 --- a/resources/functionalTests/block/10finally-block-colon/target.p +++ b/resources/functionalTests/block/10finally-block-colon/target.p @@ -2,5 +2,5 @@ /* { "AblFormatter.blockFormatting": true}*/ finally : - message "Inside FINALLY block." view-as alert-box. + message "Inside FINALLY block." view-as alert-box. end finally. \ No newline at end of file diff --git a/src/v2/formatters/block/BlockFormatter.ts b/src/v2/formatters/block/BlockFormatter.ts index 2b2bba1..6d11091 100644 --- a/src/v2/formatters/block/BlockFormatter.ts +++ b/src/v2/formatters/block/BlockFormatter.ts @@ -126,9 +126,6 @@ export class BlockFormater extends AFormatter implements IFormatter { blockStatementsStartRows = blockStatementsStartRows.map( (currentRow) => currentRow + 1 ); - } else { - // This is a way to ensure that there is no whitespace between the statement and the colon - codeLines[0] = statementWithColon + " " + partAfterColon; } }