-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from BalticAmadeus/40-find-formatting
40 find formatting
- Loading branch information
Showing
22 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND FIRST Customer WHERE Customer.CustNum = 5 NO-LOCK NO-ERROR. | ||
FIND LAST Customer WHERE Customer.CustNum = 5 NO-LOCK NO-ERROR. | ||
FIND NEXT Customer WHERE Customer.CustNum = 5 NO-LOCK NO-ERROR. | ||
FIND PREV Customer WHERE Customer.CustNum = 5 NO-LOCK NO-ERROR. |
11 changes: 11 additions & 0 deletions
11
resources/functionalTests/find/1firstLastNextPrev/target.p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND FIRST Customer WHERE | ||
Customer.CustNum = 5 NO-LOCK NO-ERROR. | ||
FIND LAST Customer WHERE | ||
Customer.CustNum = 5 NO-LOCK NO-ERROR. | ||
FIND NEXT Customer WHERE | ||
Customer.CustNum = 5 NO-LOCK NO-ERROR. | ||
FIND PREV Customer WHERE | ||
Customer.CustNum = 5 NO-LOCK NO-ERROR. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND Customer WHERE | ||
Customer.CustNum = 5 AND Customer.CustNum = 6 OR Customer.CustNum = 8 no-lock no-error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND Customer WHERE | ||
Customer.CustNum = 5 AND Customer.CustNum = 6 OR Customer.CustNum = 8 no-lock no-error. |
4 changes: 4 additions & 0 deletions
4
resources/functionalTests/find/3multipleConditions-()/input.p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND Customer WHERE (Customer.CustNum > 50 AND Customer.CustNum < 100) OR Customer.CustNum > 200 NO-ERROR. |
5 changes: 5 additions & 0 deletions
5
resources/functionalTests/find/3multipleConditions-()/target.p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND Customer WHERE | ||
(Customer.CustNum > 50 AND Customer.CustNum < 100) OR Customer.CustNum > 200 NO-ERROR. |
4 changes: 4 additions & 0 deletions
4
resources/functionalTests/find/4multipleConditions-()2/input.p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND Order WHERE (Order.OrderStatus = "Shipped" AND (Order.ShipDate > TODAY - 7)) OR (Order.OrderStatus = "Pending" AND (Order.OrderDate = TODAY)) no-lock. |
5 changes: 5 additions & 0 deletions
5
resources/functionalTests/find/4multipleConditions-()2/target.p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND Order WHERE | ||
(Order.OrderStatus = "Shipped" AND (Order.ShipDate > TODAY - 7)) OR (Order.OrderStatus = "Pending" AND (Order.OrderDate = TODAY)) no-lock. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND FIRST Customer WHERE Customer.CustNum = 5 NO-LOCK NO-ERROR. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND FIRST Customer WHERE | ||
Customer.CustNum = 5 NO-LOCK NO-ERROR. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
find Order where Order.OrderStatus = "Shipped" and Order.ShipDate = today use-index OrderNum. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
find Order where | ||
Order.OrderStatus = "Shipped" and Order.ShipDate = today use-index OrderNum. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND Order WHERE Order.CustomerID = Customer.CustomerID NO-WAIT. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND Order WHERE | ||
Order.CustomerID = Customer.CustomerID NO-WAIT. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
find first b_vac | ||
no-lock no-error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
find first b_vac no-lock no-error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND FIRST Order OF Customer WHERE Customer.Country = "USA" AND Customer.Balance > 1000. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* formatterSettingsOverride */ | ||
/* { "AblFormatter.findFormatting": true}*/ | ||
|
||
FIND FIRST Order OF Customer WHERE | ||
Customer.Country = "USA" AND Customer.Balance > 1000. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { SyntaxNode } from "web-tree-sitter"; | ||
import { IFormatter } from "../../formatterFramework/IFormatter"; | ||
import { SyntaxNodeType } from "../../../model/SyntaxNodeType"; | ||
import { CodeEdit } from "../../model/CodeEdit"; | ||
import { FullText } from "../../model/FullText"; | ||
import { FormatterHelper } from "../../formatterFramework/FormatterHelper"; | ||
import { AFormatter } from "../AFormatter"; | ||
import { RegisterFormatter } from "../../formatterFramework/formatterDecorator"; | ||
import { FindSettings } from "./FindSettings"; | ||
import { IConfigurationManager } from "../../../utils/IConfigurationManager"; | ||
|
||
@RegisterFormatter | ||
export class FindFormatter extends AFormatter implements IFormatter { | ||
private startColumn = 0; | ||
private findBodyValue = ""; | ||
|
||
public static readonly formatterLabel = "findFormatting"; | ||
private readonly settings: FindSettings; | ||
|
||
public constructor(configurationManager: IConfigurationManager) { | ||
super(configurationManager); | ||
this.settings = new FindSettings(configurationManager); | ||
} | ||
|
||
match(node: Readonly<SyntaxNode>): boolean { | ||
return node.type === SyntaxNodeType.FindStatement; | ||
} | ||
|
||
parse( | ||
node: Readonly<SyntaxNode>, | ||
fullText: Readonly<FullText> | ||
): CodeEdit | CodeEdit[] | undefined { | ||
this.collectCaseStructure(node, fullText); | ||
return this.getCodeEdit( | ||
node, | ||
FormatterHelper.getCurrentText(node, fullText), | ||
this.findBodyValue, | ||
fullText | ||
); | ||
} | ||
|
||
private collectCaseStructure( | ||
node: SyntaxNode, | ||
fullText: Readonly<FullText> | ||
) { | ||
this.startColumn = node.startPosition.column; | ||
this.findBodyValue = this.getFindStatementBlock(node, fullText); | ||
} | ||
|
||
private getFindStatementBlock( | ||
node: SyntaxNode, | ||
fullText: Readonly<FullText> | ||
): string { | ||
let resultString = ""; | ||
let alignColumn = 0; | ||
|
||
node.children.forEach((child) => { | ||
if (child.type === SyntaxNodeType.Identifier) { | ||
alignColumn = this.startColumn + resultString.length; | ||
} | ||
resultString = resultString.concat( | ||
this.getFindExpressionString(child, fullText, alignColumn) | ||
); | ||
}); | ||
|
||
return resultString + "."; | ||
} | ||
|
||
private getFindExpressionString( | ||
node: SyntaxNode, | ||
fullText: Readonly<FullText>, | ||
alignColumn: number | ||
): string { | ||
let newString = ""; | ||
|
||
switch (node.type) { | ||
case SyntaxNodeType.FindKeyword: | ||
newString = FormatterHelper.getCurrentText( | ||
node, | ||
fullText | ||
).trim(); | ||
break; | ||
case SyntaxNodeType.WhereClause: | ||
newString = this.getWhereClauseBlock( | ||
node, | ||
fullText, | ||
alignColumn | ||
); | ||
break; | ||
case SyntaxNodeType.Error: | ||
newString = FormatterHelper.getCurrentText(node, fullText); | ||
break; | ||
default: | ||
const text = FormatterHelper.getCurrentText( | ||
node, | ||
fullText | ||
).trim(); | ||
newString = text.length === 0 ? "" : " " + text; | ||
break; | ||
} | ||
|
||
return newString; | ||
} | ||
|
||
private getWhereClauseBlock( | ||
node: SyntaxNode, | ||
fullText: Readonly<FullText>, | ||
alignColumn: number | ||
): string { | ||
let resultString = ""; | ||
|
||
node.children.forEach((child) => { | ||
switch (child.type) { | ||
case SyntaxNodeType.WhereKeyword: | ||
resultString = resultString.concat( | ||
" ", | ||
FormatterHelper.getCurrentText(child, fullText).trim(), | ||
fullText.eolDelimiter, | ||
" ".repeat(alignColumn) | ||
); | ||
break; | ||
case SyntaxNodeType.Error: | ||
resultString = resultString.concat( | ||
FormatterHelper.getCurrentText(node, fullText) | ||
); | ||
break; | ||
default: | ||
const text = FormatterHelper.getCurrentText( | ||
child, | ||
fullText | ||
).trim(); | ||
resultString = resultString.concat( | ||
text.length === 0 ? "" : " " + text | ||
); | ||
break; | ||
} | ||
}); | ||
|
||
return resultString; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ASettings } from "../ASettings"; | ||
|
||
export class FindSettings extends ASettings { | ||
// token settings | ||
public findFormatting() { | ||
return this.configurationManager.get("findFormatting") ? true : false; | ||
} | ||
} |