Skip to content

Commit fd915cc

Browse files
Merge branch 'topic/#1450' into 'master'
Fix als-other-file command for child packages See merge request eng/ide/ada_language_server!1722 (cherry picked from commit 9e0856f) f286899 Fix als-other-file command for child packages Co-authored-by: Anthony Leonardo Gracio <leonardo@adacore.com>
1 parent bd069ad commit fd915cc

File tree

7 files changed

+199
-11
lines changed

7 files changed

+199
-11
lines changed

source/ada/lsp-ada_handlers-other_file_commands.adb

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18+
with GPR2.Build.Unit_Info;
19+
with GPR2.Project.View;
1820
with VSS.JSON.Streams;
1921

2022
with GNATCOLL.VFS; use GNATCOLL.VFS;
@@ -126,20 +128,27 @@ package body LSP.Ada_Handlers.Other_File_Commands is
126128
-- Unit_For_File --
127129
-------------------
128130

129-
function Unit_For_File return GPR2.Build.Compilation_Unit.Object
130-
is
131-
Unit : GPR2.Build.Compilation_Unit.Object;
131+
function Unit_For_File return GPR2.Build.Compilation_Unit.Object is
132132
begin
133-
-- First look in the closure of sources, then in the
134-
-- runtime project.
133+
-- Check in the root project's closure for a visible source
134+
-- corresponding to this file.
135+
-- Not that the root's project closure includes the runtime.
135136
if Handler.Project_Tree.Is_Defined then
136-
Unit := Handler.Project_Tree.Root_Project.Unit (F.Base_Name);
137+
declare
138+
View : constant GPR2.Project.View.Object :=
139+
Handler.Project_Tree.Root_Project;
140+
Unit_Info : constant GPR2.Build.Unit_Info.Object :=
141+
View.Visible_Source (F.Simple_Name).Unit;
142+
Unit : GPR2.Build.Compilation_Unit.Object :=
143+
GPR2.Build.Compilation_Unit.Undefined;
144+
begin
145+
if Unit_Info.Is_Defined then
146+
Unit := View.Namespace_Roots.First_Element.Unit
147+
(Unit_Info.Name);
148+
end if;
137149

138-
if not Unit.Is_Defined then
139-
Unit := Handler.Project_Tree.Runtime_Project.Unit
140-
(F.Base_Name);
141-
end if;
142-
return Unit;
150+
return Unit;
151+
end;
143152
else
144153
return GPR2.Build.Compilation_Unit.Undefined;
145154
end if;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package body A.B is
2+
procedure Proc (X : in out Integer) is
3+
begin
4+
X := X + 2 * X;
5+
6+
Proc (X => X);
7+
end Proc;
8+
end A.B;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package A.B is
2+
procedure Proc (X : in out Integer);
3+
end A.B;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package A with Pure is
2+
end A;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project Default is
2+
end Default;
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
[
2+
{
3+
"comment": "Check that the 'als-other-file' command works fine with child packages"
4+
},
5+
{
6+
"start": {
7+
"cmd": ["${ALS}"]
8+
}
9+
},
10+
{
11+
"send": {
12+
"request": {
13+
"jsonrpc": "2.0",
14+
"id": 0,
15+
"method": "initialize",
16+
"params": {
17+
"processId": 1,
18+
"rootUri": "$URI{.}",
19+
"capabilities": {}
20+
}
21+
},
22+
"wait": [
23+
{
24+
"id": 0,
25+
"result": {
26+
"capabilities": {
27+
"textDocumentSync": 2,
28+
"executeCommandProvider": {
29+
"commands": ["<HAS>", "als-other-file"]
30+
}
31+
}
32+
}
33+
}
34+
]
35+
}
36+
},
37+
{
38+
"send": {
39+
"request": {
40+
"jsonrpc": "2.0",
41+
"method": "workspace/didChangeConfiguration",
42+
"params": {
43+
"settings": {
44+
"ada": {}
45+
}
46+
}
47+
},
48+
"wait": [
49+
{
50+
"jsonrpc": "2.0",
51+
"id": 1,
52+
"method": "window/workDoneProgress/create",
53+
"params": {
54+
"token": "<ANY>"
55+
}
56+
}
57+
]
58+
}
59+
},
60+
{
61+
"send": {
62+
"request": {
63+
"jsonrpc": "2.0",
64+
"method": "textDocument/didOpen",
65+
"params": {
66+
"textDocument": {
67+
"uri": "$URI{a-b.ads}",
68+
"languageId": "ada",
69+
"version": 1,
70+
"text": "package A.B is\n procedure Proc (X : in out Integer);\nend A.B;\n"
71+
}
72+
}
73+
},
74+
"wait": []
75+
}
76+
},
77+
{
78+
"send": {
79+
"request": {
80+
"jsonrpc": "2.0",
81+
"id": "sw1",
82+
"method": "workspace/executeCommand",
83+
"params": {
84+
"command": "als-other-file",
85+
"arguments": [
86+
{
87+
"uri": "$URI{a-b.ads}"
88+
}
89+
]
90+
}
91+
},
92+
"wait": [
93+
{
94+
"jsonrpc": "2.0",
95+
"method": "window/showDocument",
96+
"params": {
97+
"uri": "$URI{a-b.adb}",
98+
"takeFocus": true
99+
}
100+
},
101+
{
102+
"jsonrpc": "2.0",
103+
"id": "sw1",
104+
"result": null
105+
}
106+
]
107+
}
108+
},
109+
{
110+
"send": {
111+
"request": {
112+
"jsonrpc": "2.0",
113+
"id": "sw2",
114+
"method": "workspace/executeCommand",
115+
"params": {
116+
"command": "als-other-file",
117+
"arguments": [
118+
{
119+
"uri": "$URI{a-b.adb}"
120+
}
121+
]
122+
}
123+
},
124+
"wait": [
125+
{
126+
"jsonrpc": "2.0",
127+
"method": "window/showDocument",
128+
"params": {
129+
"uri": "$URI{a-b.ads}",
130+
"takeFocus": true
131+
}
132+
},
133+
{
134+
"jsonrpc": "2.0",
135+
"id": "sw2",
136+
"result": null
137+
}
138+
]
139+
}
140+
},
141+
{
142+
"send": {
143+
"request": {
144+
"jsonrpc": "2.0",
145+
"id": "shutdown",
146+
"method": "shutdown",
147+
"params": null
148+
},
149+
"wait": [{ "id": "shutdown", "result": null }]
150+
}
151+
},
152+
{
153+
"send": {
154+
"request": { "jsonrpc": "2.0", "method": "exit" },
155+
"wait": []
156+
}
157+
},
158+
{
159+
"stop": {
160+
"exit_code": 0
161+
}
162+
}
163+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'commands.other_file'

0 commit comments

Comments
 (0)