Skip to content

Commit

Permalink
Fix for support
Browse files Browse the repository at this point in the history
  • Loading branch information
gmickus committed Sep 9, 2024
1 parent e68add4 commit 3002e9d
Show file tree
Hide file tree
Showing 20 changed files with 262 additions and 139 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": false,
/* { "AblFormatter.emptyBlockFormatting": false,
"AblFormatter.forFormatting": false}*/

for each Customer no-lock:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": false,
/* { "AblFormatter.emptyBlockFormatting": false,
"AblFormatter.forFormatting": false}*/

for each Customer no-lock:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": false,
/* { "AblFormatter.emptyBlockFormatting": false,
"AblFormatter.forFormatting": false}*/

for each Customer no-lock:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": false,
/* { "AblFormatter.emptyBlockFormatting": false,
"AblFormatter.forFormatting": false}*/

for each Customer no-lock:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": false,
/* { "AblFormatter.emptyBlockFormatting": false,
"AblFormatter.forFormatting": false}*/

for each Customer no-lock:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": false,
/* { "AblFormatter.emptyBlockFormatting": false,
"AblFormatter.forFormatting": false}*/

for each Customer no-lock:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

repeat:
define variable a as integer no-undo.
end.
end.
3 changes: 1 addition & 2 deletions resources/functionalTests/emptyBlock/11for/input.p
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* formatterSettingsOverride */
/* { "AblFormatter.emptyBlockFormatting": true,
"AblFormatter.forFormatting": false}*/
/* { "AblFormatter.forFormatting": true}*/

for each Customer by Customer.CreditLimit by Customer.Name:
end.
7 changes: 4 additions & 3 deletions resources/functionalTests/emptyBlock/11for/target.p
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* formatterSettingsOverride */
/* { "AblFormatter.emptyBlockFormatting": true,
"AblFormatter.forFormatting": false}*/
/* { "AblFormatter.forFormatting": true}*/

for each Customer by Customer.CreditLimit by Customer.Name:
for each Customer
by Customer.CreditLimit
by Customer.Name:
end.
2 changes: 1 addition & 1 deletion resources/functionalTests/for/2each-true/input.p
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
for
each
Customer:
Customer.var += 1.
Customer.var += 1.
end.
2 changes: 1 addition & 1 deletion resources/functionalTests/for/3each-each/input.p
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* formatterSettingsOverride */
/* { "AblFormatter.forFormatting": true,
"AblFormatter.blockFormatting": false,
"AblFormatter.blockFormatting": true,
"abl.completion.upperCase": true}*/

FOR EACH Customer NO-LOCK, EACH Order OF Customer NO-LOCK, EACH OrderLine OF Order NO-LOCK BY Order.PromiseDate BY Customer.CustNum BY OrderLine.LineNum:
Expand Down
11 changes: 7 additions & 4 deletions resources/functionalTests/for/3each-where/input.p
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": false,
/* { "AblFormatter.blockFormatting": true,
"AblFormatter.forFormatting": true
}*/

for each Customer where Customer.var = 1:
Customer.var += 1.
end.
for each Customer where
Customer.var = 1:
Customer.var += 1.
Customer.var *= 2.
Customer.var /= 3.
end.
2 changes: 2 additions & 0 deletions resources/functionalTests/for/3each-where/target.p
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
for each Customer where
Customer.var = 1:
Customer.var += 1.
Customer.var *= 2.
Customer.var /= 3.
end.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/* formatterSettingsOverride */
/* { "AblFormatter.ifFormatting": true,
"AblFormatter.blockFormatting": true,
"AblFormatter.ifFormattingThenLocation": "Same",
"AblFormatter.ifFormattingDoLocation": "Same"}*/

if a = b then do:
if a = b then do:
return a.
end.

else do:
return b.
end.
else do:
return b.
end.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* formatterSettingsOverride */
/* { "AblFormatter.ifFormatting": true,
"AblFormatter.blockFormatting": true,
"AblFormatter.ifFormattingThenLocation": "Same",
"AblFormatter.ifFormattingDoLocation": "Same"}*/

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* formatterSettingsOverride */
/* { "AblFormatter.ifFunctionFormatting": true,
"AblFormatter.ifFunctionFormattingAddParentheses": "No",
"AblFormatter.ifFunctionFormattingElseLocation": "New"}*/

