@@ -121,6 +121,48 @@ procedure LSP.Ada_Driver is
121
121
procedure Register_Commands ;
122
122
-- Register all known commands
123
123
124
+ procedure Remove_Old_Log_files
125
+ (Dir : GNATCOLL.VFS.Virtual_File;
126
+ Prefix : String;
127
+ Max_Nb_Of_Log_Files : Integer);
128
+ -- Remove old log files with the given prefix in the given log
129
+ -- directory when it exceeds the number specified in Max_Nb_Of_Log_Files.
130
+
131
+ -- ------------------------
132
+ -- Remove_Old_Log_files --
133
+ -- ------------------------
134
+
135
+ procedure Remove_Old_Log_files
136
+ (Dir : GNATCOLL.VFS.Virtual_File;
137
+ Prefix : String;
138
+ Max_Nb_Of_Log_Files : Integer)
139
+ is
140
+ Files : File_Array_Access := Read_Dir (Dir, Files_Only);
141
+ Success : Boolean;
142
+ Counted : Natural := 0 ;
143
+ Traces_File_Suffix : constant String := " .cfg" ;
144
+ begin
145
+ Sort (Files.all );
146
+
147
+ -- Browse the log files in reverse timestamp order
148
+ for J in reverse Files'Range loop
149
+ if GNATCOLL.Utils.Starts_With (+Files (J).Base_Name, Prefix)
150
+ and then not GNATCOLL.Utils.Ends_With
151
+ (+Files (J).Base_Name, Traces_File_Suffix)
152
+ then
153
+ Counted := Counted + 1 ;
154
+
155
+ -- When we've counted all the files we wanted to keep, delete
156
+ -- the older ones.
157
+ if Counted > Max_Nb_Of_Log_Files then
158
+ Delete (Files (J), Success);
159
+ end if ;
160
+ end if ;
161
+ end loop ;
162
+
163
+ Unchecked_Free (Files);
164
+ end Remove_Old_Log_files ;
165
+
124
166
-- ---------------------
125
167
-- Register_Commands --
126
168
-- ---------------------
@@ -317,6 +359,9 @@ procedure LSP.Ada_Driver is
317
359
Long_Name => " version" ,
318
360
Description => " Display the program version" );
319
361
362
+ Ada_Log_File_Prefix : constant String := " ada_ls" ;
363
+ GPR_Log_File_Prefix : constant String := " gpr_ls" ;
364
+
320
365
Config_File : Virtual_File;
321
366
322
367
Memory_Monitor_Enabled : Boolean;
@@ -384,8 +429,8 @@ begin
384
429
Traces_File := Create_From_Dir
385
430
(Dir => ALS_Dir,
386
431
Base_Name =>
387
- (if VSS.Command_Line.Is_Specified (Language_GPR_Option) then
388
- " gpr_ls " else " ada_ls " ) & " _traces.cfg" );
432
+ + (if VSS.Command_Line.Is_Specified (Language_GPR_Option) then
433
+ GPR_Log_File_Prefix else Ada_Log_File_Prefix ) & " _traces.cfg" );
389
434
390
435
-- No default traces file found: create one if we can
391
436
if not Traces_File.Is_Regular_File and then ALS_Dir.Is_Writable then
@@ -394,7 +439,7 @@ begin
394
439
Default_Traces_File_Contents : constant String :=
395
440
" >"
396
441
& (if VSS.Command_Line.Is_Specified (Language_GPR_Option)
397
- then " gpr_ls " else " ada_ls " )
442
+ then GPR_Log_File_Prefix else Ada_Log_File_Prefix )
398
443
& " _log.$T.log:buffer_size=0:buffer_size=0"
399
444
& Ada.Characters.Latin_1.LF
400
445
& " ALS.MAIN=yes" & Ada.Characters.Latin_1.LF
@@ -616,8 +661,16 @@ begin
616
661
end if ;
617
662
618
663
Server.Finalize;
664
+
619
665
if Clean_ALS_Dir then
620
- Ada_Handler.Clean_Logs (ALS_Dir);
666
+ -- Remove the logs produced for the GPR language if the '--language-gpr'
667
+ -- option has been specified. Otherwise remove the Ada language logs.
668
+ Remove_Old_Log_files
669
+ (Dir => ALS_Dir,
670
+ Prefix =>
671
+ (if VSS.Command_Line.Is_Specified (Language_GPR_Option) then
672
+ GPR_Log_File_Prefix else Ada_Log_File_Prefix),
673
+ Max_Nb_Of_Log_Files => Ada_Handler.Get_Configuration.Log_Threshold);
621
674
end if ;
622
675
623
676
-- Clean secondary stack up
0 commit comments