Skip to content

Commit

Permalink
Update formatter ; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmickus committed Oct 2, 2024
1 parent 6c035cd commit 533262d
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

DEFINE TEMP-TABLE ttCustomer NO-UNDO
FIELD CustNum AS INTEGER
FIELD Name AS CHARACTER.
FIELD Name AS CHARACTER.

DEFINE DATASET dsCustomer FOR ttCustomer.
13 changes: 7 additions & 6 deletions resources/functionalTests/temptable/3-fields/input.p
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
/* { "AblFormatter.temptableFormatting": true,
"abl.completion.upperCase": true}*/

define temp-table ttCustomer no-undo field custNum as integer
DEFINE temp-table ttCustomer no-undo
field custNum as integer
field firstName as character
field lastName as character
field birthDate as date
index custNum is primary unique custNum
index firstName firstName
index lastName lastName .
field lastName as character
field birthDate as date
index custNum is primary unique custNum
index firstName firstName
index lastName lastName.
6 changes: 3 additions & 3 deletions resources/functionalTests/temptable/3-fields/target.p
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"abl.completion.upperCase": true}*/

DEFINE temp-table ttCustomer no-undo
field custNum as integer
field custNum as integer
field firstName as character
field lastName as character
field lastName as character
field birthDate as date
index custNum is primary unique custNum
index firstName firstName
index lastName lastName.
index lastName lastName.
13 changes: 13 additions & 0 deletions resources/functionalTests/temptable/4-fields/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* formatterSettingsOverride */
/* { "AblFormatter.temptableFormatting": true,
"abl.completion.upperCase": true}*/

DEFINE TEMP-TABLE IndexDetails
FIELD tblname AS CHARACTER
FIELD idxname AS CHARACTER
FIELD tdesc AS CHARACTER
FIELD lactive AS LOGICAL
FIELD lprimary AS LOGICAL
FIELD lunique AS LOGICAL
FIELD lwordindex AS LOGICAL
FIELD labbrev AS LOGICAL.
13 changes: 13 additions & 0 deletions resources/functionalTests/temptable/4-fields/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* formatterSettingsOverride */
/* { "AblFormatter.temptableFormatting": true,
"abl.completion.upperCase": true}*/

DEFINE TEMP-TABLE IndexDetails
FIELD tblname AS CHARACTER
FIELD idxname AS CHARACTER
FIELD tdesc AS CHARACTER
FIELD lactive AS LOGICAL
FIELD lprimary AS LOGICAL
FIELD lunique AS LOGICAL
FIELD lwordindex AS LOGICAL
FIELD labbrev AS LOGICAL.
12 changes: 12 additions & 0 deletions resources/functionalTests/temptable/4-fields2/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* formatterSettingsOverride */
/* { "AblFormatter.temptableFormatting": true,
"abl.completion.upperCase": true}*/

DEFINE TEMP-TABLE saSys NO-UNDO RCODE-INFORMATION
FIELD dType AS CHARACTER LABEL "Domain Type" FORMAT "x(25)"
FIELD dDescrip AS CHARACTER LABEL "Description" FORMAT "x(65)"
FIELD dDetails AS CHARACTER LABEL "Comments" FORMAT "x(200)"
FIELD dAuthEnabled AS LOGICAL LABEL "Enable Authentication"
FIELD dChecksum AS LOGICAL LABEL "Checksum"
FIELD dCallback AS CHARACTER LABEL "Callback" FORMAT "x(100)".

12 changes: 12 additions & 0 deletions resources/functionalTests/temptable/4-fields2/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* formatterSettingsOverride */
/* { "AblFormatter.temptableFormatting": true,
"abl.completion.upperCase": true}*/

DEFINE TEMP-TABLE saSys NO-UNDO RCODE-INFORMATION
FIELD dType AS CHARACTER LABEL "Domain Type" FORMAT "x(25)"
FIELD dDescrip AS CHARACTER LABEL "Description" FORMAT "x(65)"
FIELD dDetails AS CHARACTER LABEL "Comments" FORMAT "x(200)"
FIELD dAuthEnabled AS LOGICAL LABEL "Enable Authentication"
FIELD dChecksum AS LOGICAL LABEL "Checksum"
FIELD dCallback AS CHARACTER LABEL "Callback" FORMAT "x(100)".

25 changes: 25 additions & 0 deletions resources/functionalTests/temptable/7-fields-two-tables/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* formatterSettingsOverride */
/* { "AblFormatter.temptableFormatting": true,
"abl.completion.upperCase": true}*/

DEFINE TEMP-TABLE tDataSource
FIELD TargetProc AS HANDLE
FIELD DataSource AS HANDLE
FIELD ObjectName AS CHAR
FIELD DocumentPath AS CHAR /* Consumer only */
FIELD Commit AS LOG
INDEX DataSource AS UNIQUE TargetProc DataSource
INDEX ObjectName ObjectName TargetProc
INDEX DocumentPath DocumentPath TargetProc
INDEX Commit TargetProc Commit.

