diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 1f84b04e531..f623da53992 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -348,8 +348,8 @@ namespace ts.formatting { anyToken, [isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext, isNotForContext], RuleAction.InsertSpace), - // This low-pri rule takes care of "try {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter. - rule("SpaceAfterTryFinally", [SyntaxKind.TryKeyword, SyntaxKind.FinallyKeyword], SyntaxKind.OpenBraceToken, [isNonJsxSameLineTokenContext], RuleAction.InsertSpace), + // This low-pri rule takes care of "try {", "catch {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter. + rule("SpaceAfterTryCatchFinally", [SyntaxKind.TryKeyword, SyntaxKind.CatchKeyword, SyntaxKind.FinallyKeyword], SyntaxKind.OpenBraceToken, [isNonJsxSameLineTokenContext], RuleAction.InsertSpace), ]; return [ diff --git a/tests/cases/fourslash/formatCatch.ts b/tests/cases/fourslash/formatCatch.ts new file mode 100644 index 00000000000..fce6cf75df5 --- /dev/null +++ b/tests/cases/fourslash/formatCatch.ts @@ -0,0 +1,16 @@ +/// + +////try { +////} /*0*/catch { +////} +//// +////try { +////} /*1*/catch{ +////} + +format.document(); + +for (const marker of test.markers()) { + goTo.marker(marker); + verify.currentLineContentIs("} catch {"); +}