Skip to content

Commit a4fe79f

Browse files
Merge branch 'topic/als.1719.format_jobs' into 'master'
Add jobs for rangeFormatting and onTypeFormatting Closes #1719 See merge request eng/ide/ada_language_server!2132
2 parents 19265fe + 50562cb commit a4fe79f

13 files changed

+608
-357
lines changed

source/ada/lsp-ada_contexts.adb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -958,16 +958,17 @@ package body LSP.Ada_Contexts is
958958
-----------------------------
959959

960960
function Project_Attribute_Value
961-
(Self : Context;
962-
Attribute : GPR2.Q_Attribute_Id;
963-
Index : String := "";
964-
Default : String := "") return String is
961+
(Self : Context;
962+
Attribute : GPR2.Q_Attribute_Id;
963+
Index : String := "";
964+
Default : String := "") return String is
965965
begin
966-
return Project_Attribute_Value
967-
(View => Self.Tree.Root_Project,
968-
Attribute => Attribute,
969-
Index => Index,
970-
Default => Default);
966+
return
967+
Project_Attribute_Value
968+
(View => Self.Tree.Root_Project,
969+
Attribute => Attribute,
970+
Index => Index,
971+
Default => Default);
971972
end Project_Attribute_Value;
972973

973974
end LSP.Ada_Contexts;

source/ada/lsp-ada_did_change_document.adb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,22 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18+
with GNATCOLL.Traces; use GNATCOLL.Traces;
1819
with GNATCOLL.VFS;
1920

21+
with Libadalang;
22+
with Libadalang.Analysis;
2023
with LSP.Ada_Documents;
2124
with LSP.Client_Message_Receivers;
2225
with LSP.Structures;
2326
with LSP.Server_Notifications.DidChange;
2427

2528
package body LSP.Ada_Did_Change_Document is
2629

30+
Did_Change_Indexing : constant Trace_Handle :=
31+
Create ("ALS.DID_CHANGE.INDEXING", On);
32+
-- Should be disabled when running the testsuite
33+
2734
type Did_Change_Job
2835
(Parent : not null access constant Ada_Did_Change_Handler)
2936
is limited new LSP.Server_Jobs.Server_Job with record
@@ -101,9 +108,22 @@ package body LSP.Ada_Did_Change_Document is
101108
(Message.Params.textDocument.version, Changes);
102109
end if;
103110

111+
-- Clear the cacha of symbols now
112+
LSP.Ada_Documents.Reset_Symbol_Cache (Self.Document.all);
113+
-- Manually reparse the file in all context now so the AU is up-to-date
114+
-- for the following requests.
104115
for Context of Self.Parent.Context.Contexts_For_File (File) loop
105-
Context.Index_Document (Self.Document.all);
116+
declare
117+
Dummy : Libadalang.Analysis.Analysis_Unit;
118+
begin
119+
Dummy := Context.Get_AU (File, Reparse => True);
120+
end;
106121
end loop;
122+
-- The indexing here will do PLE and fill the database of Defining_Name
123+
-- in a separate job at the lowest priority
124+
if Did_Change_Indexing.Is_Active then
125+
Self.Parent.Context.Enqueue_Indexing (File);
126+
end if;
107127

108128
-- Emit diagnostics
109129
Self.Parent.Context.Publish_Diagnostics (Self.Document);

source/ada/lsp-ada_driver.adb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ with LSP.Ada_Did_Change_Document;
5050
with LSP.Ada_Document_Symbol;
5151
with LSP.Ada_Execute_Command;
5252
with LSP.Ada_Folding_Range;
53+
with LSP.Ada_Formatter;
5354
with LSP.Ada_Handlers.Executables_Commands;
5455
with LSP.Ada_Handlers.GPR_Dependencies_Commands;
5556
with LSP.Ada_Handlers.Mains_Commands;
@@ -122,7 +123,9 @@ with LSP.Server_Requests.FoldingRange;
122123
with LSP.Server_Requests.Hover;
123124
with LSP.Server_Requests.Initialize;
124125
with LSP.Server_Requests.InlineValue;
126+
with LSP.Server_Requests.OnTypeFormatting;
125127
with LSP.Server_Requests.PrepareTypeHierarchy;
128+
with LSP.Server_Requests.RangeFormatting;
126129
with LSP.Server_Requests.References;
127130
with LSP.Server_Requests.SelectionRange;
128131
with LSP.Server_Requests.Subtypes;
@@ -310,6 +313,14 @@ procedure LSP.Ada_Driver is
310313
Ada_Hover_Handler : aliased LSP.Ada_Hover.Ada_Hover_Handler
311314
(Ada_Handler'Unchecked_Access);
312315

316+
Ada_Range_Formatter_Handler :
317+
aliased LSP.Ada_Formatter.Ada_Range_Formatter_Handler
318+
(Ada_Handler'Unchecked_Access);
319+
320+
Ada_On_Type_Formatter_Handler :
321+
aliased LSP.Ada_Formatter.Ada_On_Type_Formatter_Handler
322+
(Ada_Handler'Unchecked_Access);
323+
313324
Ada_Definition_Handler : aliased LSP.Ada_Definition.Ada_Definition_Handler
314325
(Ada_Handler'Unchecked_Access);
315326

@@ -702,6 +713,14 @@ begin
702713
(LSP.Server_Requests.Hover.Request'Tag,
703714
Ada_Hover_Handler'Unchecked_Access);
704715

716+
Server.Register_Handler
717+
(LSP.Server_Requests.RangeFormatting.Request'Tag,
718+
Ada_Range_Formatter_Handler'Unchecked_Access);
719+
720+
Server.Register_Handler
721+
(LSP.Server_Requests.OnTypeFormatting.Request'Tag,
722+
Ada_On_Type_Formatter_Handler'Unchecked_Access);
723+
705724
Server.Register_Handler
706725
(LSP.Server_Requests.Definition.Request'Tag,
707726
Ada_Definition_Handler'Unchecked_Access);

0 commit comments

Comments
 (0)