Skip to content

Commit

Permalink
fix(60887): prevent indenting finally blocks as children of try state…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
a-tarasyuk committed Jan 1, 2025
1 parent 56a0825 commit 53a897a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/services/formatting/smartIndenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
SourceFileLike,
SyntaxKind,
TextRange,
TryStatement,
TypeAliasDeclaration,
TypeLiteralNode,
TypeReferenceNode,
Expand Down Expand Up @@ -729,6 +730,12 @@ export namespace SmartIndenter {
return false;
}
break;
case SyntaxKind.TryStatement:
const tryStatement = parent as TryStatement;
if (tryStatement.finallyBlock && tryStatement.finallyBlock === child) {
return false;
}
break;
}
// No explicit rule for given nodes so the result will follow the default value argument
return indentByDefault;
Expand Down
15 changes: 15 additions & 0 deletions tests/cases/fourslash/formatTryFinally.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts"/>

////if (true) try {
//// // ...
////} finally {
//// // ...
////}

format.document();
verify.currentFileContentIs(
`if (true) try {
// ...
} finally {
// ...
}`);

0 comments on commit 53a897a

Please sign in to comment.