Skip to content

Commit

Permalink
Fix auto-indentation for c-syntax, tlaplus#120
Browse files Browse the repository at this point in the history
  • Loading branch information
alygin authored and lemmy committed Apr 5, 2021
1 parent 97ad23a commit cdb42e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/formatters/tla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
26 changes: 26 additions & 0 deletions tests/suite/formatters/tla.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit cdb42e1

Please sign in to comment.