Skip to content

Commit

Permalink
Merge pull request #274 from BalticAmadeus/261-format-functionmethod-…
Browse files Browse the repository at this point in the history
…arguments-over-multiple-lines

261 format function method arguments over multiple lines
  • Loading branch information
PauliusKu authored Dec 4, 2024
2 parents ed703cf + 77786f4 commit 9a5b4a6
Show file tree
Hide file tree
Showing 29 changed files with 499 additions and 14 deletions.
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,22 @@
"default": "true",
"description": "Enable PROCEDURE PARAMETER formatting"
},
"AblFormatter.functionParameterFormatting": {
"order": 1600,
"type": "boolean",
"default": "true",
"description": "Enable FUNCTION PARAMETER formatting"
},
"AblFormatter.functionParameterFormattingAlignParameterTypes": {
"order": 1601,
"type": "string",
"default": "Yes",
"enum": [
"Yes",
"No"
],
"description": "Align parameter types?"
},
"AblFormatter.showTreeInfoOnHover": {
"order": 10100,
"type": "boolean",
Expand Down
1 change: 1 addition & 0 deletions resources/functionalTests/assign/2inFunction/input.p
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* formatterSettingsOverride */
/* { "AblFormatter.assignFormatting": true,
"abl.completion.upperCase": true,
"AblFormatter.functionParameterFormatting": false,
"AblFormatter.assignFormattingAssignLocation": "New",
"AblFormatter.assignFormattingAlignRightExpression": "Yes",
"AblFormatter.assignFormattingEndDotLocation": "New aligned"}*/
Expand Down
1 change: 1 addition & 0 deletions resources/functionalTests/assign/2inFunction/target.p
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* formatterSettingsOverride */
/* { "AblFormatter.assignFormatting": true,
"abl.completion.upperCase": true,
"AblFormatter.functionParameterFormatting": false,
"AblFormatter.assignFormattingAssignLocation": "New",
"AblFormatter.assignFormattingAlignRightExpression": "Yes",
"AblFormatter.assignFormattingEndDotLocation": "New aligned"}*/
Expand Down
9 changes: 4 additions & 5 deletions resources/functionalTests/block/20function-block-end3/input.p
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

function fun returns integer (input p1 as integer,
input-output p2 as logical,
output p3 as character):
return p1.
end function.
function GetDLC returns character
():
define variable cValue as character no-undo.
end function.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

function fun returns integer (input p1 as integer,
input-output p2 as logical,
output p3 as character):
return p1.
function GetDLC returns character
():
define variable cValue as character no-undo.
end function.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

function fun returns integer (input p1 as integer,
function fun returns integer (input p1 as integer,
input-output p2 as logical,
output p3 as character):
output p3 as character):
return p1.
end function.
7 changes: 4 additions & 3 deletions resources/functionalTests/block/6do-end2/input.p
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* { "AblFormatter.blockFormatting": true}*/

do transaction:
do while true:
a = 3. end.
end.
do while true:
a = 3.
end.
end.
8 changes: 8 additions & 0 deletions resources/functionalTests/functionParameter/1method/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "No"}*/

class FunClass:
method public Table fill(poQuery as Query, poOnNotAvailable as QueryNotAvailable):
end end method.
end class.
9 changes: 9 additions & 0 deletions resources/functionalTests/functionParameter/1method/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "No"}*/

class FunClass:
method public Table fill(poQuery as Query,
poOnNotAvailable as QueryNotAvailable):
end end method.
end class.
7 changes: 7 additions & 0 deletions resources/functionalTests/functionParameter/2function/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "Yes"}*/

FUNCTION doubler RETURNS INTEGER(INPUT parm1 AS INTEGER):
RETURN (2 * parm1).
END FUNCTION.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "Yes"}*/

FUNCTION doubler RETURNS INTEGER(INPUT parm1 AS INTEGER):
RETURN (2 * parm1).
END FUNCTION.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "Yes"}*/

class MyEntityClass:
method public void Fetch( input-output dataset dsMyDataset,poParameter2 as integer,
piParameterInteger as myParameter):

end method.
end class.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "Yes"}*/

class MyEntityClass:
method public void Fetch(input-output dataset dsMyDataset,
poParameter2 as integer,
piParameterInteger as myParameter):

end method.
end class.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "Yes"}*/

class FunkyWorld.Util.KittyLogHelper:
method private void SnuggleDataset(dataset-handle dsCuddlePuddle bind):
/* PURR */
end method.
end class.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "Yes"}*/

