Skip to content
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
20 changes: 20 additions & 0 deletions src/Formatter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2409,6 +2409,26 @@ end function`;
`);
});

it('indents a continuation line ending with the closing paren', () => {
formatEqualTrim(`
sub test()
m.assertEqual(result, expected,
"message text")
end sub
`);
});

it('indents consecutive multi-line calls whose continuations end with a template literal closing paren', () => {
formatEqualTrim(`
sub test(input, expected)
m.assertTrue(Type(result) = "roBoolean" or Type(result) = "Boolean",
\`toBoolean('\${input}') should return boolean type but got \${Type(result)}\`)
m.assertEqual(result, expected,
\`toBoolean('\${input}') should return \${expected} but got \${result}\`)
end sub
`);
});

it('does not double indent a multi-line array of arrays opened on one line', () => {
formatEqualTrim(`
sub test()
Expand Down
11 changes: 4 additions & 7 deletions src/formatters/IndentFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ export class IndentFormatter {

let currentLineOffset = 0;
let nextLineOffset = 0;
let foundIndentorThisLine = false;
let outdentedThisLine = false;
let firstNonWhitespaceToken: Token | null = null;

for (let i = 0; i < lineTokens.length; i++) {
Expand Down Expand Up @@ -181,7 +179,6 @@ export class IndentFormatter {
this.multiLineFuncDeclarationOpeners.push(token);
} else {
nextLineOffset++;
foundIndentorThisLine = true;
}
parentIndentTokenKinds.push(token.kind);

Expand Down Expand Up @@ -211,11 +208,11 @@ export class IndentFormatter {
}

nextLineOffset--;
//only the first leading closer dedents the current line, aligning it with that closer's opener (e.g.
//the `}` in `})` aligns the line with its `{`); later closers on the line only affect the next line
if (foundIndentorThisLine === false && !outdentedThisLine) {
//only dedent the current line when it *starts* with a closer, aligning the line with that closer's
//opener (e.g. the `}` in a leading `})`). A closer at the end of a content/continuation line must not
//pull the line back - e.g. the trailing `)` in `m.assertEqual(a,` ⏎ `` `msg`) `` keeps the +1 indent.
if (token === firstNonWhitespaceToken) {
currentLineOffset--;
outdentedThisLine = true;
}
parentIndentTokenKinds.pop();

Expand Down
Loading