@@ -168,9 +168,6 @@ package body LSP.Ada_Handlers is
168168 procedure Index_Files (Self : access Message_Handler);
169169 -- Index all loaded files in each context. Emit progresormation.
170170
171- procedure Unchecked_Free is new Ada.Unchecked_Deallocation
172- (LSP.Ada_Documents.Document, Internal_Document_Access);
173-
174171 procedure Release_Contexts_And_Project_Info (Self : access Message_Handler);
175172 -- Release the memory associated to project information in Self
176173
@@ -514,20 +511,24 @@ package body LSP.Ada_Handlers is
514511 -- Cleanup --
515512 -- -----------
516513
517- procedure Cleanup (Self : access Message_Handler) is
514+ procedure Cleanup (Self : access Message_Handler)
515+ is
518516 begin
519517 if Self.File_Monitor.Assigned then
520518 Self.File_Monitor.Stop_Monitoring_Directories;
521519 end if ;
522520
523521 -- Cleanup documents
524522 for Document of Self.Open_Documents loop
525- Unchecked_Free (Document);
523+ Free (Document);
526524 end loop ;
527525 Self.Open_Documents.Clear;
528526
529527 -- Cleanup contexts, project and environment
530528 Self.Release_Contexts_And_Project_Info;
529+
530+ -- Free the file monitor
531+ LSP.File_Monitors.Unchecked_Free (Self.File_Monitor);
531532 end Cleanup ;
532533
533534 -- ---------------------
@@ -2553,7 +2554,7 @@ package body LSP.Ada_Handlers is
25532554 Context.Flush_Document (File);
25542555 end loop ;
25552556
2556- Unchecked_Free (Document);
2557+ Free (Document);
25572558
25582559 else
25592560 -- We have received a didCloseTextDocument but the document was
@@ -3686,7 +3687,7 @@ package body LSP.Ada_Handlers is
36863687 (Document.all , Context.all , Pattern,
36873688 Canceled.Has_Been_Canceled'Access , Result.result);
36883689
3689- Unchecked_Free (Internal_Document_Access (Document));
3690+ Free (Internal_Document_Access (Document));
36903691 end ;
36913692 else
36923693 Self.Get_Symbols
@@ -5900,6 +5901,18 @@ package body LSP.Ada_Handlers is
59005901 end if ;
59015902 end Publish_Diagnostics ;
59025903
5904+ -- --------
5905+ -- Free --
5906+ -- --------
5907+
5908+ procedure Free (Self : in out Internal_Document_Access) is
5909+ procedure Unchecked_Free is new Ada.Unchecked_Deallocation
5910+ (LSP.Ada_Documents.Document, Internal_Document_Access);
5911+ begin
5912+ Self.Cleanup;
5913+ Unchecked_Free (Self);
5914+ end Free ;
5915+
59035916 -- ----------------
59045917 -- Show_Message --
59055918 -- ----------------
0 commit comments