Skip to content

Commit 0c9e5a0

Browse files
U617-025: Index runtime files at startup
To allow having completion for runtime packages that are not included yet, which is similar to what the have with the old engine. An automatic test has also been added.
1 parent fb0b539 commit 0c9e5a0

File tree

10 files changed

+331
-21
lines changed

10 files changed

+331
-21
lines changed

source/ada/lsp-ada_contexts.adb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,8 @@ package body LSP.Ada_Contexts is
841841
procedure Index_File
842842
(Self : in out Context;
843843
File : GNATCOLL.VFS.Virtual_File;
844-
Reparse : Boolean := True)
844+
Reparse : Boolean := True;
845+
PLE : Boolean := True)
845846
is
846847
Unit : constant Libadalang.Analysis.Analysis_Unit :=
847848
Self.LAL_Context.Get_From_File
@@ -850,34 +851,32 @@ package body LSP.Ada_Contexts is
850851
Reparse => Reparse);
851852
begin
852853
Self.Source_Files.Index_File (File, Unit);
854+
855+
if PLE then
856+
Libadalang.Analysis.Populate_Lexical_Env (Unit);
857+
end if;
853858
end Index_File;
854859

855860
--------------------
856861
-- Index_Document --
857862
--------------------
858863

859864
procedure Index_Document
860-
(Self : Context;
865+
(Self : in out Context;
861866
Document : in out LSP.Ada_Documents.Document)
862867
is
863-
File : constant Ada.Strings.UTF_Encoding.UTF_8_String :=
868+
Filename : constant Ada.Strings.UTF_Encoding.UTF_8_String :=
864869
Self.URI_To_File (Document.URI);
865-
Unit : Libadalang.Analysis.Analysis_Unit;
866870
begin
867-
Document.Reset_Symbol_Cache;
868871
-- Reset cache of symbols to avoid access to stale references
872+
Document.Reset_Symbol_Cache;
869873

870-
-- Preprocess the buffer
871-
Unit := Self.LAL_Context.Get_From_File
872-
(Filename => File,
873-
Charset => Ada.Strings.Unbounded.To_String (Self.Charset),
874-
Reparse => True);
875-
876-
-- After creating an analysis unit, populate the lexical env with it:
877-
-- we do this to allow Libadalang to do some work in reaction to
878-
-- a file being open in the IDE, in order to speed up the response
879-
-- to user queries.
880-
Libadalang.Analysis.Populate_Lexical_Env (Unit);
874+
-- Index the file, calling Populate_Lexical_Env on it to speed up the
875+
-- response to user queries.
876+
Self.Index_File
877+
(File => Create_From_UTF8 (Filename),
878+
Reparse => True,
879+
PLE => True);
881880
end Index_Document;
882881

883882
-------------

source/ada/lsp-ada_contexts.ads

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,15 @@ package LSP.Ada_Contexts is
190190
procedure Index_File
191191
(Self : in out Context;
192192
File : GNATCOLL.VFS.Virtual_File;
193-
Reparse : Boolean := True);
193+
Reparse : Boolean := True;
194+
PLE : Boolean := True);
194195
-- Index the given file. This translates to refreshing the Libadalang
195196
-- Analysis_Unit associated to it.
197+
-- If PLE is True, Populate_Lexical_Env is called at the end, which will
198+
-- increase the speed of semantic requests.
196199

197200
procedure Index_Document
198-
(Self : Context;
201+
(Self : in out Context;
199202
Document : in out LSP.Ada_Documents.Document);
200203
-- Index/reindex the given document in this context
201204

source/ada/lsp-ada_handlers-invisibles.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ package body LSP.Ada_Handlers.Invisibles is
9797

9898
if Node.Is_Null or else
9999
(not Node.Parent.Is_Null and then Node.Parent.Kind in
100-
Libadalang.Common.Ada_Defining_Name_Range)
100+
Libadalang.Common.Ada_Defining_Name_Range
101+
| Libadalang.Common.Ada_Dotted_Name_Range)
101102
then
102103
return;
103104
end if;

source/ada/lsp-ada_handlers.adb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ package body LSP.Ada_Handlers is
9090
Notifications_For_Imprecise : constant GNATCOLL.Traces.Trace_Handle :=
9191
GNATCOLL.Traces.Create ("ALS.NOTIFICATIONS_FOR_IMPRECISE_NAVIGATION",
9292
GNATCOLL.Traces.Off);
93-
-- Whether to send notifications to the client for "imprecise"
94-
-- navigation operations.
93+
94+
Runtime_Indexing : constant GNATCOLL.Traces.Trace_Handle :=
95+
GNATCOLL.Traces.Create ("ALS.RUNTIME_INDEXING",
96+
GNATCOLL.Traces.On);
97+
-- Trace to enable/disable runtime indexing. Useful for the testsuite.
9598

9699
Is_Parent : constant LSP.Messages.AlsReferenceKind_Set :=
97100
(Is_Server_Side => True,
@@ -3358,12 +3361,29 @@ package body LSP.Ada_Handlers is
33583361
procedure Mark_Source_Files_For_Indexing (Self : access Message_Handler) is
33593362
begin
33603363
Self.Files_To_Index.Clear;
3364+
3365+
-- Mark all the project's source files
33613366
for C of Self.Contexts.Each_Context loop
33623367
for F in C.List_Files loop
33633368
Self.Files_To_Index.Include
33643369
(LSP.Ada_File_Sets.File_Sets.Element (F));
33653370
end loop;
33663371
end loop;
3372+
3373+
if Runtime_Indexing.Is_Active then
3374+
-- Mark all the predefined sources too (runtime)
3375+
for F in Self.Project_Predefined_Sources.Iterate loop
3376+
declare
3377+
File : GNATCOLL.VFS.Virtual_File renames
3378+
LSP.Ada_File_Sets.File_Sets.Element (F);
3379+
begin
3380+
for Context of Self.Contexts_For_File (File) loop
3381+
Self.Files_To_Index.Include (File);
3382+
end loop;
3383+
end;
3384+
end loop;
3385+
end if;
3386+
33673387
Self.Total_Files_Indexed := 0;
33683388
Self.Total_Files_To_Index := Positive'Max
33693389
(1, Natural (Self.Files_To_Index.Length));

testsuite/.als/traces.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ ALS.ALLOW_INCREMENTAL_TEXT_CHANGES=yes > inout.txt:buffer_size=0
1212

1313
# Activate navigation warnings in test mode
1414
ALS.NOTIFICATIONS_FOR_IMPRECISE_NAVIGATION=yes
15+
16+
# Disable runtime indexing for most tests
17+
ALS.RUNTIME_INDEXING=no
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project Default is
2+
end Default;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
procedure Main is
3+
begin
4+
Ada.Te
5+
end Main;

0 commit comments

Comments
 (0)