FOR EACH Customer NO-LOCK
BY IF Customer.Balance > 10000 THEN 1 ELSE
IF Customer.Balance > 5000 THEN 1.5 ELSE
IF Customer.Balance > 1000 THEN 2 ELSE
IF Customer.Balance > 500 THEN 2.5 ELSE 3
BY IF Customer.SalesRep = "John" THEN 1 ELSE
IF Customer.SalesRep = "Jane" THEN 2 ELSE
IF Customer.SalesRep = "Doe" THEN 3 ELSE 4:
DISPLAY Customer.SalesRep Customer.Balance Customer.Name.
END.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* formatterSettingsOverride */
/* { "AblFormatter.ifFunctionFormatting": true,
"AblFormatter.ifFunctionFormattingAddParentheses": "No",
"AblFormatter.ifFunctionFormattingElseLocation": "New"}*/

FOR EACH Customer NO-LOCK
BY IF Customer.Balance > 10000 THEN 1
ELSE IF Customer.Balance > 5000 THEN 1.5
ELSE IF Customer.Balance > 1000 THEN 2
ELSE IF Customer.Balance > 500 THEN 2.5
ELSE 3
BY IF Customer.SalesRep = "John" THEN 1
ELSE IF Customer.SalesRep = "Jane" THEN 2
ELSE IF Customer.SalesRep = "Doe" THEN 3
ELSE 4:
DISPLAY Customer.SalesRep Customer.Balance Customer.Name.
END.

2 changes: 1 addition & 1 deletion src/v2/formatterFramework/enableFormatterDecorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import { PropertyFormatter } from "../formatters/property/PropertyFormatter";
// needed just for enabling decorators. Decorators does not work if there is no usage of a class in the reachable code
export function enableFormatterDecorators(): void {
AssignFormatter;
EmptyBlockFormatter;
BlockFormater;
IfFormatter;
DefineFormatter;
UsingFormatter;
CaseFormatter;
ForFormatter;
EmptyBlockFormatter;
TempTableFormatter;
PropertyFormatter;
IfFunctionFormatter;
Expand Down
42 changes: 13 additions & 29 deletions src/v2/formatters/block/BlockFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ export class BlockFormater extends AFormatter implements IFormatter {
this.settings = new BlockSettings(configurationManager);
}

public match(node: Readonly<SyntaxNode>): boolean {
let found: boolean = false;
match(node: Readonly<SyntaxNode>): boolean {
if (!bodyBlockKeywords.hasFancy(node.type, "")) {
return false;
}

if (bodyBlockKeywords.hasFancy(node.type, "")) {
found = true;
let parent = node.parent;
if (parent === null || parent.type === SyntaxNodeType.ForStatement) {
return false;
}

return found;
return true;
}
public parse(
node: Readonly<SyntaxNode>,
Expand Down Expand Up @@ -77,19 +80,14 @@ export class BlockFormater extends AFormatter implements IFormatter {
)
);

console.log(
"Body text:\n " + FormatterHelper.getBodyText(node, fullText)
);
console.log("blockStatement:\n" + blockStatementsStartRows);
const codeLines = FormatterHelper.getBodyText(node, fullText).split(
fullText.eolDelimiter
);
const codeLines = FormatterHelper.getCurrentText(parent, fullText)
.split(fullText.eolDelimiter)
.slice(0, -1);

let n = 0;
let lineChangeDelta = 0;
codeLines.forEach((codeLine, index) => {
const lineNumber = node.startPosition.row + index;
console.log("line nr " + lineNumber + " :\n" + codeLine);
const lineNumber = parent.startPosition.row + index;

// adjust delta
if (blockStatementsStartRows[n] === lineNumber) {
Expand All @@ -101,23 +99,9 @@ export class BlockFormater extends AFormatter implements IFormatter {
fullText
);

console.log(
"ind: " +
parentIndentation +
" " +
indentationStep +
" " +
FormatterHelper.getActualTextIndentation(
codeLine,
fullText
)
);

n++;
}

console.log("myDelta: " + lineChangeDelta);

if (lineChangeDelta !== 0) {
indentationEdits.push({
line: index,
Expand Down Expand Up @@ -154,7 +138,7 @@ export class BlockFormater extends AFormatter implements IFormatter {
}

return this.getCodeEditsFromIndentationEdits(
node,
parent,
fullText,
indentationEdits
);
Expand Down
Loading

0 comments on commit 3002e9d

Please sign in to comment.