@@ -213,16 +213,6 @@ package body LSP.Ada_Handlers is
213
213
Document : not null LSP.Ada_Documents.Document_Access);
214
214
-- Publish diagnostic messages for given document if needed
215
215
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
-
226
216
function Compute_File_Operations_Server_Capabilities
227
217
(Self : access Message_Handler)
228
218
return LSP.Messages.Optional_FileOperationsServerCapabilities;
@@ -234,10 +224,8 @@ package body LSP.Ada_Handlers is
234
224
(Self : access Message_Handler)
235
225
return LSP.Messages.FileOperationRegistrationOptions;
236
226
-- 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.
241
229
242
230
function Format
243
231
(Self : in out LSP.Ada_Contexts.Context;
@@ -848,6 +836,7 @@ package body LSP.Ada_Handlers is
848
836
LSP.Messages.Optional_FileOperationsClientCapabilities
849
837
renames Self.Client.capabilities.workspace.fileOperations;
850
838
begin
839
+
851
840
if Client_Capabilities.Is_Set
852
841
and then not Self.Contexts.Each_Context.Is_Empty
853
842
then
@@ -894,27 +883,53 @@ package body LSP.Ada_Handlers is
894
883
return LSP.Messages.FileOperationRegistrationOptions
895
884
is
896
885
use LSP.Messages;
886
+ use LSP.Ada_File_Sets.Extension_Sets;
887
+ use VSS.Strings;
897
888
898
889
File_Operation_Filters : LSP.Messages.FileOperationFilter_Vector;
899
890
900
891
begin
892
+
901
893
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 ;
918
933
end loop ;
919
934
920
935
return
@@ -4787,16 +4802,14 @@ package body LSP.Ada_Handlers is
4787
4802
for Change of Value.changes loop
4788
4803
URI := Change.uri;
4789
4804
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 ;
4800
4813
end loop ;
4801
4814
end On_DidChangeWatchedFiles_Notification ;
4802
4815
@@ -5442,18 +5455,16 @@ package body LSP.Ada_Handlers is
5442
5455
-- Context.
5443
5456
5444
5457
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);
5451
5463
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 ;
5457
5468
end ;
5458
5469
end loop ;
5459
5470
@@ -5531,22 +5542,20 @@ package body LSP.Ada_Handlers is
5531
5542
URI_Contexts : Context_Lists.List;
5532
5543
5533
5544
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);
5541
5551
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 ;
5546
5556
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);
5550
5559
end ;
5551
5560
end loop ;
5552
5561
@@ -5569,22 +5578,20 @@ package body LSP.Ada_Handlers is
5569
5578
Is_Document_Open : constant Boolean := Document /= null ;
5570
5579
5571
5580
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 ;
5588
5595
end ;
5589
5596
end loop ;
5590
5597
@@ -5643,19 +5650,17 @@ package body LSP.Ada_Handlers is
5643
5650
-- Context.
5644
5651
5645
5652
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);
5652
5658
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 ;
5659
5664
end ;
5660
5665
end loop ;
5661
5666
0 commit comments