Skip to content

Commit

Permalink
Merge branch 'topic/eng/ide/ada_language_server#1373' into 'master'
Browse files Browse the repository at this point in the history
Create ~/.als/traces.cfg file by default

See merge request eng/ide/ada_language_server!1586
  • Loading branch information
AnthonyLeonardoGracio committed Jun 27, 2024
2 parents 951d78d + 65c4b08 commit aafce3d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 28 deletions.
23 changes: 14 additions & 9 deletions doc/traces.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# ALS Trace File

Default trace file name is `$HOME/.als/traces.cfg`.
You can provide another file by `--tracefile=<FILE>` command line option.
Default trace file name is `$HOME/.als/traces.cfg`. This file gets automatically created
if not present on the disk. The first line of the traces file
defines the traces output stream (a filename in our case) and the other
lines are used to enable or disable traces.

Here is a list of supported settings.
Note that you can provide another traces file via the `--tracefile=<FILE>` command line option.

Here is a list of the most useful supported traces:

## `ALS.IN` (default no)
Show all the server input. Use this way:
Shows all the server's input. Use this way:

ALS.IN=yes > inout.txt:buffer_size=0
ALS.IN=yes

## `ALS.OUT` (default no)
Show all the server output. Use this way:
Shows all the server's output. Use this way:

ALS.OUT=yes > inout.txt:buffer_size=0
ALS.OUT=yes

## `ALS.MAIN` (default no)
Trace requests, notifications and responses in an ALS log file.
## `ALS.MAIN` (default yes)
Trace requests, notifications and responses in ALS log files. Will
also log any exception that occurs when handling LSP requests.

ALS.MAIN=yes

Expand Down
58 changes: 39 additions & 19 deletions source/ada/lsp-ada_driver.adb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
--
-- This is driver to run LSP server for Ada language.

with Ada.Characters.Latin_1;
with Ada.Text_IO;
with Ada.Strings.Unbounded;
with GNAT.OS_Lib;
Expand Down Expand Up @@ -257,6 +258,14 @@ procedure LSP.Ada_Driver is
GNATdebug : constant Virtual_File := Create_From_Base
(".gnatdebug");

Default_Traces_File_Contents : constant String :=
">als.$T.txt:buffer_size=0" & Ada.Characters.Latin_1.LF
& "ALS.MAIN=yes" & Ada.Characters.Latin_1.LF
& "ALS.IN=no" & Ada.Characters.Latin_1.LF
& "ALS.OUT=no" & Ada.Characters.Latin_1.LF;

Traces_File : Virtual_File;

Trace_File_Option : constant VSS.Command_Line.Value_Option :=
(Short_Name => "",
Long_Name => "tracefile",
Expand Down Expand Up @@ -309,31 +318,42 @@ begin
-- - in a .gnatdebug file locally
-- - in "traces.cfg" in the ALS home directory
if VSS.Command_Line.Is_Specified (Trace_File_Option) then
declare
Traces_File : constant Virtual_File := Create_From_UTF8
(VSS.Strings.Conversions.To_UTF_8_String
(VSS.Command_Line.Value (Trace_File_Option)));
begin
if not Traces_File.Is_Regular_File then
Ada.Text_IO.Put_Line ("Could not find the specified traces file");
GNAT.OS_Lib.OS_Exit (1);
end if;
Traces_File := Create_From_UTF8
(VSS.Strings.Conversions.To_UTF_8_String
(VSS.Command_Line.Value (Trace_File_Option)));
if not Traces_File.Is_Regular_File then
Ada.Text_IO.Put_Line ("Could not find the specified traces file");
GNAT.OS_Lib.OS_Exit (1);
end if;

Parse_Config_File (Traces_File);

Parse_Config_File (Traces_File);
end;
elsif GNATdebug.Is_Regular_File then
Parse_Config_File (GNATdebug);

elsif ALS_Dir.Is_Directory then
Clean_ALS_Dir := True;
else
-- No $HOME/.als directory: create one first
if not ALS_Dir.Is_Directory then
Make_Dir (ALS_Dir);
end if;

-- Search for custom traces config in traces.cfg
Parse_Config_File (+Virtual_File'(ALS_Dir / "traces.cfg").Full_Name);
Traces_File := Create_From_Dir
(Dir => ALS_Dir,
Base_Name => "traces.cfg");

-- No default traces file found: create one
if not Traces_File.Is_Regular_File then
declare
W_Traces_File : Writable_File;
begin
W_Traces_File := Traces_File.Write_File;
W_Traces_File.Write (Default_Traces_File_Contents);
W_Traces_File.Close;
end;
end if;

-- Set log file
Set_Default_Stream
(">" & (+Virtual_File'(ALS_Dir / "als").Full_Name) &
".$T.$$.log:buffer_size=0");
Clean_ALS_Dir := True;
Parse_Config_File (Traces_File);
end if;

-- Look for a config file, that contains the configuration for the server
Expand Down
3 changes: 3 additions & 0 deletions testsuite/.als/traces.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ ALS.RUNTIME_INDEXING=no

# Disable advanced PP formatting of snippet for most tests
ALS.COMPLETION.FORMATTING=no

# Disable logging in LSP formatting module
ALS.FORMATTING=no

0 comments on commit aafce3d

Please sign in to comment.