Skip to content

Commit

Permalink
Solution extended to support more indent and outdent tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
fumer-fubotv committed Apr 3, 2024
1 parent d053541 commit ffdbad7
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/formatters/IndentFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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),

Check failure on line 193 in src/formatters/IndentFormatter.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Argument of type 'Token | undefined' is not assignable to parameter of type 'Token'.

Check failure on line 193 in src/formatters/IndentFormatter.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Argument of type 'Token | undefined' is not assignable to parameter of type 'Token'.
Expand Down

0 comments on commit ffdbad7

Please sign in to comment.