Skip to content

Commit 50562cb

Browse files
BoulangerAdrienBoulanger
authored andcommitted
Move indexing after didChange to a job but still reparse the AU
The indexing after didChange is a job which is increasing the IDs for the next requests. Disable this indexing via a trace for the testsuites. Index the runtime only after loading the project
1 parent b90df0f commit 50562cb

10 files changed

+83
-17
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_formatter.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ package body LSP.Ada_Formatter is
4040
(Parent : not null access constant Ada_Range_Formatter_Handler)
4141
is limited
4242
new LSP.Ada_Request_Jobs.Ada_Request_Job
43-
(Priority => LSP.Server_Jobs.Fence)
43+
(Priority => LSP.Server_Jobs.High)
4444
with null record;
4545

4646
type Ada_Range_Formatter_Job_Access is access all Ada_Range_Formatter_Job;
@@ -56,7 +56,7 @@ package body LSP.Ada_Formatter is
5656
(Parent : not null access constant Ada_On_Type_Formatter_Handler)
5757
is limited
5858
new LSP.Ada_Request_Jobs.Ada_Request_Job
59-
(Priority => LSP.Server_Jobs.Fence)
59+
(Priority => LSP.Server_Jobs.High)
6060
with null record;
6161

6262
type Ada_On_Type_Formatter_Job_Access is

source/ada/lsp-ada_handlers-project_loading.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ package body LSP.Ada_Handlers.Project_Loading is
808808
Handler => Self'Unchecked_Access,
809809
Configuration => Self.Configuration,
810810
Project_Stamp => Self.Project_Stamp,
811-
Files => Files);
811+
Files => Files,
812+
Index_Runtime => True);
812813
end Enqueue_Indexing_Job;
813814

814815
---------------------------------------

source/ada/lsp-ada_handlers.adb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ with Ada.Unchecked_Deallocation;
2424
with GNAT.OS_Lib;
2525

2626
with LAL_Refactor.Sort_Case;
27+
with LSP.Ada_Indexing;
2728
with LSP.Env;
2829
with VSS.Characters.Latin;
2930
with VSS.Strings;
@@ -356,6 +357,27 @@ package body LSP.Ada_Handlers is
356357
return Self.Contexts_For_File (File);
357358
end Contexts_For_Position;
358359

360+
----------------------
361+
-- Enqueue_Indexing --
362+
----------------------
363+
364+
overriding
365+
procedure Enqueue_Indexing
366+
(Self : in out Message_Handler;
367+
File : GNATCOLL.VFS.Virtual_File)
368+
is
369+
Files : LSP.Ada_Indexing.File_Sets.Set;
370+
begin
371+
Files.Include (File);
372+
LSP.Ada_Indexing.Schedule_Indexing
373+
(Server => Self.Server,
374+
Handler => Self'Unchecked_Access,
375+
Configuration => Self.Configuration,
376+
Project_Stamp => Self.Project_Stamp,
377+
Files => Files,
378+
Index_Runtime => False);
379+
end Enqueue_Indexing;
380+
359381
----------
360382
-- Free --
361383
----------

source/ada/lsp-ada_handlers.ads

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@ private
413413
-- When Force is True, the diagnostics will always be sent, regardless if
414414
-- they have changed or not.
415415

416+
overriding
417+
procedure Enqueue_Indexing
418+
(Self : in out Message_Handler; File : GNATCOLL.VFS.Virtual_File);
419+
-- Reindex files and clear document.
420+
416421
procedure Publish_Diagnostics
417422
(Self : in out Message_Handler; Force : Boolean := False);
418423
-- Publish workspace diagnostic messages.

source/ada/lsp-ada_indexing.adb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ package body LSP.Ada_Indexing is
117117
Client.On_ProgressEnd_Work_Done
118118
(Self.Indexing_Token, (message => <>));
119119

120-
if Self.Handler.Project_Tree_Is_Aggregate then
120+
if not Self.Handler.Is_Shutdown
121+
and then Self.Index_Runtime
122+
and then Self.Handler.Project_Tree_Is_Aggregate
123+
then
121124
-- Add runtime to the invisible symbols for aggregate project
122125
declare
123126
use GPR2;
@@ -162,7 +165,8 @@ package body LSP.Ada_Indexing is
162165
Handler : not null access LSP.Ada_Handlers.Message_Handler'Class;
163166
Configuration : LSP.Ada_Configurations.Configuration'Class;
164167
Project_Stamp : LSP.Ada_Handlers.Project_Stamp;
165-
Files : File_Sets.Set) is
168+
Files : File_Sets.Set;
169+
Index_Runtime : Boolean) is
166170
begin
167171
if Files.Is_Empty
168172
or not Configuration.Indexing_Enabled
@@ -184,7 +188,8 @@ package body LSP.Ada_Indexing is
184188
Total_Files_Indexed => 0,
185189
Total_Files_To_Index => Natural (Files.Length),
186190
Progress_Report_Sent => Ada.Calendar.Clock,
187-
Project_Stamp => Project_Stamp);
191+
Project_Stamp => Project_Stamp,
192+
Index_Runtime => Index_Runtime);
188193

189194
begin
190195
Server.On_Progress_Create_Request (Id, (token => Token));

source/ada/lsp-ada_indexing.ads

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ package LSP.Ada_Indexing is
4141
Handler : not null access LSP.Ada_Handlers.Message_Handler'Class;
4242
Configuration : LSP.Ada_Configurations.Configuration'Class;
4343
Project_Stamp : LSP.Ada_Handlers.Project_Stamp;
44-
Files : File_Sets.Set);
44+
Files : File_Sets.Set;
45+
Index_Runtime : Boolean);
4546

4647
type Indexing_Job (<>) is new LSP.Server_Jobs.Server_Job
4748
with private;
@@ -82,6 +83,9 @@ private
8283
-- Time of send of last progress notification.
8384

8485
Project_Stamp : LSP.Ada_Handlers.Project_Stamp;
86+
87+
Index_Runtime : Boolean := False;
88+
-- True if the runtime should be indexed
8589
end record;
8690

8791
overriding function Priority

source/ada/lsp-ada_job_contexts.ads

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ package LSP.Ada_Job_Contexts is
114114
Force : Boolean := False) is abstract;
115115
-- Publish document diagnostics
116116

117+
procedure Enqueue_Indexing
118+
(Self : in out Ada_Job_Context;
119+
File : GNATCOLL.VFS.Virtual_File) is abstract;
120+
117121
function Contexts_For_File
118122
(Self : Ada_Job_Context;
119123
File : GNATCOLL.VFS.Virtual_File)

testsuite/.als/ada_ls_traces.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ ALS.COMPLETION.FORMATTING=no
2222

2323
# Disable logging in LSP formatting module
2424
ALS.FORMATTING=no
25+
26+
# Disable indexing after didChange they are shifting the indexing for
27+
# refactoring requests
28+
ALS.DID_CHANGE.INDEXING=no

0 commit comments

Comments
 (0)