Skip to content

Commit d8d1ebd

Browse files
Merge branch 'topic/als.138.gnatformat_option' into 'edge'
Add gnatformat preferences to FormatOptions See merge request eng/ide/ada_language_server!1639
2 parents 1bc8887 + a62ee30 commit d8d1ebd

File tree

13 files changed

+218
-58
lines changed

13 files changed

+218
-58
lines changed

doc/metaModel.json

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9087,58 +9087,6 @@
90879087
],
90889088
"documentation": "Provider options for a [DocumentLinkRequest](#DocumentLinkRequest)."
90899089
},
9090-
{
9091-
"name": "FormattingOptions",
9092-
"properties": [
9093-
{
9094-
"name": "tabSize",
9095-
"type": {
9096-
"kind": "base",
9097-
"name": "uinteger"
9098-
},
9099-
"documentation": "Size of a tab in spaces."
9100-
},
9101-
{
9102-
"name": "insertSpaces",
9103-
"type": {
9104-
"kind": "base",
9105-
"name": "boolean"
9106-
},
9107-
"documentation": "Prefer spaces over tabs."
9108-
},
9109-
{
9110-
"name": "trimTrailingWhitespace",
9111-
"type": {
9112-
"kind": "base",
9113-
"name": "boolean"
9114-
},
9115-
"optional": true,
9116-
"documentation": "Trim trailing whitespace on a line.\n\n@since 3.15.0",
9117-
"since": "3.15.0"
9118-
},
9119-
{
9120-
"name": "insertFinalNewline",
9121-
"type": {
9122-
"kind": "base",
9123-
"name": "boolean"
9124-
},
9125-
"optional": true,
9126-
"documentation": "Insert a newline character at the end of the file if one does not exist.\n\n@since 3.15.0",
9127-
"since": "3.15.0"
9128-
},
9129-
{
9130-
"name": "trimFinalNewlines",
9131-
"type": {
9132-
"kind": "base",
9133-
"name": "boolean"
9134-
},
9135-
"optional": true,
9136-
"documentation": "Trim all newlines after the final newline at the end of the file.\n\n@since 3.15.0",
9137-
"since": "3.15.0"
9138-
}
9139-
],
9140-
"documentation": "Value-object describing what options formatting should use."
9141-
},
91429090
{
91439091
"name": "DocumentFormattingOptions",
91449092
"properties": [],

doc/metaModel.patch.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,76 @@
132132
}
133133
],
134134
"structures": [
135+
{
136+
"name": "FormattingOptions",
137+
"properties": [
138+
{
139+
"name": "tabSize",
140+
"type": {
141+
"kind": "base",
142+
"name": "uinteger"
143+
},
144+
"documentation": "Size of a tab in spaces."
145+
},
146+
{
147+
"name": "insertSpaces",
148+
"type": {
149+
"kind": "base",
150+
"name": "boolean"
151+
},
152+
"documentation": "Prefer spaces over tabs."
153+
},
154+
{
155+
"name": "trimTrailingWhitespace",
156+
"type": {
157+
"kind": "base",
158+
"name": "boolean"
159+
},
160+
"optional": true,
161+
"documentation": "Trim trailing whitespace on a line.\n\n@since 3.15.0",
162+
"since": "3.15.0"
163+
},
164+
{
165+
"name": "insertFinalNewline",
166+
"type": {
167+
"kind": "base",
168+
"name": "boolean"
169+
},
170+
"optional": true,
171+
"documentation": "Insert a newline character at the end of the file if one does not exist.\n\n@since 3.15.0",
172+
"since": "3.15.0"
173+
},
174+
{
175+
"name": "trimFinalNewlines",
176+
"type": {
177+
"kind": "base",
178+
"name": "boolean"
179+
},
180+
"optional": true,
181+
"documentation": "Trim all newlines after the final newline at the end of the file.\n\n@since 3.15.0",
182+
"since": "3.15.0"
183+
},
184+
{
185+
"name": "gnatFormatMaxSize",
186+
"type": {
187+
"kind": "base",
188+
"name": "uinteger"
189+
},
190+
"optional": true,
191+
"documentation": "Maximum line width for gnatformat"
192+
},
193+
{
194+
"name": "gnatFormatContinuationLineIndent",
195+
"type": {
196+
"kind": "base",
197+
"name": "uinteger"
198+
},
199+
"optional": true,
200+
"documentation": "Continuation Line Indentation size (defaults to indentation-1) for gnatformat"
201+
}
202+
],
203+
"documentation": "Value-object describing what options formatting should use."
204+
},
135205
{
136206
"name": "AlsCheckSyntaxParams",
137207
"properties": [

liblsp_3_16/source/generated/lsp-message_io.adb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7855,6 +7855,10 @@ package body LSP.Message_IO is
78557855
Optional_Boolean'Read (S, V.insertFinalNewline);
78567856
elsif Key = "trimFinalNewlines" then
78577857
Optional_Boolean'Read (S, V.trimFinalNewlines);
7858+
elsif Key = "gnatFormatMaxSize" then
7859+
Optional_uinteger'Read (S, V.gnatFormatMaxSize);
7860+
elsif Key = "gnatFormatContinuationLineIndent" then
7861+
Optional_uinteger'Read (S, V.gnatFormatContinuationLineIndent);
78587862
else
78597863
JS.Skip_Value;
78607864
end if;
@@ -7880,6 +7884,10 @@ package body LSP.Message_IO is
78807884
Optional_Boolean'Write (S, V.insertFinalNewline);
78817885
JS.Key ("trimFinalNewlines");
78827886
Optional_Boolean'Write (S, V.trimFinalNewlines);
7887+
JS.Key ("gnatFormatMaxSize");
7888+
Optional_uinteger'Write (S, V.gnatFormatMaxSize);
7889+
JS.Key ("gnatFormatContinuationLineIndent");
7890+
Optional_uinteger'Write (S, V.gnatFormatContinuationLineIndent);
78837891
JS.End_Object;
78847892
end Write_FormattingOptions;
78857893

liblsp_3_16/source/lsp-messages.ads

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8716,6 +8716,8 @@ package LSP.Messages is
87168716
trimTrailingWhitespace: Optional_Boolean;
87178717
insertFinalNewline: Optional_Boolean;
87188718
trimFinalNewlines: Optional_Boolean;
8719+
gnatFormatMaxSize : Optional_uinteger;
8720+
gnatFormatContinuationLineIndent : Optional_uinteger;
87198721
-- [key: string]: boolean | number | string; ???
87208722
end record;
87218723
procedure Read_FormattingOptions

liblsp_3_17/source/generated/lsp-inputs-part_19.adb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ package body LSP.Inputs.Part_19 is
382382
"insertSpaces",
383383
"trimTrailingWhitespace",
384384
"insertFinalNewline",
385-
"trimFinalNewlines"]);
385+
"trimFinalNewlines",
386+
"gnatFormatMaxSize",
387+
"gnatFormatContinuationLineIndent"]);
386388

