From ffdbad7dd75f6ca52cb91a361945ca4ee7f19a63 Mon Sep 17 00:00:00 2001 From: fumer-fubotv <89787347+fumer-fubotv@users.noreply.github.com> Date: Wed, 3 Apr 2024 07:54:20 -0700 Subject: [PATCH] Solution extended to support more indent and outdent tokens --- src/formatters/IndentFormatter.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/formatters/IndentFormatter.ts b/src/formatters/IndentFormatter.ts index 8346e6d..ca6f852 100644 --- a/src/formatters/IndentFormatter.ts +++ b/src/formatters/IndentFormatter.ts @@ -93,7 +93,7 @@ export class IndentFormatter { //skip indent for 'function'|'sub' used as type if another indent already exist in this line if ( - CallableKeywordTokenKinds.includes(token.kind) && + IndentSpacerTokenKinds.includes(token.kind) && //validate if its a function/sub call nextNonWhitespaceToken.kind === TokenKind.LeftParen && foundIndentorThisLine @@ -164,10 +164,17 @@ export class IndentFormatter { nextLineOffset--; + let doubleIndentSkip = (token.kind === TokenKind.RightCurlyBrace || token.kind === TokenKind.RightSquareBracket) && + //next is closing square + nextNonWhitespaceToken && nextNonWhitespaceToken.kind === TokenKind.RightSquareBracket && + //both tokens are on the same line + token.range.start.line === nextNonWhitespaceToken.range.start.line; + if ( - [TokenKind.RightCurlyBrace].includes(token.kind) && - //if the line has already been unindented - (foundUnIndentOnThisLine) + OutdentSpacerTokenKinds.includes(token.kind) && + //if the line has already been outdented + (foundUnIndentOnThisLine) && + !doubleIndentSkip ) { continue; } @@ -180,14 +187,7 @@ export class IndentFormatter { parentIndentTokenKinds.pop(); //don't double un-indent if this is `[[...\n...]]` or `[{...\n...}]` - if ( - //is closing curly or square - (token.kind === TokenKind.RightCurlyBrace || token.kind === TokenKind.RightSquareBracket) && - //next is closing square - nextNonWhitespaceToken && nextNonWhitespaceToken.kind === TokenKind.RightSquareBracket && - //both tokens are on the same line - token.range.start.line === nextNonWhitespaceToken.range.start.line - ) { + if (doubleIndentSkip) { let opener = this.getOpeningToken( tokens, tokens.indexOf(nextNonWhitespaceToken),