@@ -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