Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added scope_tuning formatting #352

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions resources/functionalTests/defineVariable/10-static2/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
define private static var partId as char no-undo.
define public static var intStartRowid as int64 no-undo.
define static var currRowid as char no-undo
define private static var partId2 as char no-undo.
define protected static var intStartRowid2 as int64 no-undo.
define static var currRowid2 as char no-undo.
6 changes: 6 additions & 0 deletions resources/functionalTests/defineVariable/10-static2/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
define private static var partId as char no-undo.
define public static var intStartRowid as int64 no-undo.
define static var currRowid as char no-undo.
define private static var partId2 as char no-undo.
define protected static var intStartRowid2 as int64 no-undo.
define static var currRowid2 as char no-undo.
21 changes: 21 additions & 0 deletions src/formatters/variableDefinition/VariableDefinitionFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class VariableDefinitionFormatter
private alignVariableTuning: number = 0;
private alignExtent: number = 0;
private alignVariableKeyword: number = 0;
private countAccessTuning: number = 0;
private hasAccessTuning = false;

public constructor(configurationManager: IConfigurationManager) {
Expand Down Expand Up @@ -107,6 +108,7 @@ export class VariableDefinitionFormatter
);
break;
case SyntaxNodeType.AccessTuning:
this.countAccessTuning++;
this.alignVariableKeyword = Math.max(
this.alignVariableKeyword,
FormatterHelper.getCurrentText(node, fullText).trim().length
Expand Down Expand Up @@ -191,6 +193,25 @@ export class VariableDefinitionFormatter
case SyntaxNodeType.Error:
newString = FormatterHelper.getCurrentText(node, fullText);
break;
case SyntaxNodeType.ScopeTuning: {
const text = FormatterHelper.getCurrentText(
node,
fullText
).trim();
let spaces: string;
const hasAccessTuning =
node.previousSibling?.type === SyntaxNodeType.AccessTuning;

if (hasAccessTuning) {
spaces = " ";
} else if (this.countAccessTuning === 0 && !hasAccessTuning) {
spaces = " ";
} else {
spaces = " ".repeat(this.alignVariableKeyword + 2);
}
newString = spaces + text;
break;
}
case SyntaxNodeType.VariableTuning:
let variableTuningText = "";
let spacesCount = 0;
Expand Down
1 change: 1 addition & 0 deletions src/model/SyntaxNodeType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export enum SyntaxNodeType {
Parameters = "parameters",
FunctionParameter = "function_parameter",
FunctionParameterMode = "function_parameter_mode",
ScopeTuning = "scope_tuning",
// arithmetic operators
Add = "+",
Subtract = "-",
Expand Down
Loading