@@ -838,18 +838,49 @@ package body LSP.Ada_Handlers.Project_Loading is
838838 (Self : in out Message_Handler'Class)
839839 is
840840 use GPR2;
841- use GPR2.Build.Source.Sets;
841+
842+ procedure For_All_Part_Action
843+ (Kind : Unit_Kind;
844+ View : GPR2.Project.View.Object;
845+ Path : Path_Name.Object;
846+ Index : Unit_Index;
847+ Sep_Name : Optional_Name_Type);
848+
849+ -- -----------------------
850+ -- For_All_Part_Action --
851+ -- -----------------------
852+
853+ procedure For_All_Part_Action
854+ (Kind : Unit_Kind;
855+ View : GPR2.Project.View.Object;
856+ Path : Path_Name.Object;
857+ Index : Unit_Index;
858+ Sep_Name : Optional_Name_Type)
859+ is
860+ pragma Unreferenced (Kind);
861+ pragma Unreferenced (View);
862+ pragma Unreferenced (Index);
863+ pragma Unreferenced (Sep_Name);
864+ begin
865+ Self.Project_Predefined_Sources.Include (Path.Virtual_File);
866+ end For_All_Part_Action ;
842867 begin
843868 Self.Project_Predefined_Sources.Clear;
844869
845870 if Self.Project_Tree.Is_Defined
846871 and then Self.Project_Tree.Has_Runtime_Project
847872 then
848- for Source of Self.Project_Tree.Runtime_Project.Sources loop
849- if Source.Language = GPR2.Ada_Language then
850- Self.Project_Predefined_Sources.Include
851- (Source.Path_Name.Virtual_File);
852- end if ;
873+ -- Note that the following loop differs rather subtly from iterating
874+ -- over the units in the runtime view: user projects are allowed to
875+ -- override units from the runtime, and when they do the overridden
876+ -- units should be ignored. We would incorrectly consider them if we
877+ -- just iterated over the units of the runtime view.
878+ for P of Self.Project_Tree.Namespace_Root_Projects loop
879+ for Unit of P.Units (With_Externally_Built => True) loop
880+ if Unit.Owning_View.Is_Runtime then
881+ Unit.For_All_Part (For_All_Part_Action'Access );
882+ end if ;
883+ end loop ;
853884 end loop ;
854885 end if ;
855886 end Update_Project_Predefined_Sources ;
0 commit comments