@@ -27,7 +27,6 @@ with GPR2.Containers;
2727with GPR2.Path_Name ;
2828with GPR2.Project.Attribute ;
2929with GPR2.Project.Attribute_Index ;
30- with GPR2.Project.View.Set ;
3130with GPR2.Build.Source ;
3231with GPR2.Build.Source.Sets ;
3332
@@ -607,61 +606,105 @@ package body LSP.Ada_Contexts is
607606
608607 procedure Update_Source_Files is
609608
609+ procedure Process_Closure
610+ (Root : GPR2.Project.View.Object;
611+ Callback : not null access procedure
612+ (View : GPR2.Project.View.Object));
613+ -- Process the closure of Root with the given callback.
614+ -- Similar to GPR2.Project.View.Closure, but, in addition,
615+ -- when encountering an extending project, consider the
616+ -- project it is extending to be part of the closure.
617+
618+ procedure Add_Sources_From_View (View : GPR2.Project.View.Object);
619+ -- Add the sources from the given view to the context
620+
621+ procedure Add_Dirs_From_View (View : GPR2.Project.View.Object);
622+ -- Add the source directories from the given view to the context
623+
610624 procedure Insert_Source (Source : GPR2.Build.Source.Object);
611625 -- Insert Source in Self.Source_Files
612626
613627 -- -----------------
614628 -- Insert_Source --
615629 -- -----------------
616630
617- procedure Insert_Source (Source : GPR2.Build.Source.Object) is
618- Path : constant Virtual_File := Source.Path_Name.Virtual_File;
631+ procedure Insert_Source (Source : GPR2.Build.Source.Object)
632+ is
633+ Path : constant Virtual_File :=
634+ Source.Path_Name.Virtual_File;
619635 begin
620636 if not Self.Source_Files.Contains (Path) then
621637 Self.Source_Files.Include (Path);
622638 end if ;
623639 end Insert_Source ;
624640
625- begin
626- Self.Source_Files.Clear;
641+ -- -------------------
642+ -- Process_Closure --
643+ -- -------------------
627644
628- for View of Root.Closure (Include_Self => True)
629- when not View.Is_Runtime
630- loop
631- declare
632- Sources : constant GPR2.Build.Source.Sets.Object
633- := View.Sources;
634- use type GPR2.Language_Id;
635- begin
636- for Source of Sources loop
637- if Source.Language = GPR2.Ada_Language then
638- Insert_Source (Source);
639- end if ;
645+ procedure Process_Closure
646+ (Root : GPR2.Project.View.Object;
647+ Callback : not null access procedure
648+ (View : GPR2.Project.View.Object))
649+ is
650+ begin
651+ -- First process the closure of the view
652+ for View of Root.Closure
653+ (Include_Self => True) when not View.Is_Runtime
654+ loop
655+ Callback (View);
656+ end loop ;
657+
658+ -- If we're looking at an extending view, now
659+ -- process the closure of the extended views.
660+ if Root.Is_Extending then
661+ for V of Root.Extended loop
662+ Process_Closure (V, Callback);
640663 end loop ;
641- end ;
642- end loop ;
664+ end if ;
665+ end Process_Closure ;
643666
644- Self.Source_Dirs.Clear;
645- Self.External_Source_Dirs.Clear;
667+ -- -------------------------
668+ -- Add_Sources_From_View --
669+ -- -------------------------
646670
647- declare
648- Views : constant GPR2.Project.View.Set .Object :=
649- Root.Closure (Include_Self => True) ;
671+ procedure Add_Sources_From_View (View : GPR2.Project.View.Object) is
672+ Sources : constant GPR2.Build.Source.Sets .Object := View.Sources;
673+ use type GPR2.Language_Id ;
650674 begin
651- for View of Views
652- when not View.Is_Runtime
653- loop
654- if View.Is_Externally_Built then
655- for Dir of View.Source_Directories loop
656- Self.External_Source_Dirs.Include (Dir.Virtual_File);
657- end loop ;
658- else
659- for Dir of View.Source_Directories loop
660- Self.Source_Dirs.Include (Dir.Virtual_File);
661- end loop ;
675+ for Source of Sources loop
676+ if Source.Language = GPR2.Ada_Language then
677+ Insert_Source (Source);
662678 end if ;
663679 end loop ;
664- end ;
680+ end Add_Sources_From_View ;
681+
682+ -- ----------------------
683+ -- Add_Dirs_From_View --
684+ -- ----------------------
685+
686+ procedure Add_Dirs_From_View (View : GPR2.Project.View.Object) is
687+ begin
688+ if View.Is_Externally_Built then
689+ for Dir of View.Source_Directories loop
690+ Self.External_Source_Dirs.Include (Dir.Virtual_File);
691+ end loop ;
692+ else
693+ for Dir of View.Source_Directories loop
694+ Self.Source_Dirs.Include (Dir.Virtual_File);
695+ end loop ;
696+ end if ;
697+ end Add_Dirs_From_View ;
698+
699+ begin
700+ Self.Source_Files.Clear;
701+
702+ Process_Closure (Root, Add_Sources_From_View'Access );
703+
704+ Self.Source_Dirs.Clear;
705+ Self.External_Source_Dirs.Clear;
706+
707+ Process_Closure (Root, Add_Dirs_From_View'Access );
665708
666709 Self.Extension_Set.Clear;
667710
0 commit comments