From 34336753f72b4c0b0a201894f8c3dbc537ac2649 Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Wed, 31 Jul 2024 15:58:20 +0000 Subject: [PATCH] Avoid certain cases where 'is' is in its own line --- extensions/default_unparsing_config.json | 87 +++++++++++++++++-- .../long_subp_spec_no_decls/input.ada | 10 +++ .../long_subp_spec_no_decls/test.out | 9 ++ .../long_subp_spec_no_decls/test.yaml | 6 ++ .../long_subp_spec_with_decls/input.ada | 10 +++ .../long_subp_spec_with_decls/test.out | 11 +++ .../long_subp_spec_with_decls/test.yaml | 5 ++ 7 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/input.ada create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/test.out create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/test.yaml create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/input.ada create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/test.out create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/test.yaml diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index 1b6a37506..73a5bc690 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -5309,17 +5309,88 @@ { "kind": "recurse_field", "field": "f_aspects" - }, - "line", - { - "kind": "text", - "text": "is" } - ] + ], + "id": "subp_spec" }, { - "kind": "recurse_field", - "field": "f_decls" + "kind": "ifKind", + "field": "f_aspects", + "default": { + "kind": "ifBreak", + "groupId": "subp_spec", + "flatContents": { + "kind": "group", + "document": [ + { + "kind": "group", + "document": [ + "line", + { + "kind": "text", + "text": "is" + } + ] + }, + { + "kind": "recurse_field", + "field": "f_decls" + } + ] + }, + "breakContents": { + "kind": "group", + "document": [ + "hardline", + { + "kind": "text", + "text": "is" + }, + { + "kind": "recurse_field", + "field": "f_decls" + } + ] + } + }, + "null": { + "kind": "ifBreak", + "groupId": "subp_spec", + "flatContents": { + "kind": "group", + "document": [ + { + "kind": "group", + "document": [ + "line", + { + "kind": "text", + "text": "is" + } + ] + }, + { + "kind": "recurse_field", + "field": "f_decls" + } + ] + }, + "breakContents": { + "kind": "group", + "document": [ + "line", + { + "kind": "text", + "text": "is" + }, + { + "kind": "recurse_field", + "field": "f_decls" + } + ] + } + }, + "matchers": [] }, { "kind": "text", diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/input.ada b/testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/input.ada new file mode 100644 index 000000000..b36d4cee6 --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/input.ada @@ -0,0 +1,10 @@ +function To_Source_Location_Range + (Self : Langkit_Text_Document'Class; A_Range : LSP.Structures.A_Range) + return Langkit_Support.Slocs.Source_Location_Range +is +begin + return + Langkit_Support.Slocs.Make_Range + (Self.To_Source_Location (A_Range.start), + Self.To_Source_Location (A_Range.an_end)); +end To_Source_Location_Range; diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/test.out b/testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/test.out new file mode 100644 index 000000000..685430f48 --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/test.out @@ -0,0 +1,9 @@ +function To_Source_Location_Range + (Self : Langkit_Text_Document'Class; A_Range : LSP.Structures.A_Range) + return Langkit_Support.Slocs.Source_Location_Range is +begin + return + Langkit_Support.Slocs.Make_Range + (Self.To_Source_Location (A_Range.start), + Self.To_Source_Location (A_Range.an_end)); +end To_Source_Location_Range; diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/test.yaml b/testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/test.yaml new file mode 100644 index 000000000..9616107b9 --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec_no_decls/test.yaml @@ -0,0 +1,6 @@ +driver: unparser +rule: subp_body +description: | + For a `SubpBody` node whose `f_decls` is empty, null `f_aspects` and + `f_subp_spec` breaks, test that the `is` is added to the end of + `f_subp_spec` if it fits. diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/input.ada b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/input.ada new file mode 100644 index 000000000..5cc6f1335 --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/input.ada @@ -0,0 +1,10 @@ +function To_Source_Location_Range + (Self : Langkit_Text_Document'Class; A_Range : LSP.Structures.A_Range) + return Langkit_Support.Slocs.Source_Location_Range is + I : Integer; +begin + return + Langkit_Support.Slocs.Make_Range + (Self.To_Source_Location (A_Range.start), + Self.To_Source_Location (A_Range.an_end)); +end To_Source_Location_Range; diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/test.out b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/test.out new file mode 100644 index 000000000..90d9de264 --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/test.out @@ -0,0 +1,11 @@ +function To_Source_Location_Range + (Self : Langkit_Text_Document'Class; A_Range : LSP.Structures.A_Range) + return Langkit_Support.Slocs.Source_Location_Range +is + I : Integer; +begin + return + Langkit_Support.Slocs.Make_Range + (Self.To_Source_Location (A_Range.start), + Self.To_Source_Location (A_Range.an_end)); +end To_Source_Location_Range; diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/test.yaml b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/test.yaml new file mode 100644 index 000000000..02140cd0d --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_decls/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: subp_body +description: | + For a `SubpBody` node whose `f_decls` is not empty, null `f_aspects` and + `f_subp_spec` breaks, test that a line break is added before the `is`.