From 492309f019076feaa99ff6e4f58a94b721a05b33 Mon Sep 17 00:00:00 2001 From: gmickus Date: Mon, 9 Dec 2024 09:27:37 +0200 Subject: [PATCH] Update UsingFormatter --- .../functionalTests/using/3lowercase/input.p | 2 +- .../functionalTests/using/3lowercase/target.p | 2 +- .../using/4optional-statements/input.p | 4 ++-- .../using/4optional-statements/target.p | 4 ++-- src/v2/formatters/using/UsingFormatter.ts | 22 ++++++++++++++----- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/resources/functionalTests/using/3lowercase/input.p b/resources/functionalTests/using/3lowercase/input.p index 88e95af..902ecee 100644 --- a/resources/functionalTests/using/3lowercase/input.p +++ b/resources/functionalTests/using/3lowercase/input.p @@ -3,7 +3,7 @@ "abl.completion.upperCase": false}*/ using as. -define variable a as integer no-undo. +//define variable a as integer no-undo. USING b. using c. USING a. \ No newline at end of file diff --git a/resources/functionalTests/using/3lowercase/target.p b/resources/functionalTests/using/3lowercase/target.p index 6a2f2f7..81915e1 100644 --- a/resources/functionalTests/using/3lowercase/target.p +++ b/resources/functionalTests/using/3lowercase/target.p @@ -3,7 +3,7 @@ "abl.completion.upperCase": false}*/ using a. -define variable a as integer no-undo. +//define variable a as integer no-undo. using as. using b. using c. \ No newline at end of file diff --git a/resources/functionalTests/using/4optional-statements/input.p b/resources/functionalTests/using/4optional-statements/input.p index 1761837..3052fd1 100644 --- a/resources/functionalTests/using/4optional-statements/input.p +++ b/resources/functionalTests/using/4optional-statements/input.p @@ -3,8 +3,8 @@ "abl.completion.upperCase": false}*/ using A from propath. -define variable c as integer no-undo. +//define variable c as integer no-undo. USING b. using c FROM aSsemblY. -message ".". +//message ".". USING a. \ No newline at end of file diff --git a/resources/functionalTests/using/4optional-statements/target.p b/resources/functionalTests/using/4optional-statements/target.p index d4bda55..ae55ae2 100644 --- a/resources/functionalTests/using/4optional-statements/target.p +++ b/resources/functionalTests/using/4optional-statements/target.p @@ -3,8 +3,8 @@ "abl.completion.upperCase": false}*/ using A from propath. -define variable c as integer no-undo. +//define variable c as integer no-undo. using a. using b. -message ".". +//message ".". using c from assembly. \ No newline at end of file diff --git a/src/v2/formatters/using/UsingFormatter.ts b/src/v2/formatters/using/UsingFormatter.ts index 095ddc2..88d6971 100644 --- a/src/v2/formatters/using/UsingFormatter.ts +++ b/src/v2/formatters/using/UsingFormatter.ts @@ -16,15 +16,14 @@ export class UsingFormatter extends AFormatter implements IFormatter { private usingStatementsFound: number = 0; private alignOptionalStatements: number = 0; + private usingStatements: UsingStatement[] = []; + private textUsingStatements: string[] = []; public constructor(configurationManager: IConfigurationManager) { super(configurationManager); this.settings = new UsingSettings(configurationManager); } - private usingStatements: UsingStatement[] = []; - private textUsingStatements: string[] = []; - match(node: Readonly): boolean { if (node.type === SyntaxNodeType.UsingStatement) { return true; @@ -44,10 +43,13 @@ export class UsingFormatter extends AFormatter implements IFormatter { this.textUsingStatements.sort(); } const text = FormatterHelper.getCurrentText(node, fullText); - if (this.usingStatementsFound > this.usingStatements.length) { + if (this.usingStatementsFound > this.textUsingStatements.length) { return undefined; } const newText = this.textUsingStatements[this.usingStatementsFound - 1]; + if (this.usingStatementsFound === this.textUsingStatements.length) { + this.reset(); + } return this.getCodeEdit(node, text, newText, fullText); } @@ -56,9 +58,12 @@ export class UsingFormatter extends AFormatter implements IFormatter { fullText: FullText ): void { for (node; node !== null; node = node.nextSibling) { - if (!this.match(node)) { + if (node.type === SyntaxNodeType.Comment) { continue; } + if (!this.match(node)) { + break; + } const keywordChild = node.child(0); const identifierChild = node.child(1); @@ -126,6 +131,13 @@ export class UsingFormatter extends AFormatter implements IFormatter { ); } } + + private reset(): void { + this.usingStatementsFound = 0; + this.alignOptionalStatements = 0; + this.usingStatements = []; + this.textUsingStatements = []; + } } type UsingStatement = {