1818with Ada.Containers.Indefinite_Vectors ;
1919with GPR2.Project.View ;
2020
21+ with GPR2.Project.View.Set ;
2122with VSS.JSON.Streams ;
2223
2324package body LSP.Ada_Handlers.Mains_Commands is
@@ -47,6 +48,9 @@ package body LSP.Ada_Handlers.Mains_Commands is
4748 Response : in out LSP.Structures.LSPAny_Or_Null;
4849 Error : in out LSP.Errors.ResponseError_Optional)
4950 is
51+ function Get_Main_Paths
52+ (Views : GPR2.Project.View.Set.Object) return Main_Vectors.Vector;
53+
5054 procedure Append (Item : VSS.JSON.Streams.JSON_Stream_Element);
5155
5256 -- ----------
@@ -58,28 +62,47 @@ package body LSP.Ada_Handlers.Mains_Commands is
5862 Response.Value.Append (Item);
5963 end Append ;
6064
61- Element : GPR2.Project.View.Object;
65+ -- ------------------
66+ -- Get_Main_Paths --
67+ -- ------------------
68+
69+ function Get_Main_Paths
70+ (Views : GPR2.Project.View.Set.Object) return Main_Vectors.Vector
71+ is
72+ Main_Paths : Main_Vectors.Vector;
73+ begin
74+ for View of Views loop
75+ if View.Has_Mains then
76+ for Main of View.Mains loop
77+ declare
78+ Main_Path : constant String := String (Main.Source.Value);
79+ begin
80+ -- Avoid duplicates coming from GPR2
81+ -- Workaround for eng/ide/gpr-issues#417
82+ if not Main_Paths.Contains (Main_Path) then
83+ Main_Paths.Append (Main_Path);
84+ end if ;
85+ end ;
86+ end loop ;
87+ end if ;
88+ end loop ;
89+
90+ return Main_Paths;
91+ end Get_Main_Paths ;
92+
93+ Views : GPR2.Project.View.Set.Object;
6294 Main_Paths : Main_Vectors.Vector;
6395 begin
6496 Response := (Is_Null => False, Value => <>);
6597 Append ((Kind => VSS.JSON.Streams.Start_Array));
6698
99+ -- If the project was correctly loaded, iterate over each
100+ -- subtree to get their list of mains.
101+ -- This is needed to handle aggregate projects: we want to
102+ -- combine the mains of each aggregated project in this case.
67103 if Handler.Project_Tree.Is_Defined then
68- Element := Handler.Project_Tree.Root_Project;
69-
70- if Element.Has_Mains then
71- for Main of Element.Mains loop
72- declare
73- Main_Path : constant String := String (Main.Source.Value);
74- begin
75- -- Avoid duplicates coming from GPR2
76- -- Workaround for eng/ide/gpr-issues#417
77- if not Main_Paths.Contains (Main_Path) then
78- Main_Paths.Append (Main_Path);
79- end if ;
80- end ;
81- end loop ;
82- end if ;
104+ Views := Handler.Project_Tree.Namespace_Root_Projects;
105+ Main_Paths := Get_Main_Paths (Views);
83106 end if ;
84107
85108 for Main_Path of Main_Paths loop
0 commit comments