/** Producer temp-tables **/
/* Register all datasource/methods that update nodes with out parameters */
DEFINE TEMP-TABLE tMethodNode
FIELD TargetProc AS HANDLE
FIELD DataSource AS HANDLE
FIELD Method AS CHAR
FIELD MethodNode AS DEC
FIELD NumParam AS INT
INDEX Method AS UNIQUE TargetProc DataSource Method
INDEX Node TargetProc MethodNode.
25 changes: 25 additions & 0 deletions resources/functionalTests/temptable/7-fields-two-tables/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* formatterSettingsOverride */
/* { "AblFormatter.temptableFormatting": true,
"abl.completion.upperCase": true}*/

DEFINE TEMP-TABLE tDataSource
FIELD TargetProc AS HANDLE
FIELD DataSource AS HANDLE
FIELD ObjectName AS CHAR
FIELD DocumentPath AS CHAR /* Consumer only */
FIELD Commit AS LOG
INDEX DataSource AS UNIQUE TargetProc DataSource
INDEX ObjectName ObjectName TargetProc
INDEX DocumentPath DocumentPath TargetProc
INDEX Commit TargetProc Commit.

/** Producer temp-tables **/
/* Register all datasource/methods that update nodes with out parameters */
DEFINE TEMP-TABLE tMethodNode
FIELD TargetProc AS HANDLE
FIELD DataSource AS HANDLE
FIELD Method AS CHAR
FIELD MethodNode AS DEC
FIELD NumParam AS INT
INDEX Method AS UNIQUE TargetProc DataSource Method
INDEX Node TargetProc MethodNode.
75 changes: 71 additions & 4 deletions src/v2/formatters/tempTable/TempTableFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
export class TempTableFormatter extends AFormatter implements IFormatter {
public static readonly formatterLabel = "temptableFormatting";
private readonly settings: TempTableSettings;

private alignType = 0;
private startColumn = 0;
private temptableValueColumn = 0;
private temptableBodyValue = "";
Expand All @@ -36,13 +36,13 @@ export class TempTableFormatter extends AFormatter implements IFormatter {
node: Readonly<SyntaxNode>,
fullText: Readonly<FullText>
): CodeEdit | CodeEdit[] | undefined {
const text = FormatterHelper.getCurrentText(node, fullText);

this.collectTemptableStructure(node, fullText);
const text = FormatterHelper.getCurrentText(node, fullText);
this.collectTemptableString(node, fullText);
return this.getCodeEdit(node, text, this.temptableBodyValue, fullText);
}

private collectTemptableStructure(node: SyntaxNode, fullText: FullText) {
private collectTemptableString(node: SyntaxNode, fullText: FullText) {
this.startColumn = FormatterHelper.getActualStatementIndentation(
node,
fullText
Expand Down Expand Up @@ -71,6 +71,71 @@ export class TempTableFormatter extends AFormatter implements IFormatter {
return resultString;
}

private collectTemptableStructure(
node: SyntaxNode,
fullText: Readonly<FullText>
): void {
node.children.forEach((child) => {
this.getTemptableStructure(child, fullText);
});
}

private getTemptableStructure(node: SyntaxNode, fullText: FullText): void {
switch (node.type) {
case SyntaxNodeType.FieldDefinition:
node.children.forEach((child) => {
this.getFieldStructure(child, fullText);
});
break;
}
}

private getFieldStructure(node: SyntaxNode, fullText: FullText): void {
switch (node.type) {
case SyntaxNodeType.Identifier:
this.alignType = Math.max(
this.alignType,
FormatterHelper.getCurrentText(node, fullText).trim().length
);
break;
}
}

private collectFieldString(
node: SyntaxNode,
fullText: Readonly<FullText>
): string {
let newString = "";
node.children.forEach((child) => {
newString = newString.concat(this.getFieldString(child, fullText));
});
return newString;
}

private getFieldString(
node: SyntaxNode,
fullText: Readonly<FullText>
): string {
let newString = "";
const text = FormatterHelper.getCurrentText(node, fullText).trim();
switch (node.type) {
case SyntaxNodeType.FieldKeyword:
newString = FormatterHelper.getCurrentText(
node,
fullText
).trim();
break;
case SyntaxNodeType.Identifier:
newString =
" " + text + " ".repeat(this.alignType - text.length);
break;
default:
newString = text.length === 0 ? "" : " " + text;
break;
}
return newString;
}

private getTemptableExpressionString(
node: SyntaxNode,
separator: string,
Expand All @@ -83,6 +148,8 @@ export class TempTableFormatter extends AFormatter implements IFormatter {
newString = FormatterHelper.getCurrentText(node, fullText);
break;
case SyntaxNodeType.FieldDefinition:
newString = separator + this.collectFieldString(node, fullText);
break;
case SyntaxNodeType.IndexDefinition:
node.children.forEach((child) => {
newString = newString.concat(
Expand Down

0 comments on commit 533262d

Please sign in to comment.