Skip to content

Commit

Permalink
Merge branch 'gnatformat-issue_50' into 'master'
Browse files Browse the repository at this point in the history
Unparsing: Try to fit f_subp_spec, f_aspects and is on the same line

Closes eng/ide/gnatformat#50

See merge request eng/libadalang/libadalang!1714
  • Loading branch information
joaopsazevedo committed Jul 30, 2024
2 parents 7f04367 + 92ac5a8 commit 19e5256
Show file tree
Hide file tree
Showing 22 changed files with 95 additions and 33 deletions.
31 changes: 18 additions & 13 deletions extensions/default_unparsing_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5077,17 +5077,22 @@
"field": "f_overriding"
},
{
"kind": "recurse_field",
"field": "f_subp_spec"
},
{
"kind": "recurse_field",
"field": "f_aspects"
},
"hardlineWithoutBreakParent",
{
"kind": "text",
"text": "is"
"kind": "group",
"document": [
{
"kind": "recurse_field",
"field": "f_subp_spec"
},
{
"kind": "recurse_field",
"field": "f_aspects"
},
"line",
{
"kind": "text",
"text": "is"
}
]
},
{
"kind": "recurse_field",
Expand All @@ -5101,7 +5106,7 @@
"kind": "recurse_field",
"field": "f_stmts"
},
"hardlineWithoutBreakParent",
"hardline",
{
"kind": "text",
"text": "end"
Expand All @@ -5118,7 +5123,7 @@
},
"fields": {
"f_aspects": [
"hardline",
"line",
"recurse"
],
"f_decls": [
Expand Down
3 changes: 1 addition & 2 deletions testsuite/tests/unparsing/decl_block/test.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
procedure Foo
is
procedure Foo is
begin
declare
Bar : Baz;
Expand Down
3 changes: 1 addition & 2 deletions testsuite/tests/unparsing/exception_handler/test.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
procedure Foo
is
procedure Foo is
begin
declare
Bar : Baz;
Expand Down
3 changes: 1 addition & 2 deletions testsuite/tests/unparsing/object_decl/table/test.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
procedure Main
is
procedure Main is
AAAAAAAAAAAAAAAA : Baaaaaar := Bar;
BBBBBBBBBBBBBBBBBBBB :
Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz :=
Expand Down
6 changes: 2 additions & 4 deletions testsuite/tests/unparsing/protected_body/simple_body/test.out
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
protected body Shared_Array is
function Component (N : in Index) return Item
is
function Component (N : in Index) return Item is
begin
return Table (N);
end Component;

procedure Set_Component (N : in Index; E : in Item)
is
procedure Set_Component (N : in Index; E : in Item) is
begin
Table (N) := E;
end Set_Component;
Expand Down
3 changes: 1 addition & 2 deletions testsuite/tests/unparsing/protected_body/with_entry/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ protected body Resource is
Busy := True;
end Seize;

procedure Release
is
procedure Release is
begin
Busy := False;
end Release;
Expand Down
3 changes: 3 additions & 0 deletions testsuite/tests/unparsing/subp_body/long_subp_spec/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Freeeeeeeeeeeeeeed is begin
null;
end;
5 changes: 5 additions & 0 deletions testsuite/tests/unparsing/subp_body/long_subp_spec/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Freeeeeeeeeeeeeeed
is
begin
null;
end;
5 changes: 5 additions & 0 deletions testsuite/tests/unparsing/subp_body/long_subp_spec/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: subp_body
description: |
Test a `SubpBody` whose `f_subp_spec` and `is` token do not fit on one
line.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Fooooooooooooo
(A : Bar; B : Baz; C : Qux) return Freeeeeeeeeeeeeeeeeed with Precondition is
begin
null;
end;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function Fooooooooooooo
(A : Bar; B : Baz; C : Qux) return Freeeeeeeeeeeeeeeeeed
with Precondition
is
begin
null;
end;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: subp_body
description: |
Test that, if the `f_subp_spec` of a `SubpBody` breaks, then a line break is
added before `f_aspects` and the `is` token.
3 changes: 1 addition & 2 deletions testsuite/tests/unparsing/subp_body/no_end_name/test.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred
is
function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred is
type Garply;
begin
null;
Expand Down
3 changes: 1 addition & 2 deletions testsuite/tests/unparsing/subp_body/with_decls/test.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred
is
function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred is
type Garply;
begin
null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred
with Pre => Some_Long_Precondition (With_An_Aggregate => And_Looooooooooooong_R_Expr)
is
type My_Type;
begin
null;
end;

9 changes: 9 additions & 0 deletions testsuite/tests/unparsing/subp_body/with_long_aspect/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred
with
Pre =>
Some_Long_Precondition (With_An_Aggregate => And_Looooooooooooong_R_Expr)
is
type My_Type;
begin
null;
end;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: subp_body
description: |
Test that when a `SubpBody` has an non null `f_aspects`, a line break is
added before the `is` token.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Foo (A : Bar) return Fred with Pre => Precondition is
type My_Type;
begin
null;
end;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Foo (A : Bar) return Fred with Pre => Precondition is
type My_Type;
begin
null;
end;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: subp_body
description: |
Test a `SubpBody` whose `f_subp_spec` and `is` token do not fine on one
line.
3 changes: 1 addition & 2 deletions testsuite/tests/unparsing/subp_body/without_decls/test.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred
is
function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred is
begin
null;
end Foo;
3 changes: 1 addition & 2 deletions testsuite/tests/unparsing/subunit/test.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
separate(Parent)
procedure Inner
is
procedure Inner is
begin
Foo;
end Inner;

0 comments on commit 19e5256

Please sign in to comment.