Skip to content

Commit 06415b9

Browse files
Merge branch 'topic/als.1713.fallback_indenter' into 'master'
Add fallback indenter and do some cleanup See merge request eng/ide/ada_language_server!2116
2 parents 3373905 + bb38718 commit 06415b9

File tree

68 files changed

+3114
-854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3114
-854
lines changed

doc/settings.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Settings understood by the Ada Language Server itself, independently from the LS
121121
* [followSymlinks](#followsymlinks)
122122
* [documentationStyle](#documentationstyle)
123123
* [onTypeFormatting.indentOnly](#ontypeformattingindentonly)
124+
* [rangeFormattingFallback](#rangeFormattingFallback)
124125
* [useGnatformat](#usegnatformat)
125126

126127
----
@@ -418,11 +419,16 @@ Conversely, in VS Code this settings can be set without nesting:
418419
}
419420
```
420421

422+
### rangeFormattingFallback
423+
424+
This option controls if the `textDocument/rangeFormatting` request should fallback to another
425+
indenter in case the code is not syntactically correct. If disabled, `textDocument/rangeFormatting`
426+
will return an error if the code is not syntactically correct.
427+
421428
### useGnatformat
422429

423-
This option controls the formatting provider for the `textDocument/formatting`,
424-
`textDocument/rangeFormatting` and `textDocument/onTypeFormatting` request. By default, this option
425-
is enabled and ALS uses GNATformat as its formatting provider. If disabled, GNATpp is used instead.
430+
GNATpp has been removed as a provider for formatting requests. GNATformat is now enabled by default
431+
and this settings is now obsolete.
426432

427433
### logThreshold
428434

@@ -434,4 +440,3 @@ See the documentation on [ALS Traces](traces.md) for more information.
434440
### enableExperimentalFeatures
435441

436442
This option enable the use of experimental features which are still under development.
437-

integration/vscode/ada/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,26 @@
371371
],
372372
"default": null,
373373
"markdownDescription": "If the VS Code `editor.formatOnType` setting is enabled, the Ada Language Server will format Ada code while it is being typed in the editor, in particular when a new line is typed.\n\nThis setting controls whether formatting should only perform the indentation of the new line (true) or also format the previous line (false).\n\nIf not set in VS Code, this setting takes its value from the [`.als.json`](https://github.com/AdaCore/ada_language_server/blob/master/doc/settings.md) file at the root of the workspace, if that file exists. Otherwise it defaults to `true`."
374+
},
375+
"ada.rangeFormattingFallback": {
376+
"scope": "window",
377+
"enum": [
378+
true,
379+
false,
380+
null
381+
],
382+
"enumItemLabels": [
383+
null,
384+
null,
385+
"Provided by .als.json (default: true)"
386+
],
387+
"markdownEnumDescriptions": [
388+
"true",
389+
"false",
390+
"Provided by [`.als.json`](https://github.com/AdaCore/ada_language_server/blob/master/doc/settings.md) if it exists at the workspace root, otherwise defaults to `true`."
391+
],
392+
"default": null,
393+
"markdownDescription": "Enable fallback indenter in case the file is not syntactically correct.\n\nIf not set in VS Code, this setting takes its value from the [`.als.json`](https://github.com/AdaCore/ada_language_server/blob/master/doc/settings.md) file at the root of the workspace, if that file exists. Otherwise it defaults to `true`."
374394
}
375395
}
376396
},

integration/vscode/ada/schemas/als-settings-schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
"default": true,
5454
"markdownDescription": "Enable GNATformat as the formatting provider for Ada source files."
5555
},
56+
"rangeFormattingFallback": {
57+
"type": "boolean",
58+
"default": true,
59+
"markdownDescription": "Enable fallback indenter in case the file is not syntactically correct."
60+
},
5661
"onTypeFormatting": {
5762
"type": "object",
5863
"properties": {

source/ada/lsp-ada_configurations.adb

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ package body LSP.Ada_Configurations is
5757
("ALS.COMPLETION.FORMATTING", Default => GNATCOLL.Traces.On);
5858
-- Used in Completion_Formatting/LSP.Ada_Completions.Pretty_Print_Snippet
5959

60-
Partial_Gnatpp_Trace : constant GNATCOLL.Traces.Trace_Handle :=
61-
GNATCOLL.Traces.Create
62-
(Unit_Name => "ALS.PARTIAL_GNATPP",
63-
Default => GNATCOLL.Traces.On);
64-
-- Trace to enable/disable using partial Gnatpp in the rangeFormatting
65-
-- request.
66-
6760
On_Type_Formatting_Trace : constant GNATCOLL.Traces.Trace_Handle :=
6861
GNATCOLL.Traces.Create
6962
(Unit_Name => "ALS.ON_TYPE_FORMATTING",
@@ -433,6 +426,12 @@ package body LSP.Ada_Configurations is
433426

434427
end if;
435428

429+
elsif Check_Variable
430+
(Name, JSON (Index).Kind, "rangeFormattingFallback",
431+
Boolean_Value)
432+
then
433+
Self.Range_Formatting_Fallback := JSON (Index).Boolean_Value;
434+
436435
elsif Check_Variable
437436
(Name, JSON (Index).Kind, "useGnatformat", Boolean_Value)
438437
then
@@ -475,15 +474,6 @@ package body LSP.Ada_Configurations is
475474
end loop;
476475
end Parse_Ada;
477476

478-
--------------------
479-
-- Partial_GNATPP --
480-
--------------------
481-
482-
function Partial_GNATPP return Boolean is
483-
begin
484-
return Partial_Gnatpp_Trace.Is_Active;
485-
end Partial_GNATPP;
486-
487477
---------------
488478
-- Read_File --
489479
---------------

source/ada/lsp-ada_configurations.ads

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ package LSP.Ada_Configurations is
131131

132132
function Indent_Only (Self : Configuration'Class) return Boolean;
133133

134+
function Range_Formatting_Fallback
135+
(Self : Configuration'Class) return Boolean;
136+
-- Whether the fallback indenter is enabled for rangeFormatting
137+
134138
function Follow_Symlinks (Self : Configuration'Class) return Boolean;
135139
-- False if the client disables symlink following. In this case
136140
-- URIs from client should match file names reported by LAL and
@@ -155,9 +159,6 @@ package LSP.Ada_Configurations is
155159
function Completion_Formatting return Boolean;
156160
-- Used in LSP.Ada_Completions.Pretty_Print_Snippet
157161

158-
function Partial_GNATPP return Boolean;
159-
-- Whether partial GNATPP is enabled.
160-
161162
function On_Type_Formatting return Boolean;
162163
-- Whether onTypeFormatting is enabled.
163164

@@ -187,6 +188,7 @@ private
187188
Use_Completion_Snippets : Boolean := True;
188189
Use_Gnatformat : Boolean := True;
189190
Indent_Only : Boolean := True;
191+
Range_Formatting_Fallback : Boolean := False;
190192
Follow_Symlinks : Boolean := True;
191193
Insert_With_Clauses : Boolean := True;
192194

@@ -281,6 +283,10 @@ private
281283
function Indent_Only (Self : Configuration'Class) return Boolean is
282284
(Self.Indent_Only);
283285

286+
function Range_Formatting_Fallback
287+
(Self : Configuration'Class) return Boolean is
288+
(Self.Range_Formatting_Fallback);
289+
284290
function Documentation_Style (Self : Configuration'Class)
285291
return GNATdoc.Comments.Options.Documentation_Style is
286292
(Self.Documentation_Style);

source/ada/lsp-ada_contexts.adb

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
with Ada.Characters.Handling; use Ada.Characters.Handling;
1919

20-
with GNAT.Strings;
21-
2220
with GNATCOLL.Traces; use GNATCOLL.Traces;
2321
with GNATCOLL.VFS; use GNATCOLL.VFS;
2422

@@ -36,14 +34,10 @@ with VSS.Strings.Conversions;
3634
with Libadalang.Common; use Libadalang.Common;
3735
with Langkit_Support.Slocs;
3836

39-
with Utils.Command_Lines.Common;
40-
41-
with Pp.Actions;
4237
with Langkit_Support.Text;
4338

4439
with URIs;
4540
with LSP.Ada_Id_Iterators;
46-
with LSP.Ada_Projects;
4741

4842
package body LSP.Ada_Contexts is
4943

@@ -582,8 +576,6 @@ package body LSP.Ada_Contexts is
582576
is
583577
procedure Update_Source_Files;
584578
-- Update the value of Self.Source_Files
585-
procedure Pretty_Printer_Setup;
586-
-- Setup PP_Options object
587579

588580
-------------------------
589581
-- Update_Source_Files --
@@ -709,66 +701,6 @@ package body LSP.Ada_Contexts is
709701
end loop;
710702
end Update_Source_Files;
711703

712-
--------------------------
713-
-- Pretty_Printer_Setup --
714-
--------------------------
715-
716-
procedure Pretty_Printer_Setup is
717-
Validated : GNAT.Strings.String_List_Access;
718-
Index : Integer := 0;
719-
Attribute : GPR2.Project.Attribute.Object;
720-
Values : GPR2.Containers.Value_List;
721-
722-
begin
723-
724-
-- Initialize an gnatpp command line object
725-
726-
if Provider.Projects.First_Element.Check_Attribute
727-
(Name => LSP.Ada_Projects.Pretty_Printer.Switches,
728-
Index => LSP.Ada_Projects.Pretty_Printer.Ada_Index,
729-
Result => Attribute)
730-
then
731-
732-
-- Fill 'Values' with non empty value
733-
734-
for Value of Attribute.Values loop
735-
declare
736-
Text : constant String := Value.Text;
737-
begin
738-
if Text /= "" then
739-
Values.Append (Text);
740-
Index := Index + 1;
741-
end if;
742-
end;
743-
end loop;
744-
745-
Validated := new GNAT.Strings.String_List (1 .. Index);
746-
747-
if Index > 0 then
748-
Index := Validated'First;
749-
for Text of Values loop
750-
Validated (Index) := new String'(Text);
751-
Index := Index + 1;
752-
end loop;
753-
end if;
754-
else
755-
Validated := new GNAT.Strings.String_List (1 .. 0);
756-
end if;
757-
758-
Utils.Command_Lines.Parse
759-
(Validated,
760-
Self.PP_Options,
761-
Phase => Utils.Command_Lines.Cmd_Line_1,
762-
Callback => null,
763-
Collect_File_Names => False,
764-
Ignore_Errors => True);
765-
766-
GNAT.Strings.Free (Validated);
767-
768-
-- Set UTF-8 encoding
769-
Utils.Command_Lines.Common.Set_WCEM (Self.PP_Options, "8");
770-
end Pretty_Printer_Setup;
771-
772704
begin
773705
-- Use the full path for the ID to avoid conflict when project are
774706
-- sharing the same name. For example for GNATTest stubs.
@@ -786,7 +718,6 @@ package body LSP.Ada_Contexts is
786718
Self.Reload;
787719
Update_Source_Files;
788720

789-
Pretty_Printer_Setup;
790721
-- Choose the first project in case of aggregate context, assuming
791722
-- they all share the gnatformat options.
792723
Self.Format_Options :=
@@ -818,9 +749,6 @@ package body LSP.Ada_Contexts is
818749
Self.Source_Files.Clear;
819750
Self.Source_Dirs.Clear;
820751
Self.Tree := GPR2.Project.Tree.Undefined;
821-
822-
-- Cleanup gnatpp's template tables
823-
Pp.Actions.Clear_Template_Tables;
824752
end Free;
825753

826754
--------

source/ada/lsp-ada_contexts.ads

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ with Libadalang.Analysis;
3535
with Libadalang.Common;
3636
with Libadalang.Project_Provider;
3737

38-
with Utils.Command_Lines;
39-
with Pp.Command_Lines;
40-
4138
with VSS.String_Vectors;
4239
with VSS.Strings;
4340

@@ -190,13 +187,12 @@ package LSP.Ada_Contexts is
190187
function File_Count (Self : Context) return Natural;
191188
-- Return number of files known to this context.
192189

193-
function Get_PP_Options
194-
(Self : Context) return Utils.Command_Lines.Command_Line;
195-
-- Return the command line for the Pretty Printer
196-
197190
function Get_Format_Options
198191
(Self : Context) return Gnatformat.Configuration.Format_Options_Type;
199-
-- Return the formatting options for Gnatformat
192+
-- Return the project formatting options for Gnatformat.
193+
-- This function should not be called directly most of the time because
194+
-- it doesn't take in consideration the request options. Please use
195+
-- LSP.Ada_Handlers.Formatting.Get_Formatting_Options
200196

201197
function Get_Documentation_Style
202198
(Self : Context) return GNATdoc.Comments.Options.Documentation_Style;
@@ -364,10 +360,6 @@ private
364360
Extension_Set : LSP.Ada_File_Sets.Extension_Sets.Set;
365361
-- All the ada extensions valid for the current project
366362

367-
PP_Options : Utils.Command_Lines.Command_Line
368-
(Pp.Command_Lines.Descriptor'Access);
369-
-- Object to keep gnatpp options
370-
371363
Format_Options : Gnatformat.Configuration.Format_Options_Type;
372364

373365
Style : GNATdoc.Comments.Options.Documentation_Style :=
@@ -396,9 +388,6 @@ private
396388
function File_Count (Self : Context) return Natural
397389
is (Self.Source_Files.Length);
398390

399-
function Get_PP_Options (Self : Context) return
400-
Utils.Command_Lines.Command_Line is (Self.PP_Options);
401-
402391
function Get_Format_Options
403392
(Self : Context)
404393
return Gnatformat.Configuration.Format_Options_Type

0 commit comments

Comments
 (0)