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

276 change sorting of using statements #278

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion resources/functionalTests/using/3lowercase/input.p
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion resources/functionalTests/using/3lowercase/target.p
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions resources/functionalTests/using/4optional-statements/input.p
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions resources/functionalTests/using/4optional-statements/target.p
Original file line number Diff line number Diff line change
Expand Up @@ -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.
22 changes: 17 additions & 5 deletions src/v2/formatters/using/UsingFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SyntaxNode>): boolean {
if (node.type === SyntaxNodeType.UsingStatement) {
return true;
Expand All @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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 = {
Expand Down
Loading