class FunkyWorld.Util.KittyLogHelper:
method private void SnuggleDataset(dataset-handle dsCuddlePuddle bind):
/* PURR */
end method.
end class.
16 changes: 16 additions & 0 deletions resources/functionalTests/functionParameter/3table-handle/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "Yes"}*/

class Olympus.Util.HermesHelper:
method public static void ExecuteOracleQuery(pcOracleString as character,
pcOlympianFields as character,
piNumProphecies as integer,
output table-handle phOracleTable):

ZeusCollectorHelper:SmiteObject(hHermesQuery).
ZeusCollectorHelper:SmiteObject(hDionysusBuffer).

end method.

end class.
16 changes: 16 additions & 0 deletions resources/functionalTests/functionParameter/3table-handle/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "Yes"}*/

class Olympus.Util.HermesHelper:
method public static void ExecuteOracleQuery(pcOracleString as character,
pcOlympianFields as character,
piNumProphecies as integer,
output table-handle phOracleTable):

ZeusCollectorHelper:SmiteObject(hHermesQuery).
ZeusCollectorHelper:SmiteObject(hDionysusBuffer).

end method.

end class.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "Yes"}*/

function finalShot returns character (input myDribbleShot as character, output tipOffAll as TipOff):

end function.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "Yes"}*/

function finalShot returns character (input myDribbleShot as character,
output tipOffAll as TipOff):

end function.
8 changes: 8 additions & 0 deletions resources/functionalTests/functionParameter/4function/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "No"}*/

function finalShot returns character (input myDribble as character, output tipOff as character):

end function.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* formatterSettingsOverride */
/* { "AblFormatter.functionParameterFormatting": true,
"AblFormatter.functionParameterFormattingAlignParameterTypes": "No"}*/

function finalShot returns character (input myDribble as character,
output tipOff as character):

end function.

19 changes: 19 additions & 0 deletions src/model/SyntaxNodeType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export enum SyntaxNodeType {
LeftParenthesis = "(",
RightParenthesis = ")",
Label = "label",
Parameters = "parameters",
FunctionParameter = "function_parameter",
FunctionParameterMode = "function_parameter_mode",

// keywords
WhenKeyword = "WHEN",
Expand Down Expand Up @@ -107,6 +110,10 @@ export enum SyntaxNodeType {
ReturnKeyword = "RETURN",
ParameterKeyword = "PARAMETER",
VariableKeyword = "VARIABLE",
TableKeyword = "TABLE",
TableHandleKeyword = "TABLE-HANDLE",
DatasetKeyword = "DATASET",
DatasetHandleKeyword = "DATASET-HANDLE",
}

export const afterThenStatements = new MyFancySet<string>([
Expand All @@ -124,6 +131,13 @@ export const definitionKeywords = new MyFancySet<string>([
SyntaxNodeType.DefKeyword,
]);

export const dataStructureKeywords = new MyFancySet<string>([
SyntaxNodeType.TableKeyword,
SyntaxNodeType.TableHandleKeyword,
SyntaxNodeType.DatasetKeyword,
SyntaxNodeType.DatasetHandleKeyword,
]);

export const bodyBlockKeywords = new MyFancySet<string>([
SyntaxNodeType.Body,
SyntaxNodeType.CaseBody,
Expand All @@ -137,3 +151,8 @@ export const parameterTypes = new MyFancySet<string>([
SyntaxNodeType.InputOutputKeyword,
SyntaxNodeType.ReturnKeyword,
]);

export const parentheses = new MyFancySet<string>([
SyntaxNodeType.LeftParenthesis,
SyntaxNodeType.RightParenthesis,
]);
2 changes: 2 additions & 0 deletions src/v2/formatterFramework/enableFormatterDecorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { BodyFormatter } from "../formatters/body/BodyFormatter";
import { EnumFormatter } from "../formatters/enum/EnumFormatter";
import { VariableDefinitionFormatter } from "../formatters/variableDefinition/VariableDefinitionFormatter";
import { ProcedureParameterFormatter } from "../formatters/procedureParameter/ProcedureParameterFormatter";
import { FunctionParameterFormatter } from "../formatters/functionParameter/FunctionParameterFormatter";

// 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 {
Expand All @@ -31,4 +32,5 @@ export function enableFormatterDecorators(): void {
VariableDefinitionFormatter;
EnumFormatter;
ProcedureParameterFormatter;
FunctionParameterFormatter;
}
Loading

0 comments on commit 9a5b4a6

Please sign in to comment.