From 1105bcd20e11eeddb924525c0f6d27aa97850884 Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Wed, 25 Sep 2024 20:23:51 +0000 Subject: [PATCH] Do not indent rows that start with EOL --- src/prettier_ada-documents-implementation.adb | 7 +- .../alignment}/doc.json | 0 .../alignment}/test.out | 0 .../alignment}/test.yaml | 0 .../must_break_false/doc.json | 0 .../must_break_false/test.out | 0 .../must_break_false/test.yaml | 0 .../must_break_true/doc.json | 0 .../must_break_true/test.out | 0 .../must_break_true/test.yaml | 0 .../row_starts_with_eol/doc.json | 183 ++++++++++++++++++ .../row_starts_with_eol/test.out | 4 + .../row_starts_with_eol/test.yaml | 4 + 13 files changed, 197 insertions(+), 1 deletion(-) rename testsuite/tests/{table_alignment => alignment_table/alignment}/doc.json (100%) rename testsuite/tests/{table_alignment => alignment_table/alignment}/test.out (100%) rename testsuite/tests/{table_alignment => alignment_table/alignment}/test.yaml (100%) rename testsuite/tests/{table_break_propagation => alignment_table/break_propagation}/must_break_false/doc.json (100%) rename testsuite/tests/{table_break_propagation => alignment_table/break_propagation}/must_break_false/test.out (100%) rename testsuite/tests/{table_break_propagation => alignment_table/break_propagation}/must_break_false/test.yaml (100%) rename testsuite/tests/{table_break_propagation => alignment_table/break_propagation}/must_break_true/doc.json (100%) rename testsuite/tests/{table_break_propagation => alignment_table/break_propagation}/must_break_true/test.out (100%) rename testsuite/tests/{table_break_propagation => alignment_table/break_propagation}/must_break_true/test.yaml (100%) create mode 100644 testsuite/tests/alignment_table/row_starts_with_eol/doc.json create mode 100644 testsuite/tests/alignment_table/row_starts_with_eol/test.out create mode 100644 testsuite/tests/alignment_table/row_starts_with_eol/test.yaml diff --git a/src/prettier_ada-documents-implementation.adb b/src/prettier_ada-documents-implementation.adb index 1df51d1..8b3e2f1 100644 --- a/src/prettier_ada-documents-implementation.adb +++ b/src/prettier_ada-documents-implementation.adb @@ -1746,7 +1746,12 @@ package body Prettier_Ada.Documents.Implementation is in Standard."+" (First_Row_Index, 1) .. Last_Row_Index loop Format_State.Result.Text.Append (End_Of_Line.Text); - Format_State.Result.Text.Append (Indentation.Value.Text); + if not States (Row_Index).Result.Text.Starts_With + (End_Of_Line.Text) + then + Format_State.Result.Text.Append + (Indentation.Value.Text); + end if; Format_State.Result.Text.Append (States (Row_Index).Result.Text); end loop; diff --git a/testsuite/tests/table_alignment/doc.json b/testsuite/tests/alignment_table/alignment/doc.json similarity index 100% rename from testsuite/tests/table_alignment/doc.json rename to testsuite/tests/alignment_table/alignment/doc.json diff --git a/testsuite/tests/table_alignment/test.out b/testsuite/tests/alignment_table/alignment/test.out similarity index 100% rename from testsuite/tests/table_alignment/test.out rename to testsuite/tests/alignment_table/alignment/test.out diff --git a/testsuite/tests/table_alignment/test.yaml b/testsuite/tests/alignment_table/alignment/test.yaml similarity index 100% rename from testsuite/tests/table_alignment/test.yaml rename to testsuite/tests/alignment_table/alignment/test.yaml diff --git a/testsuite/tests/table_break_propagation/must_break_false/doc.json b/testsuite/tests/alignment_table/break_propagation/must_break_false/doc.json similarity index 100% rename from testsuite/tests/table_break_propagation/must_break_false/doc.json rename to testsuite/tests/alignment_table/break_propagation/must_break_false/doc.json diff --git a/testsuite/tests/table_break_propagation/must_break_false/test.out b/testsuite/tests/alignment_table/break_propagation/must_break_false/test.out similarity index 100% rename from testsuite/tests/table_break_propagation/must_break_false/test.out rename to testsuite/tests/alignment_table/break_propagation/must_break_false/test.out diff --git a/testsuite/tests/table_break_propagation/must_break_false/test.yaml b/testsuite/tests/alignment_table/break_propagation/must_break_false/test.yaml similarity index 100% rename from testsuite/tests/table_break_propagation/must_break_false/test.yaml rename to testsuite/tests/alignment_table/break_propagation/must_break_false/test.yaml diff --git a/testsuite/tests/table_break_propagation/must_break_true/doc.json b/testsuite/tests/alignment_table/break_propagation/must_break_true/doc.json similarity index 100% rename from testsuite/tests/table_break_propagation/must_break_true/doc.json rename to testsuite/tests/alignment_table/break_propagation/must_break_true/doc.json diff --git a/testsuite/tests/table_break_propagation/must_break_true/test.out b/testsuite/tests/alignment_table/break_propagation/must_break_true/test.out similarity index 100% rename from testsuite/tests/table_break_propagation/must_break_true/test.out rename to testsuite/tests/alignment_table/break_propagation/must_break_true/test.out diff --git a/testsuite/tests/table_break_propagation/must_break_true/test.yaml b/testsuite/tests/alignment_table/break_propagation/must_break_true/test.yaml similarity index 100% rename from testsuite/tests/table_break_propagation/must_break_true/test.yaml rename to testsuite/tests/alignment_table/break_propagation/must_break_true/test.yaml diff --git a/testsuite/tests/alignment_table/row_starts_with_eol/doc.json b/testsuite/tests/alignment_table/row_starts_with_eol/doc.json new file mode 100644 index 0000000..bad1551 --- /dev/null +++ b/testsuite/tests/alignment_table/row_starts_with_eol/doc.json @@ -0,0 +1,183 @@ +{ + "command": { + "break": false, + "command": "group", + "expandedStates": null, + "groupContents": { + "command": { + "command": "indent", + "indentContents": { + "id": 94, + "kind": "list", + "list": [ + { + "id": 70, + "kind": "text", + "text": "Foooooooooooooo" + }, + { + "id": 73, + "kind": "list", + "list": [ + { + "command": { + "command": "line", + "hard": true, + "literal": false, + "soft": false + }, + "id": 71, + "kind": "command" + }, + { + "command": { + "command": "breakParent" + }, + "id": 72, + "kind": "command" + } + ] + }, + { + "command": { + "breakParents": true, + "command": "alignmentTable", + "elements": [ + [ + { + "id": 74, + "kind": "text", + "text": "AAAAA" + }, + { + "command": { + "break": false, + "command": "group", + "expandedStates": null, + "groupContents": { + "id": 80, + "kind": "list", + "list": [ + { + "command": { + "command": "line", + "hard": false, + "literal": false, + "soft": false + }, + "id": 78, + "kind": "command" + }, + { + "id": 79, + "kind": "text", + "text": "BBBBB" + } + ] + }, + "id": 0 + }, + "id": 81, + "kind": "command" + } + ], + [ + { + "id": 92, + "kind": "list", + "list": [ + { + "command": { + "command": "line", + "hard": true, + "literal": false, + "soft": false + }, + "id": 82, + "kind": "command" + }, + { + "command": { + "command": "breakParent" + }, + "id": 83, + "kind": "command" + }, + { + "id": 85, + "kind": "text", + "text": "CCC" + } + ] + }, + { + "command": { + "break": false, + "command": "group", + "expandedStates": null, + "groupContents": { + "id": 90, + "kind": "list", + "list": [ + { + "command": { + "command": "line", + "hard": false, + "literal": false, + "soft": false + }, + "id": 88, + "kind": "command" + }, + { + "id": 89, + "kind": "text", + "text": "DDDD" + } + ] + }, + "id": 0 + }, + "id": 91, + "kind": "command" + } + ] + ], + "mustBreak": true, + "separators": [ + [ + { + "command": { + "command": "alignmentTableSeparator", + "text": "" + }, + "id": 75, + "kind": "command" + } + ], + [ + { + "command": { + "command": "alignmentTableSeparator", + "text": "" + }, + "id": 86, + "kind": "command" + } + ] + ] + }, + "id": 93, + "kind": "command" + } + ] + } + }, + "id": 95, + "kind": "command" + }, + "id": 0 + }, + "id": 96, + "kind": "command" +} diff --git a/testsuite/tests/alignment_table/row_starts_with_eol/test.out b/testsuite/tests/alignment_table/row_starts_with_eol/test.out new file mode 100644 index 0000000..9c989d1 --- /dev/null +++ b/testsuite/tests/alignment_table/row_starts_with_eol/test.out @@ -0,0 +1,4 @@ +Foooooooooooooo + AAAAA BBBBB + + CCC DDDD diff --git a/testsuite/tests/alignment_table/row_starts_with_eol/test.yaml b/testsuite/tests/alignment_table/row_starts_with_eol/test.yaml new file mode 100644 index 0000000..97641d5 --- /dev/null +++ b/testsuite/tests/alignment_table/row_starts_with_eol/test.yaml @@ -0,0 +1,4 @@ +title: Table_Alignment row starts with EOL +driver: document_formatter +description: | + This test confirms that Table_Alignment does not add indentation to a row if it starts with EOL.