Skip to content

Commit 2c33d7a

Browse files
Handle aggregate projects in 'als-mains' command
By grouping all the mains of each aggregated project together. For eng/ide/ada_language_server#1637
1 parent 54ecf2e commit 2c33d7a

File tree

9 files changed

+171
-16
lines changed

9 files changed

+171
-16
lines changed

source/ada/lsp-ada_handlers-mains_commands.adb

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
with Ada.Containers.Indefinite_Vectors;
1919
with GPR2.Project.View;
2020

21+
with GPR2.Project.View.Set;
2122
with VSS.JSON.Streams;
2223

2324
package 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
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
aggregate project Aggr is
2+
for Project_Files use ("project_1.gpr", "project_2.gpr");
3+
end Aggr;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Main_1 is
2+
begin
3+
null;
4+
end Main_1;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Main_2 is
2+
begin
3+
null;
4+
end Main_2;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Main_3 is
2+
begin
3+
null;
4+
end Main_3;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project Project_1 is
2+
for Main use ("main_1.adb", "main_2.adb");
3+
end Project_1;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project Project_2 is
2+
for Main use ("main_3.adb");
3+
end Project_2;
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
[
2+
{
3+
"comment": [
4+
"Check als-mains command for aggregate projects. ",
5+
"The result should combine all the mains of all the projects being aggregated."
6+
]
7+
},
8+
{
9+
"start": {
10+
"cmd": ["${ALS}"]
11+
}
12+
},
13+
{
14+
"send": {
15+
"request": {
16+
"jsonrpc": "2.0",
17+
"id": 0,
18+
"method": "initialize",
19+
"params": {
20+
"processId": 1,
21+
"rootUri": "$URI{.}",
22+
"capabilities": {}
23+
}
24+
},
25+
"wait": [
26+
{
27+
"id": 0,
28+
"result": {
29+
"capabilities": {
30+
"textDocumentSync": 2,
31+
"executeCommandProvider": {
32+
"commands": ["<HAS>", "als-mains"]
33+
}
34+
}
35+
}
36+
}
37+
]
38+
}
39+
},
40+
{
41+
"send": {
42+
"request": {
43+
"jsonrpc": "2.0",
44+
"method": "workspace/didChangeConfiguration",
45+
"params": {
46+
"settings": {
47+
"ada": {
48+
"projectFile": "$URI{aggr.gpr}"
49+
}
50+
}
51+
}
52+
},
53+
"wait": [
54+
{
55+
"jsonrpc": "2.0",
56+
"id": 1,
57+
"method": "window/workDoneProgress/create",
58+
"params": {
59+
"token": "<ANY>"
60+
}
61+
}
62+
]
63+
}
64+
},
65+
{
66+
"send": {
67+
"request": {
68+
"jsonrpc": "2.0",
69+
"id": "sw1",
70+
"method": "workspace/executeCommand",
71+
"params": {
72+
"command": "als-mains"
73+
}
74+
},
75+
"wait": [
76+
{
77+
"jsonrpc": "2.0",
78+
"id": "sw1",
79+
"result": [
80+
"$FILE{main_1.adb}",
81+
"$FILE{main_2.adb}",
82+
"$FILE{main_3.adb}"
83+
]
84+
}
85+
]
86+
}
87+
},
88+
{
89+
"send": {
90+
"request": {
91+
"jsonrpc": "2.0",
92+
"id": "shutdown",
93+
"method": "shutdown",
94+
"params": null
95+
},
96+
"wait": [{ "id": "shutdown", "result": null }]
97+
}
98+
},
99+
{
100+
"send": {
101+
"request": { "jsonrpc": "2.0", "method": "exit" },
102+
"wait": []
103+
}
104+
},
105+
{
106+
"stop": {
107+
"exit_code": 0
108+
}
109+
}
110+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'commands.mains.aggregate'

0 commit comments

Comments
 (0)