Skip to content

Commit 24d78a6

Browse files
committed
Merge branch 'topic/#1554' into 'master'
Use first received configuration as base one if not set yet See merge request eng/ide/ada_language_server!1848
2 parents bd6866d + a82ec5a commit 24d78a6

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

source/ada/lsp-ada_configurations.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ with GPR2.Path_Name;
3030
package LSP.Ada_Configurations is
3131

3232
type Configuration is tagged private;
33+
-- Type representing the server's configuration, containing all the
34+
-- settings that can be set through the 'initialize' and
35+
-- 'didChangeConfiguration' notifications.
3336

3437
function Needs_Reload
3538
(Self : Configuration; Other : Configuration'Class) return Boolean;

source/ada/lsp-ada_handlers.adb

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ package body LSP.Ada_Handlers is
438438
To_Virtual_String (ALS_Workspace_Config_File),
439439
To_Virtual_String (CLI_Config_File)];
440440

441+
Config_File_Processed : Boolean := False;
442+
New_Configuration : LSP.Ada_Configurations.Configuration;
441443
begin
442444
for F_Path of Candidates loop
443445
if not F_Path.Is_Empty then
@@ -448,7 +450,8 @@ package body LSP.Ada_Handlers is
448450
Self.Tracer.Trace_Text ("Trying config file: " & F_Path);
449451
if F.Is_Regular_File then
450452
Self.Tracer.Trace_Text ("Loading config file: " & F_Path);
451-
Self.Configuration.Read_File (F_Path);
453+
New_Configuration.Read_File (F_Path);
454+
Config_File_Processed := True;
452455
else
453456
Self.Tracer.Trace_Text (F_Path & " doesn't exist");
454457
end if;
@@ -461,16 +464,20 @@ package body LSP.Ada_Handlers is
461464
-- overwritten if a value is provided in the initialize request.
462465
-- Prioritize the config file given on the CLI.
463466
if CLI_Config_File.Is_Regular_File then
464-
Self.Client.Set_Root_If_Empty (To_Virtual_String (CLI_Config_File.Dir));
467+
Self.Client.Set_Root_If_Empty
468+
(To_Virtual_String (CLI_Config_File.Dir));
465469
elsif ALS_Workspace_Config_File.Is_Regular_File then
466-
Self.Client.Set_Root_If_Empty (
467-
To_Virtual_String (ALS_Workspace_Config_File.Get_Parent));
470+
Self.Client.Set_Root_If_Empty
471+
(To_Virtual_String (ALS_Workspace_Config_File.Get_Parent));
468472
end if;
469473

470-
-- Save the initial configuration so that we can restore individual
471-
-- settings back to the initial state when 'onDidChangeConfiguration'
472-
-- provides null values.
473-
Self.Base_Configuration := Self.Configuration;
474+
-- Set it as the current configuration.
475+
-- This will also save it as the initial configuration so that
476+
-- we can restore individual settings back to the initial state when
477+
-- 'onDidChangeConfiguration' provides null values.
478+
if Config_File_Processed then
479+
Self.Set_Configuration (New_Configuration);
480+
end if;
474481
end Load_Config_Files;
475482

476483
-------------------
@@ -2425,7 +2432,19 @@ package body LSP.Ada_Handlers is
24252432
-- ...
24262433
-- }
24272434
-- }
2428-
Self.Configuration.Read_JSON (Value.initializationOptions);
2435+
declare
2436+
New_Configuration : LSP.Ada_Configurations.Configuration;
2437+
begin
2438+
-- Parse the configuration.
2439+
New_Configuration.Read_JSON (Value.initializationOptions);
2440+
2441+
-- Set it as the current configuration.
2442+
-- This will also save it as the initial configuration (if not done
2443+
-- yet through config files) so that we can restore individual
2444+
-- settings back to the initial state when
2445+
-- 'onDidChangeConfiguration' provides null values.
2446+
Self.Set_Configuration (New_Configuration);
2447+
end;
24292448

24302449
-- We don't load the project here because we can't send progress
24312450
-- notifications to the client before receiving the 'initialized'
@@ -3783,6 +3802,14 @@ package body LSP.Ada_Handlers is
37833802
Value : LSP.Ada_Configurations.Configuration'Class) is
37843803
begin
37853804
Self.Configuration := LSP.Ada_Configurations.Configuration (Value);
3805+
3806+
-- The base configuration is still the default one, meaning that
3807+
-- we did not receive any user configuration previously: use
3808+
-- the new configuration as the base one.
3809+
if not Self.Base_Configuration_Received then
3810+
Self.Base_Configuration := Self.Configuration;
3811+
Self.Base_Configuration_Received := True;
3812+
end if;
37863813
end Set_Configuration;
37873814

37883815
-----------------------

source/ada/lsp-ada_handlers.ads

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ private
191191
Configuration : aliased LSP.Ada_Configurations.Configuration;
192192
-- The current configuration in use.
193193

194+
Base_Configuration_Received : Boolean := False;
195+
-- Set to true once we receive the user's base configuration, either
196+
-- through config files, the 'initialize' request or the first
197+
-- 'didChangeConfiguration' notification.
198+
194199
Contexts : LSP.Ada_Context_Sets.Context_Set;
195200
-- There is one context in this list per loaded project.
196201
-- There should always be at least one "project" context - if no .gpr

0 commit comments

Comments
 (0)