Skip to content

Commit 2e4af8f

Browse files
W125-018: Remove Is_Ada_File checks
They are too slow with libgpr2, filter the files using the Ada extensions defined in the loaded project. Adapt tests.
1 parent 9c37072 commit 2e4af8f

File tree

12 files changed

+180
-249
lines changed

12 files changed

+180
-249
lines changed

source/ada/lsp-ada_context_sets.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ package LSP.Ada_Context_Sets is
6565
-- Return the list of all source directories for writable projects in the
6666
-- context, including externally built projects' source directories when
6767
-- Include_Externally_Built is set to True.
68-
-- Each dirctory is present only once in the resulting array.
68+
-- Each directory is present only once in the resulting array.
6969

7070
procedure Cleanup (Self : in out Context_Set'Class);
7171
-- Free memory referenced by Self

source/ada/lsp-ada_contexts.adb

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,6 @@ package body LSP.Ada_Contexts is
265265
File : GNATCOLL.VFS.Virtual_File;
266266
Reparse : Boolean := False) return Libadalang.Analysis.Analysis_Unit is
267267
begin
268-
if not Is_Ada_File (Self.Tree.all, File) then
269-
return Libadalang.Analysis.No_Analysis_Unit;
270-
end if;
271-
272268
return Self.LAL_Context.Get_From_File
273269
(File.Display_Full_Name,
274270
Charset => Self.Get_Charset,
@@ -310,6 +306,16 @@ package body LSP.Ada_Contexts is
310306
end if;
311307
end List_Source_Directories;
312308

309+
----------------------------
310+
-- List_Source_Externsion --
311+
----------------------------
312+
313+
function List_Source_Extensions
314+
(Self : Context) return LSP.Ada_File_Sets.Extension_Sets.Set is
315+
begin
316+
return Self.Extension_Set;
317+
end List_Source_Extensions;
318+
313319
-------------------------
314320
-- Find_All_References --
315321
-------------------------
@@ -744,6 +750,32 @@ package body LSP.Ada_Contexts is
744750
loop
745751
Self.External_Source_Dirs.Include (Dir.Virtual_File);
746752
end loop;
753+
754+
Self.Extension_Set.Clear;
755+
756+
for C in Tree.Iterate
757+
(Kind => (GPR2.Project.I_Runtime => True,
758+
GPR2.Project.I_Configuration => False,
759+
others => True))
760+
loop
761+
declare
762+
View : constant GPR2.Project.View.Object :=
763+
GPR2.Project.Tree.Element (C);
764+
Spec_Suffix : constant String :=
765+
View.Spec_Suffix (GPR2.Ada_Language).Value.Text;
766+
Body_Suffix : constant String :=
767+
View.Body_Suffix (GPR2.Ada_Language).Value.Text;
768+
Separate_Suffix : constant String :=
769+
View.Separate_Suffix.Value.Text;
770+
begin
771+
Self.Extension_Set.Include
772+
(VSS.Strings.Conversions.To_Virtual_String (Spec_Suffix));
773+
Self.Extension_Set.Include
774+
(VSS.Strings.Conversions.To_Virtual_String (Body_Suffix));
775+
Self.Extension_Set.Include
776+
(VSS.Strings.Conversions.To_Virtual_String (Separate_Suffix));
777+
end;
778+
end loop;
747779
end Update_Source_Files;
748780

749781
--------------------------

source/ada/lsp-ada_contexts.ads

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ package LSP.Ada_Contexts is
234234
-- List the source directories, including externally built projects' source
235235
-- directories when Include_Externally_Built is set to True.
236236

237+
function List_Source_Extensions
238+
(Self : Context) return LSP.Ada_File_Sets.Extension_Sets.Set;
239+
-- List all extensions for the current project.
240+
237241
function Get_AU
238242
(Self : Context;
239243
File : GNATCOLL.VFS.Virtual_File;
@@ -355,6 +359,9 @@ private
355359
External_Source_Dirs : LSP.Ada_File_Sets.File_Sets.Set;
356360
-- All the source dirs coming from externally built projects
357361

362+
Extension_Set : LSP.Ada_File_Sets.Extension_Sets.Set;
363+
-- All the ada extensions valid for the current project
364+
358365
PP_Options : Utils.Command_Lines.Command_Line
359366
(Pp.Command_Lines.Descriptor'Access);
360367
-- Object to keep gnatpp options

source/ada/lsp-ada_file_sets.ads

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@ with Libadalang.Analysis;
2828
with Langkit_Support.Slocs;
2929

3030
with VSS.Strings;
31+
with VSS.Strings.Hash;
3132
with LSP.Search;
3233

3334
package LSP.Ada_File_Sets is
3435

36+
package Extension_Sets is
37+
new Ada.Containers.Hashed_Sets
38+
(Element_Type => VSS.Strings.Virtual_String,
39+
Hash => VSS.Strings.Hash,
40+
Equivalent_Elements => VSS.Strings."=",
41+
"=" => VSS.Strings."=");
42+
3543
package File_Sets is new Ada.Containers.Ordered_Sets
3644
(Element_Type => GNATCOLL.VFS.Virtual_File,
3745
"<" => GNATCOLL.VFS."<",

source/ada/lsp-ada_handlers-file_readers.adb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18+
with Ada.Streams;
1819
with GNAT.Strings; use GNAT.Strings;
1920

2021
with GNATCOLL.Traces; use GNATCOLL.Traces;

source/ada/lsp-ada_handlers.adb

Lines changed: 98 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,6 @@ package body LSP.Ada_Handlers is
213213
Document : not null LSP.Ada_Documents.Document_Access);
214214
-- Publish diagnostic messages for given document if needed
215215

216-
function Is_Ada_Source
217-
(Self : access Message_Handler;
218-
File : GNATCOLL.VFS.Virtual_File)
219-
return Boolean
220-
is (Is_Ada_File (Self.Project_Tree, File));
221-
-- Checks if File is an Ada source of Self's project. This is needed
222-
-- to filter non Ada sources on notifications like
223-
-- DidCreate/Rename/DeleteFiles and DidChangeWatchedFiles since it's not
224-
-- possible to filter them in the FileOperationRegistrationOptions.
225-
226216
function Compute_File_Operations_Server_Capabilities
227217
(Self : access Message_Handler)
228218
return LSP.Messages.Optional_FileOperationsServerCapabilities;
@@ -234,10 +224,8 @@ package body LSP.Ada_Handlers is
234224
(Self : access Message_Handler)
235225
return LSP.Messages.FileOperationRegistrationOptions;
236226
-- Computes FileOperationRegistrationOptions based on the project held by
237-
-- Self. These registration options will include any file that is in a
238-
-- source folder of Self's project. We can't filter non Ada sources here,
239-
-- only on the DidCreate/Rename/DeleteFiles and DidChangeWatchedFiles
240-
-- notifications.
227+
-- Self. These registration options will include Ada file that is in a
228+
-- source folder of Self's project.
241229

242230
function Format
243231
(Self : in out LSP.Ada_Contexts.Context;
@@ -848,6 +836,7 @@ package body LSP.Ada_Handlers is
848836
LSP.Messages.Optional_FileOperationsClientCapabilities
849837
renames Self.Client.capabilities.workspace.fileOperations;
850838
begin
839+
851840
if Client_Capabilities.Is_Set
852841
and then not Self.Contexts.Each_Context.Is_Empty
853842
then
@@ -894,27 +883,53 @@ package body LSP.Ada_Handlers is
894883
return LSP.Messages.FileOperationRegistrationOptions
895884
is
896885
use LSP.Messages;
886+
use LSP.Ada_File_Sets.Extension_Sets;
887+
use VSS.Strings;
897888

898889
File_Operation_Filters : LSP.Messages.FileOperationFilter_Vector;
899890

900891
begin
892+
901893
for Context of Self.Contexts.Each_Context loop
902-
for Source_Dir of Context.List_Source_Directories loop
903-
declare
904-
Dir_Full_Name : constant GNATCOLL.VFS.Filesystem_String :=
905-
GNATCOLL.VFS."/" (Source_Dir, "*").Full_Name;
906-
Scheme : constant VSS.Strings.Virtual_String := "file";
907-
Sources_Glob : constant VSS.Strings.Virtual_String :=
908-
VSS.Strings.Conversions.To_Virtual_String (+Dir_Full_Name);
909-
910-
File_Operation_Filter :
911-
constant LSP.Messages.FileOperationFilter :=
912-
(scheme => (Is_Set => True, Value => Scheme),
913-
pattern => (glob => Sources_Glob, others => <>));
914-
begin
915-
File_Operation_Filters.Append (File_Operation_Filter);
916-
end;
917-
end loop;
894+
declare
895+
Extensions_Set : constant LSP.Ada_File_Sets.Extension_Sets.Set
896+
:= Context.List_Source_Extensions;
897+
-- Need to lock the Set in a local variable for the cursor to stay
898+
-- valid.
899+
Extension_Pattern : VSS.Strings.Virtual_String := "{";
900+
Extension_Cursor : LSP.Ada_File_Sets.Extension_Sets.Cursor :=
901+
First (Extensions_Set);
902+
begin
903+
while Has_Element (Extension_Cursor) loop
904+
Extension_Pattern.Append (Element (Extension_Cursor));
905+
Next (Extension_Cursor);
906+
if Has_Element (Extension_Cursor) then
907+
Extension_Pattern.Append (",");
908+
else
909+
Extension_Pattern.Append ("}");
910+
end if;
911+
end loop;
912+
913+
for Source_Dir of Context.List_Source_Directories loop
914+
declare
915+
Dir_Full_Name : constant GNATCOLL.VFS.Filesystem_String :=
916+
GNATCOLL.VFS."/" (Source_Dir, "*").Full_Name;
917+
Scheme : constant VSS.Strings.Virtual_String :=
918+
"file";
919+
Sources_Glob : constant VSS.Strings.Virtual_String :=
920+
VSS.Strings.Conversions.To_Virtual_String (+Dir_Full_Name);
921+
922+
File_Operation_Filter :
923+
constant LSP.Messages.FileOperationFilter :=
924+
(scheme => (Is_Set => True,
925+
Value => Scheme),
926+
pattern => (glob => Sources_Glob & Extension_Pattern,
927+
others => <>));
928+
begin
929+
File_Operation_Filters.Append (File_Operation_Filter);
930+
end;
931+
end loop;
932+
end;
918933
end loop;
919934

920935
return
@@ -4787,16 +4802,14 @@ package body LSP.Ada_Handlers is
47874802
for Change of Value.changes loop
47884803
URI := Change.uri;
47894804
File := Self.To_File (URI);
4790-
if Self.Is_Ada_Source (File) then
4791-
case Change.a_type is
4792-
when LSP.Messages.Created =>
4793-
Process_Created_File;
4794-
when LSP.Messages.Deleted =>
4795-
Process_Deleted_File;
4796-
when LSP.Messages.Changed =>
4797-
Process_Changed_File;
4798-
end case;
4799-
end if;
4805+
case Change.a_type is
4806+
when LSP.Messages.Created =>
4807+
Process_Created_File;
4808+
when LSP.Messages.Deleted =>
4809+
Process_Deleted_File;
4810+
when LSP.Messages.Changed =>
4811+
Process_Changed_File;
4812+
end case;
48004813
end loop;
48014814
end On_DidChangeWatchedFiles_Notification;
48024815

@@ -5442,18 +5455,16 @@ package body LSP.Ada_Handlers is
54425455
-- Context.
54435456

54445457
begin
5445-
if Self.Is_Ada_Source (Created_File) then
5446-
for Context of Self.Contexts.Each_Context
5447-
(Has_Dir'Unrestricted_Access)
5448-
loop
5449-
Context.Include_File (Created_File);
5450-
Context.Index_File (Created_File);
5458+
for Context of Self.Contexts.Each_Context
5459+
(Has_Dir'Unrestricted_Access)
5460+
loop
5461+
Context.Include_File (Created_File);
5462+
Context.Index_File (Created_File);
54515463

5452-
Self.Trace.Trace
5453-
("Included " & Created_File.Display_Base_Name
5454-
& " in context " & To_UTF_8_String (Context.Id));
5455-
end loop;
5456-
end if;
5464+
Self.Trace.Trace
5465+
("Included " & Created_File.Display_Base_Name
5466+
& " in context " & To_UTF_8_String (Context.Id));
5467+
end loop;
54575468
end;
54585469
end loop;
54595470

@@ -5531,22 +5542,20 @@ package body LSP.Ada_Handlers is
55315542
URI_Contexts : Context_Lists.List;
55325543

55335544
begin
5534-
if Self.Is_Ada_Source (Old_File) then
5535-
for Context of Self.Contexts.Each_Context
5536-
(Has_File'Unrestricted_Access)
5537-
loop
5538-
URI_Contexts.Append (Context);
5539-
Context.Exclude_File (Old_File);
5540-
Context.Index_File (Old_File);
5545+
for Context of Self.Contexts.Each_Context
5546+
(Has_File'Unrestricted_Access)
5547+
loop
5548+
URI_Contexts.Append (Context);
5549+
Context.Exclude_File (Old_File);
5550+
Context.Index_File (Old_File);
55415551

5542-
Self.Trace.Trace
5543-
("Excluded " & Old_File.Display_Full_Name
5544-
& " from context " & To_UTF_8_String (Context.Id));
5545-
end loop;
5552+
Self.Trace.Trace
5553+
("Excluded " & Old_File.Display_Full_Name
5554+
& " from context " & To_UTF_8_String (Context.Id));
5555+
end loop;
55465556

5547-
URIs_Contexts.Insert
5548-
(To_LSP_URI (File_Rename.oldUri), URI_Contexts);
5549-
end if;
5557+
URIs_Contexts.Insert
5558+
(To_LSP_URI (File_Rename.oldUri), URI_Contexts);
55505559
end;
55515560
end loop;
55525561

@@ -5569,22 +5578,20 @@ package body LSP.Ada_Handlers is
55695578
Is_Document_Open : constant Boolean := Document /= null;
55705579

55715580
begin
5572-
if Self.Is_Ada_Source (New_File) then
5573-
for Context of
5574-
URIs_Contexts.Constant_Reference
5575-
(To_LSP_URI (File_Rename.oldUri))
5576-
loop
5577-
Context.Include_File (New_File);
5578-
if Is_Document_Open then
5579-
Context.Index_Document (Document.all);
5580-
else
5581-
Context.Index_File (New_File);
5582-
end if;
5583-
Self.Trace.Trace
5584-
("Included " & New_File.Display_Base_Name & " in context "
5585-
& To_UTF_8_String (Context.Id));
5586-
end loop;
5587-
end if;
5581+
for Context of
5582+
URIs_Contexts.Constant_Reference
5583+
(To_LSP_URI (File_Rename.oldUri))
5584+
loop
5585+
Context.Include_File (New_File);
5586+
if Is_Document_Open then
5587+
Context.Index_Document (Document.all);
5588+
else
5589+
Context.Index_File (New_File);
5590+
end if;
5591+
Self.Trace.Trace
5592+
("Included " & New_File.Display_Base_Name & " in context "
5593+
& To_UTF_8_String (Context.Id));
5594+
end loop;
55885595
end;
55895596
end loop;
55905597

@@ -5643,19 +5650,17 @@ package body LSP.Ada_Handlers is
56435650
-- Context.
56445651

56455652
begin
5646-
if Self.Is_Ada_Source (Deleted_File) then
5647-
for Context of Self.Contexts.Each_Context
5648-
(Has_File'Unrestricted_Access)
5649-
loop
5650-
Context.Exclude_File (Deleted_File);
5651-
Context.Index_File (Deleted_File);
5653+
for Context of Self.Contexts.Each_Context
5654+
(Has_File'Unrestricted_Access)
5655+
loop
5656+
Context.Exclude_File (Deleted_File);
5657+
Context.Index_File (Deleted_File);
56525658

5653-
Self.Trace.Trace
5654-
("Excluded " & Deleted_File.Display_Base_Name
5655-
& " from context "
5656-
& VSS.Strings.Conversions.To_UTF_8_String (Context.Id));
5657-
end loop;
5658-
end if;
5659+
Self.Trace.Trace
5660+
("Excluded " & Deleted_File.Display_Base_Name
5661+
& " from context "
5662+
& VSS.Strings.Conversions.To_UTF_8_String (Context.Id));
5663+
end loop;
56595664
end;
56605665
end loop;
56615666

0 commit comments

Comments
 (0)