387389
end FormattingOptions_Scope;
388390

@@ -426,6 +428,20 @@ package body LSP.Inputs.Part_19 is
426428
Value => <>);
427429
Value.trimFinalNewlines.Value := Handler.Boolean_Value;
428430
Handler.Read_Next;
431+
when 6 => -- gnatFormatMaxSize
432+
Value.gnatFormatMaxSize :=
433+
(Is_Set => True,
434+
Value => <>);
435+
Value.gnatFormatMaxSize.Value :=
436+
Integer (Handler.Number_Value.Integer_Value);
437+
Handler.Read_Next;
438+
when 7 => -- gnatFormatContinuationLineIndent
439+
Value.gnatFormatContinuationLineIndent :=
440+
(Is_Set => True,
441+
Value => <>);
442+
Value.gnatFormatContinuationLineIndent.Value :=
443+
Integer (Handler.Number_Value.Integer_Value);
444+
Handler.Read_Next;
429445
when others =>
430446
Handler.Skip_Current_Value;
431447
end case;

liblsp_3_17/source/generated/lsp-outputs.adb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7609,6 +7609,15 @@ package body LSP.Outputs is
76097609
Handler.Key_Name ("trimFinalNewlines");
76107610
Handler.Boolean_Value (Value.trimFinalNewlines.Value);
76117611
end if;
7612+
if Value.gnatFormatMaxSize.Is_Set then
7613+
Handler.Key_Name ("gnatFormatMaxSize");
7614+
Handler.Integer_Value (Integer'Pos (Value.gnatFormatMaxSize.Value));
7615+
end if;
7616+
if Value.gnatFormatContinuationLineIndent.Is_Set then
7617+
Handler.Key_Name ("gnatFormatContinuationLineIndent");
7618+
Handler.Integer_Value
7619+
(Integer'Pos (Value.gnatFormatContinuationLineIndent.Value));
7620+
end if;
76127621
Handler.End_Object;
76137622
end Write_FormattingOptions;
76147623

liblsp_3_17/source/generated/lsp-structures.ads

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4884,6 +4884,13 @@ package LSP.Structures is
48844884
--
48854885
-- @since 3.15.0
48864886

4887+
gnatFormatMaxSize : Natural_Optional;
4888+
-- Maximum line width for gnatformat
4889+
4890+
gnatFormatContinuationLineIndent : Natural_Optional;
4891+
-- Continuation Line Indentation size (defaults to indentation-1) for
4892+
-- gnatformat
4893+
48874894
end record;
48884895
-- Value-object describing what options formatting should use.
48894896

source/ada/lsp-ada_documents.adb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ with Ada.Tags;
2020
with GNAT.Strings;
2121
with GNATCOLL.Traces;
2222
with GNATCOLL.VFS;
23-
23+
with Gnatformat.Configuration;
2424
with Gnatformat.Formatting;
2525

2626
with Langkit_Support.Symbols;
@@ -50,6 +50,7 @@ with LSP.Ada_Id_Iterators;
5050
with LSP.Enumerations;
5151
with LSP.Formatters.File_Names;
5252
with LSP.Formatters.Texts;
53+
with LSP.GNATFormat_Utils;
5354
with LSP.Predicates;
5455
with LSP.Structures.LSPAny_Vectors;
5556
with LSP.Utils;
@@ -1242,23 +1243,30 @@ package body LSP.Ada_Documents is
12421243
function Range_Format
12431244
(Self : Document;
12441245
Context : LSP.Ada_Contexts.Context;
1245-
Span : LSP.Structures.A_Range)
1246+
Span : LSP.Structures.A_Range;
1247+
Options : LSP.Structures.FormattingOptions)
12461248
return LSP.Structures.TextEdit
12471249
is
12481250
use type LSP.Structures.A_Range;
1251+
use Gnatformat.Configuration;
12491252

1253+
Full_Options : Format_Options_Type := Context.Get_Format_Options;
12501254
begin
12511255
if Span = LSP.Text_Documents.Empty_Range then
12521256
return (LSP.Constants.Empty, VSS.Strings.Empty_Virtual_String);
12531257
end if;
12541258

1259+
-- Combine the project options with the ones from the request
1260+
Full_Options.Overwrite
1261+
(LSP.GNATFormat_Utils.Get_Format_Option (Options));
1262+
12551263
declare
12561264
Range_Formatted_Document :
12571265
constant Gnatformat.Formatting.Formatted_Edits :=
12581266
Gnatformat.Formatting.Range_Format
12591267
(Self.Unit (Context),
12601268
Self.To_Source_Location_Range (Span),
1261-
Context.Get_Format_Options);
1269+
Full_Options);
12621270

12631271
begin
12641272
return

source/ada/lsp-ada_documents.ads

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ package LSP.Ada_Documents is
196196
function Range_Format
197197
(Self : Document;
198198
Context : LSP.Ada_Contexts.Context;
199-
Span : LSP.Structures.A_Range)
199+
Span : LSP.Structures.A_Range;
200+
Options : LSP.Structures.FormattingOptions)
200201
return LSP.Structures.TextEdit;
201202
-- Format part of Self defined by Span with formatting options based on
202203
-- Context.

source/ada/lsp-ada_handlers-formatting.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ package body LSP.Ada_Handlers.Formatting is
187187
begin
188188
Success := True;
189189
Response.Clear;
190-
Response.Append (Document.Range_Format (Context, Span));
190+
Response.Append
191+
(Document.Range_Format (Context, Span, Options => Options));
191192

192193
exception
193194
when E : others =>

0 commit comments

Comments
 (0)