Skip to content

Commit a4d444c

Browse files
Merge branch 'topic/als.1238.fix_number_log' into 'master'
Fix number of log files Closes #1238 See merge request eng/ide/ada_language_server!1434
2 parents 6ee62c5 + 8717d4d commit a4d444c

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

source/ada/lsp-ada_driver.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ begin
381381

382382
Server.Finalize;
383383
if Clean_ALS_Dir then
384-
pragma Assert (Clean_ALS_Dir);
384+
Ada_Handler.Clean_Logs (ALS_Dir);
385385
end if;
386386

387387
-- Clean secondary stack up

source/ada/lsp-ada_handlers.adb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ with Ada.Unchecked_Deallocation;
2323

2424
with GNAT.OS_Lib;
2525
with GNATCOLL.Traces;
26+
with GNATCOLL.Utils;
2627

2728
with VSS.Characters.Latin;
2829
with VSS.Strings.Formatters.Integers;
@@ -216,6 +217,34 @@ package body LSP.Ada_Handlers is
216217
end if;
217218
end Clean_Diagnostics;
218219

220+
----------------
221+
-- Clean_Logs --
222+
----------------
223+
224+
procedure Clean_Logs
225+
(Self : access Message_Handler'Class;
226+
Dir : GNATCOLL.VFS.Virtual_File)
227+
is
228+
use GNATCOLL.VFS;
229+
Files : File_Array_Access := Read_Dir (Dir, Files_Only);
230+
Dummy : Boolean;
231+
Cpt : Integer := 0;
232+
begin
233+
Sort (Files.all);
234+
-- Browse the log files in reverse timestamp order
235+
for F of reverse Files.all loop
236+
-- Filter out files like traces.cfg
237+
if GNATCOLL.Utils.Ends_With (+F.Base_Name, ".log") then
238+
Cpt := Cpt + 1;
239+
-- Delete the old logs
240+
if Cpt > Self.Configuration.Log_Threshold then
241+
Delete (F, Dummy);
242+
end if;
243+
end if;
244+
end loop;
245+
Unchecked_Free (Files);
246+
end Clean_Logs;
247+
219248
-----------------------
220249
-- Contexts_For_File --
221250
-----------------------

source/ada/lsp-ada_handlers.ads

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ package LSP.Ada_Handlers is
8787
return LSP.Structures.ProgressToken;
8888
-- Return an unique token for indicating progress
8989

90-
----------------------------
91-
-- Open Document Manger --
92-
----------------------------
90+
-----------------------------
91+
-- Open Document Manager --
92+
-----------------------------
9393

9494
function Get_Open_Document
9595
(Self : in out Message_Handler;
@@ -125,6 +125,15 @@ package LSP.Ada_Handlers is
125125
-- If the document is not opened, then it returns a
126126
-- OptionalVersionedTextDocumentIdentifier with a null version.
127127

128+
-----------------
129+
-- Log Manager --
130+
-----------------
131+
132+
procedure Clean_Logs
133+
(Self : access Message_Handler'Class;
134+
Dir : GNATCOLL.VFS.Virtual_File);
135+
-- Remove the oldest logs in Dir
136+
128137
private
129138

130139
type Load_Project_Status is

0 commit comments

Comments
 (0)