Skip to content

Commit 921660f

Browse files
Merge branch 'cherry-pick-5b445808' into '25.0'
Merge branch 'topic/eng/ide/ada_language_server#1451' into 'master' See merge request eng/ide/ada_language_server!1719
2 parents 2f8c9cd + dac8554 commit 921660f

File tree

4 files changed

+58
-51
lines changed

4 files changed

+58
-51
lines changed

source/ada/lsp-ada_driver.adb

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,48 @@ procedure LSP.Ada_Driver is
121121
procedure Register_Commands;
122122
-- Register all known commands
123123

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+
124166
-----------------------
125167
-- Register_Commands --
126168
-----------------------
@@ -317,6 +359,9 @@ procedure LSP.Ada_Driver is
317359
Long_Name => "version",
318360
Description => "Display the program version");
319361

362+
Ada_Log_File_Prefix : constant String := "ada_ls";
363+
GPR_Log_File_Prefix : constant String := "gpr_ls";
364+
320365
Config_File : Virtual_File;
321366

322367
Memory_Monitor_Enabled : Boolean;
@@ -384,8 +429,8 @@ begin
384429
Traces_File := Create_From_Dir
385430
(Dir => ALS_Dir,
386431
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");
389434

390435
-- No default traces file found: create one if we can
391436
if not Traces_File.Is_Regular_File and then ALS_Dir.Is_Writable then
@@ -394,7 +439,7 @@ begin
394439
Default_Traces_File_Contents : constant String :=
395440
">"
396441
& (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)
398443
& "_log.$T.log:buffer_size=0:buffer_size=0"
399444
& Ada.Characters.Latin_1.LF
400445
& "ALS.MAIN=yes" & Ada.Characters.Latin_1.LF
@@ -616,8 +661,16 @@ begin
616661
end if;
617662

618663
Server.Finalize;
664+
619665
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);
621674
end if;
622675

623676
-- Clean secondary stack up

source/ada/lsp-ada_handlers-project_loading.adb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,7 @@ package body LSP.Ada_Handlers.Project_Loading is
398398
-- Log the messages
399399
Self.Tracer.Trace ("GPR2 Log Messages:");
400400
for Msg of Update_Log loop
401-
declare
402-
Location : constant String :=
403-
Msg.Sloc.Format (Full_Path_Name => True);
404-
Message : constant String := Msg.Message;
405-
begin
406-
Self.Tracer.Trace (Location & " " & Message);
407-
end;
401+
Self.Tracer.Trace (Msg.Format);
408402
end loop;
409403

410404
-- Retrieve the GPR2 error/warning messages right after loading the

source/ada/lsp-ada_handlers.adb

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ with Ada.Strings.UTF_Encoding;
2121
with Ada.Unchecked_Deallocation;
2222

2323
with GNAT.OS_Lib;
24-
with GNATCOLL.Utils;
2524

2625
with VSS.Characters.Latin;
2726
with VSS.Strings.Formatters.Integers;
@@ -220,36 +219,6 @@ package body LSP.Ada_Handlers is
220219
end if;
221220
end Clean_Diagnostics;
222221

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

source/ada/lsp-ada_handlers.ads

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,6 @@ package LSP.Ada_Handlers is
132132
-- If the document is not opened, then it returns a
133133
-- OptionalVersionedTextDocumentIdentifier with a null version.
134134

135-
-----------------
136-
-- Log Manager --
137-
-----------------
138-
139-
procedure Clean_Logs
140-
(Self : access Message_Handler'Class;
141-
Dir : GNATCOLL.VFS.Virtual_File);
142-
-- Remove the oldest logs in Dir
143-
144135
private
145136
type Project_Stamp is mod 2**32;
146137

0 commit comments

Comments
 (0)