@@ -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 -- ---------------------
0 commit comments