diff --git a/src/formatters/tla.ts b/src/formatters/tla.ts index 966826b..96ad345 100644 --- a/src/formatters/tla.ts +++ b/src/formatters/tla.ts @@ -118,11 +118,11 @@ function testStateDefBlockStart(line: vscode.TextLine, options: vscode.Formattin } function testBlockStart(line: vscode.TextLine): LineInfo | undefined { - const matches = /^(\s*)(?:\w+\:)?\s*(?:begin|if|else|elsif|while|either|or|with|define|macro|procedure)\b.*/g.exec(line.text); + const matches = /^(\s*)(?:\w+\:)?\s*(?:begin\b|if\b|else\b|elsif\b|while\b|either\b|or\b|with\b|define\b|macro\b|procedure\b|\{).*/g.exec(line.text); return matches ? new LineInfo(line, matches[1], IndentationType.Right) : undefined; } function testBlockEnd(line: vscode.TextLine): LineInfo | undefined { - const matches = /^(\s*)(?:end|else|elsif|or)\b.*/g.exec(line.text); + const matches = /^(\s*)(?:end\b|else\b|elsif\b|or\b|\}).*/g.exec(line.text); return matches ? new LineInfo(line, matches[1], IndentationType.Left) : undefined; } diff --git a/tests/suite/formatters/tla.test.ts b/tests/suite/formatters/tla.test.ts index 803253f..87616fc 100644 --- a/tests/suite/formatters/tla.test.ts +++ b/tests/suite/formatters/tla.test.ts @@ -587,6 +587,32 @@ suite('TLA On Type Formatting Test Suite', () => { ]); }); + test('Indents block contents, c-syntax', () => { + return assertTlaOnTypeFormatting(doc, [ + ' procedure Foo() {', + ' ${enter}', + ' }' + ], [ + ' procedure Foo() {', + ' ', + ' }' + ]); + }); + + test('Keeps correct indentation after closed block, c-syntax', () => { + return assertTlaOnTypeFormatting(doc, [ + ' procedure Foo() {', + ' skip;', + ' }', + ' ${enter}' + ], [ + ' procedure Foo() {', + ' skip;', + ' }', + ' ' + ]); + }); + test('CAN IMPROVE: Indents to the body of enclosing block', () => { return assertTlaOnTypeFormatting(doc, [ ' begin',