Skip to content

Commit f8c306e

Browse files
committed
Replace ALS.GNATFORMAT trace by a setting
1 parent a259ba1 commit f8c306e

File tree

17 files changed

+101
-71
lines changed

17 files changed

+101
-71
lines changed

doc/settings.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ prefixing each setting name with `ada.`, e.g.
1616
"ada.scenarioVariables": {
1717
"LIBRARY_TYPE": "static"
1818
},
19-
"ada.onTypeFormatting.indentOnly": true
19+
"ada.onTypeFormatting.indentOnly": true,
20+
"useGnatformat": true
2021
}
2122
```
2223

@@ -67,6 +68,7 @@ Ada Language Server understands these settings:
6768
* [followSymlinks](#followsymlinks)
6869
* [documentationStyle](#documentationstyle)
6970
* [onTypeFormatting.indentOnly](#ontypeformattingindentonly)
71+
* [useGnatformat](#usegnatformat)
7072

7173
----
7274

@@ -275,3 +277,9 @@ An equivalent setting `gpr.trace.server` exists for tracing the communcation bet
275277
This option controls if the `textDocument/onTypeFormatting` request only indents a new line, or if
276278
it additionally tries to format the previous node. By default, this option is enabled, that is,
277279
`textDocument/onTypeFormatting` only indents new lines.
280+
281+
## useGnatformat
282+
283+
This option controls the formatting provider for the `textDocument/formatting`,
284+
`textDocument/rangeFormatting` and `textDocument/onTypeFormatting` request. By default, this option
285+
is enabled and ALS uses GNATformat as its formatting provider. If disabled, GNATpp is used instead.

integration/vscode/ada/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@
323323
"title": "Formatting",
324324
"order": 1,
325325
"properties": {
326+
"ada.useGnatformat": {
327+
"scope": "window",
328+
"type": "boolean",
329+
"default": true,
330+
"markdownDescription": "Enable GNATformat as the formatting provider for Ada source files."
331+
},
326332
"ada.onTypeFormatting.indentOnly": {
327333
"scope": "window",
328334
"type": "boolean",

source/ada/lsp-ada_configurations.adb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ package body LSP.Ada_Configurations is
351351
Self.Indent_Only := JSON (Index + 2).Boolean_Value;
352352

353353
end if;
354+
355+
elsif Name = "useGnatformat"
356+
and then JSON (Index).Kind = Boolean_Value
357+
then
358+
Self.Use_Gnatformat := JSON (Index).Boolean_Value;
354359
end if;
355360

356361
Skip_Value (JSON, Index);

source/ada/lsp-ada_configurations.ads

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ package LSP.Ada_Configurations is
8686
-- True if completion is allowed to insert automatically with-clauses for
8787
-- invisible symbols.
8888

89+
function Use_Gnatformat (Self : Configuration'Class) return Boolean;
90+
8991
function Indent_Only (Self : Configuration'Class) return Boolean;
9092

9193
function Follow_Symlinks (Self : Configuration'Class) return Boolean;
@@ -137,6 +139,7 @@ private
137139
Rename_In_Comments : Boolean := False;
138140
Folding_Comments : Boolean := True;
139141
Use_Completion_Snippets : Boolean := True;
142+
Use_Gnatformat : Boolean := False;
140143
Indent_Only : Boolean := True;
141144
Follow_Symlinks : Boolean := True;
142145
Insert_With_Clauses : Boolean := True;
@@ -202,6 +205,9 @@ private
202205
function Folding_Comments (Self : Configuration'Class) return Boolean is
203206
(Self.Folding_Comments);
204207

208+
function Use_Gnatformat (Self : Configuration'Class) return Boolean is
209+
(Self.Use_Gnatformat);
210+
205211
function Indent_Only (Self : Configuration'Class) return Boolean is
206212
(Self.Indent_Only);
207213

source/ada/lsp-ada_handlers-formatting.adb

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ package body LSP.Ada_Handlers.Formatting is
2727
Formatting_Trace : constant GNATCOLL.Traces.Trace_Handle :=
2828
GNATCOLL.Traces.Create ("ALS.FORMATTING", GNATCOLL.Traces.On);
2929

30-
Gnatformat_Trace : constant GNATCOLL.Traces.Trace_Handle :=
31-
GNATCOLL.Traces.Create ("ALS.GNATFORMAT", GNATCOLL.Traces.Off);
32-
3330
procedure Update_Pp_Formatting_Options
3431
(Pp_Options : in out Utils.Command_Lines.Command_Line;
3532
LSP_Options : LSP.Structures.FormattingOptions);
@@ -46,6 +43,7 @@ package body LSP.Ada_Handlers.Formatting is
4643
Document : not null LSP.Ada_Documents.Document_Access;
4744
Span : LSP.Structures.A_Range;
4845
Options : LSP.Structures.FormattingOptions;
46+
Provider : Formatting_Provider;
4947
Success : out Boolean;
5048
Response : out LSP.Structures.TextEdit_Vector;
5149
Messages : out VSS.String_Vectors.Virtual_String_Vector;
@@ -115,12 +113,12 @@ package body LSP.Ada_Handlers.Formatting is
115113
return;
116114
end if;
117115

118-
if Gnatformat_Trace.Is_Active then
119-
Gnatformat_Format;
120-
121-
else
122-
Gnatpp_Format;
123-
end if;
116+
case Provider is
117+
when Gnatformat =>
118+
Gnatformat_Format;
119+
when Gnatpp =>
120+
Gnatpp_Format;
121+
end case;
124122
end Format;
125123

126124
------------------
@@ -132,6 +130,7 @@ package body LSP.Ada_Handlers.Formatting is
132130
Document : not null LSP.Ada_Documents.Document_Access;
133131
Span : LSP.Structures.A_Range;
134132
Options : LSP.Structures.FormattingOptions;
133+
Provider : Formatting_Provider;
135134
Success : out Boolean;
136135
Response : out LSP.Structures.TextEdit_Vector;
137136
Error : out LSP.Errors.ResponseError)
@@ -209,12 +208,12 @@ package body LSP.Ada_Handlers.Formatting is
209208
return;
210209
end if;
211210

212-
if Gnatformat_Trace.Is_Active then
213-
Gnatformat_Range_Format;
214-
215-
else
216-
Gnatpp_Range_Format;
217-
end if;
211+
case Provider is
212+
when Gnatformat =>
213+
Gnatformat_Range_Format;
214+
when Gnatpp =>
215+
Gnatpp_Range_Format;
216+
end case;
218217
end Range_Format;
219218

220219
----------------------------------

source/ada/lsp-ada_handlers-formatting.ads

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ with LSP.Structures;
2525

2626
private package LSP.Ada_Handlers.Formatting is
2727

28+
type Formatting_Provider is (Gnatformat, Gnatpp);
29+
2830
procedure Format
2931
(Context : LSP.Ada_Contexts.Context;
3032
Document : not null LSP.Ada_Documents.Document_Access;
3133
Span : LSP.Structures.A_Range;
3234
Options : LSP.Structures.FormattingOptions;
35+
Provider : Formatting_Provider;
3336
Success : out Boolean;
3437
Response : out LSP.Structures.TextEdit_Vector;
3538
Messages : out VSS.String_Vectors.Virtual_String_Vector;
@@ -41,6 +44,7 @@ private package LSP.Ada_Handlers.Formatting is
4144
Document : not null LSP.Ada_Documents.Document_Access;
4245
Span : LSP.Structures.A_Range;
4346
Options : LSP.Structures.FormattingOptions;
47+
Provider : Formatting_Provider;
4448
Success : out Boolean;
4549
Response : out LSP.Structures.TextEdit_Vector;
4650
Error : out LSP.Errors.ResponseError);

source/ada/lsp-ada_handlers.adb

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,14 +2269,18 @@ package body LSP.Ada_Handlers is
22692269

22702270
begin
22712271
LSP.Ada_Handlers.Formatting.Format
2272-
(Context.all,
2273-
Document,
2274-
LSP.Constants.Empty,
2275-
Value.options,
2276-
Success,
2277-
Response,
2278-
Messages,
2279-
Error);
2272+
(Context => Context.all,
2273+
Document => Document,
2274+
Span => LSP.Constants.Empty,
2275+
Options => Value.options,
2276+
Provider =>
2277+
(if Self.Configuration.Use_Gnatformat
2278+
then LSP.Ada_Handlers.Formatting.Gnatformat
2279+
else LSP.Ada_Handlers.Formatting.Gnatpp),
2280+
Success => Success,
2281+
Response => Response,
2282+
Messages => Messages,
2283+
Error => Error);
22802284

22812285
if Success then
22822286
Self.Sender.On_Formatting_Response (Id, Response);
@@ -2732,13 +2736,17 @@ package body LSP.Ada_Handlers is
27322736

27332737
begin
27342738
LSP.Ada_Handlers.Formatting.Range_Format
2735-
(Context.all,
2736-
Document,
2737-
Previous_NWNC_Token_Span,
2738-
Value.options,
2739-
Success,
2740-
Response,
2741-
Error);
2739+
(Context => Context.all,
2740+
Document => Document,
2741+
Span => Previous_NWNC_Token_Span,
2742+
Options => Value.options,
2743+
Provider =>
2744+
(if Self.Configuration.Use_Gnatformat
2745+
then LSP.Ada_Handlers.Formatting.Gnatformat
2746+
else LSP.Ada_Handlers.Formatting.Gnatpp),
2747+
Success => Success,
2748+
Response => Response,
2749+
Error => Error);
27422750

27432751
if Success then
27442752
-- Result contains the Range_Format result.
@@ -2970,24 +2978,32 @@ package body LSP.Ada_Handlers is
29702978
begin
29712979
if LSP.Ada_Configurations.Partial_GNATPP then
29722980
LSP.Ada_Handlers.Formatting.Range_Format
2973-
(Context.all,
2974-
Document,
2975-
Value.a_range,
2976-
Value.options,
2977-
Success,
2978-
Response,
2979-
Error);
2981+
(Context => Context.all,
2982+
Document => Document,
2983+
Span => Value.a_range,
2984+
Options => Value.options,
2985+
Provider =>
2986+
(if Self.Configuration.Use_Gnatformat
2987+
then LSP.Ada_Handlers.Formatting.Gnatformat
2988+
else LSP.Ada_Handlers.Formatting.Gnatpp),
2989+
Success => Success,
2990+
Response => Response,
2991+
Error => Error);
29802992

29812993
else
29822994
LSP.Ada_Handlers.Formatting.Format
2983-
(Context.all,
2984-
Document,
2985-
Value.a_range,
2986-
Value.options,
2987-
Success,
2988-
Response,
2989-
Messages,
2990-
Error);
2995+
(Context => Context.all,
2996+
Document => Document,
2997+
Span => Value.a_range,
2998+
Options => Value.options,
2999+
Provider =>
3000+
(if Self.Configuration.Use_Gnatformat
3001+
then LSP.Ada_Handlers.Formatting.Gnatformat
3002+
else LSP.Ada_Handlers.Formatting.Gnatpp),
3003+
Success => Success,
3004+
Response => Response,
3005+
Messages => Messages,
3006+
Error => Error);
29913007
end if;
29923008

29933009
if Success then

testsuite/ada_lsp/gnatformat/range_format/.gnatdebug

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
project Test is
2-
for Object_Dir use "obj";
32
for Main use ("main.adb");
43
end Test;

testsuite/ada_lsp/gnatformat/range_format/test.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
[
22
{
33
"start": {
4-
"cmd": [
5-
"${ALS}"
6-
]
4+
"cmd": ["${ALS}"]
75
}
86
},
97
{
@@ -63,7 +61,8 @@
6361
"displayMethodAncestryOnNavigation": "usage_and_abstract_only",
6462
"enableDiagnostics": true,
6563
"useCompletionSnippets": false,
66-
"renameInComments": false
64+
"renameInComments": false,
65+
"useGnatformat": true
6766
}
6867
}
6968
}

0 commit comments

Comments
 (0)