Skip to content

Commit 5e62ed2

Browse files
Merge branch 'topic/als.1437.goto_entry_protected_type' into 'master'
Fix Goto Definition for entry in Protected Types Closes #1437 See merge request eng/ide/ada_language_server!1753
2 parents 410891a + a7fa2fb commit 5e62ed2

File tree

5 files changed

+364
-11
lines changed

5 files changed

+364
-11
lines changed

source/ada/lsp-ada_definition.adb

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ package body LSP.Ada_Definition is
122122
Manual_Fallback : Libadalang.Analysis.Defining_Name;
123123
Definition_Node : Libadalang.Analysis.Basic_Decl;
124124
Decl_For_Find_Overrides : Libadalang.Analysis.Basic_Decl;
125-
Entry_Decl_Node : Libadalang.Analysis.Entry_Decl;
126125

127126
Ignore : Boolean;
128127
begin
@@ -186,7 +185,37 @@ package body LSP.Ada_Definition is
186185

187186
-- Search for accept statements only if we are on an entry
188187
if Definition_Node.Kind in Libadalang.Common.Ada_Entry_Decl_Range then
189-
Entry_Decl_Node := Definition_Node.As_Entry_Decl;
188+
declare
189+
Entry_Decl_Node : constant Libadalang.Analysis.Entry_Decl :=
190+
Definition_Node.As_Entry_Decl;
191+
Entry_Parent_Node : constant Libadalang.Analysis.Basic_Decl :=
192+
Entry_Decl_Node.P_Parent_Basic_Decl;
193+
begin
194+
-- P_Accept_Stmts is only valid for entries declared in tasks
195+
if Entry_Parent_Node.Kind in
196+
Libadalang.Common.Ada_Task_Type_Decl_Range
197+
then
198+
for Accept_Node of Entry_Decl_Node.P_Accept_Stmts loop
199+
Self.Parent.Context.Append_Location
200+
(Self.Response,
201+
Self.Filter,
202+
Accept_Node.F_Body_Decl.F_Name);
203+
end loop;
204+
205+
-- Others entries are are handled as simple subprograms
206+
else
207+
declare
208+
Other_Part_For_Decl : constant
209+
Libadalang.Analysis.Basic_Decl :=
210+
Laltools.Common.Find_Next_Part_For_Decl
211+
(Definition_Node, Trace);
212+
begin
213+
if not Other_Part_For_Decl.Is_Null then
214+
Other_Part := Other_Part_For_Decl.P_Defining_Name;
215+
end if;
216+
end;
217+
end if;
218+
end;
190219

191220
elsif Definition_Node.Kind in
192221
Libadalang.Common.Ada_Single_Task_Type_Decl_Range |
@@ -265,15 +294,6 @@ package body LSP.Ada_Definition is
265294
end loop;
266295
end;
267296
end if;
268-
269-
if not Entry_Decl_Node.Is_Null then
270-
for Accept_Node of Entry_Decl_Node.P_Accept_Stmts loop
271-
Self.Parent.Context.Append_Location
272-
(Self.Response,
273-
Self.Filter,
274-
Accept_Node.F_Body_Decl.F_Name);
275-
end loop;
276-
end if;
277297
end Execute_Ada_Request;
278298

279299
end LSP.Ada_Definition;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
with Ada.Text_IO; use Ada.Text_IO;
2+
3+
procedure Show_Protected_Objects_Entries is
4+
5+
protected Obj is
6+
procedure Set (V : Integer);
7+
entry Get (V : out Integer);
8+
private
9+
Local : Integer;
10+
Is_Set : Boolean := False;
11+
end Obj;
12+
13+
protected body Obj is
14+
procedure Set (V : Integer) is
15+
begin
16+
Local := V;
17+
Is_Set := True;
18+
end Set;
19+
20+
entry Get (V : out Integer)
21+
when Is_Set is
22+
-- Entry is blocked until the
23+
-- condition is true. The barrier
24+
-- is evaluated at call of entries
25+
-- and at exits of procedures and
26+
-- entries. The calling task sleeps
27+
-- until the barrier is released.
28+
begin
29+
V := Local;
30+
Is_Set := False;
31+
end Get;
32+
end Obj;
33+
34+
N : Integer := 0;
35+
36+
task T is
37+
entry Seize;
38+
end T;
39+
40+
task body T is
41+
begin
42+
43+
accept Seize;
44+
Put_Line
45+
("Task T will delay for 4 seconds...");
46+
delay 4.0;
47+
48+
accept Seize;
49+
Put_Line
50+
("Task T will set Obj...");
51+
Obj.Set (5);
52+
53+
accept Seize;
54+
Put_Line
55+
("Task T has just set Obj...");
56+
end T;
57+
begin
58+
Put_Line
59+
("Main application will get Obj...");
60+
Obj.Get (N);
61+
62+
Put_Line
63+
("Main application has retrieved Obj...");
64+
Put_Line
65+
("Number is: " & Integer'Image (N));
66+
67+
end Show_Protected_Objects_Entries;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project Test is
2+
end Test;
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
[
2+
{
3+
"comment": [
4+
"Test textDocument/definition on protected type's entry."
5+
]
6+
},
7+
{
8+
"start": {
9+
"cmd": ["${ALS}"]
10+
}
11+
},
12+
{
13+
"send": {
14+
"request": {
15+
"jsonrpc": "2.0",
16+
"id": 1,
17+
"method": "initialize",
18+
"params": {
19+
"rootUri": "$URI{.}",
20+
"capabilities": {}
21+
}
22+
},
23+
"wait": []
24+
}
25+
},
26+
{
27+
"send": {
28+
"request": {
29+
"jsonrpc": "2.0",
30+
"method": "initialized",
31+
"params": {}
32+
},
33+
"wait": []
34+
}
35+
},
36+
{
37+
"send": {
38+
"request": {
39+
"jsonrpc": "2.0",
40+
"method": "textDocument/didOpen",
41+
"params": {
42+
"textDocument": {
43+
"uri": "$URI{show_protected_objects_entries.adb}",
44+
"languageId": "Ada",
45+
"version": 0,
46+
"text": "with Ada.Text_IO; use Ada.Text_IO;\n\nprocedure Show_Protected_Objects_Entries is\n\n protected Obj is\n procedure Set (V : Integer);\n entry Get (V : out Integer);\n private\n Local : Integer;\n Is_Set : Boolean := False;\n end Obj;\n\n protected body Obj is\n procedure Set (V : Integer) is\n begin\n Local := V;\n Is_Set := True;\n end Set;\n\n entry Get (V : out Integer)\n when Is_Set is\n -- Entry is blocked until the\n -- condition is true. The barrier\n -- is evaluated at call of entries\n -- and at exits of procedures and\n -- entries. The calling task sleeps\n -- until the barrier is released.\n begin\n V := Local;\n Is_Set := False;\n end Get;\n end Obj;\n\n N : Integer := 0;\n\n task T is\n entry Seize;\n end T;\n\n task body T is\n begin\n\n accept Seize;\n Put_Line\n (\"Task T will delay for 4 seconds...\");\n delay 4.0;\n\n accept Seize;\n Put_Line\n (\"Task T will set Obj...\");\n Obj.Set (5);\n\n accept Seize;\n Put_Line\n (\"Task T has just set Obj...\");\n end T;\nbegin\n Put_Line\n (\"Main application will get Obj...\");\n Obj.Get (N);\n\n Put_Line\n (\"Main application has retrieved Obj...\");\n Put_Line\n (\"Number is: \" & Integer'Image (N));\n\nend Show_Protected_Objects_Entries;\n"
47+
}
48+
}
49+
},
50+
"wait": []
51+
}
52+
},
53+
{
54+
"send": {
55+
"request": {
56+
"jsonrpc": "2.0",
57+
"id": 6,
58+
"method": "textDocument/definition",
59+
"params": {
60+
"textDocument": {
61+
"uri": "$URI{show_protected_objects_entries.adb}"
62+
},
63+
"position": {
64+
"line": 6,
65+
"character": 12
66+
},
67+
"alsDisplayMethodAncestryOnNavigation": "Usage_And_Abstract_Only"
68+
}
69+
},
70+
"wait": [
71+
{
72+
"id": 6,
73+
"result": {
74+
"uri": "$URI{show_protected_objects_entries.adb}",
75+
"range": {
76+
"start": {
77+
"line": 19,
78+
"character": 12
79+
},
80+
"end": {
81+
"line": 19,
82+
"character": 15
83+
}
84+
}
85+
}
86+
}
87+
]
88+
}
89+
},
90+
{
91+
"send": {
92+
"request": {
93+
"jsonrpc": "2.0",
94+
"id": 9,
95+
"method": "textDocument/definition",
96+
"params": {
97+
"textDocument": {
98+
"uri": "$URI{show_protected_objects_entries.adb}"
99+
},
100+
"position": {
101+
"line": 19,
102+
"character": 12
103+
},
104+
"alsDisplayMethodAncestryOnNavigation": "Usage_And_Abstract_Only"
105+
}
106+
},
107+
"wait": [
108+
{
109+
"id": 9,
110+
"result": {
111+
"uri": "$URI{show_protected_objects_entries.adb}",
112+
"range": {
113+
"start": {
114+
"line": 6,
115+
"character": 12
116+
},
117+
"end": {
118+
"line": 6,
119+
"character": 15
120+
}
121+
}
122+
}
123+
}
124+
]
125+
}
126+
},
127+
{
128+
"send": {
129+
"request": {
130+
"jsonrpc": "2.0",
131+
"id": 12,
132+
"method": "textDocument/definition",
133+
"params": {
134+
"textDocument": {
135+
"uri": "$URI{show_protected_objects_entries.adb}"
136+
},
137+
"position": {
138+
"line": 36,
139+
"character": 12
140+
},
141+
"alsDisplayMethodAncestryOnNavigation": "Usage_And_Abstract_Only"
142+
}
143+
},
144+
"wait": [
145+
{
146+
"id": 12,
147+
"result": [
148+
{
149+
"uri": "$URI{show_protected_objects_entries.adb}",
150+
"range": {
151+
"start": {
152+
"line": 42,
153+
"character": 13
154+
},
155+
"end": {
156+
"line": 42,
157+
"character": 18
158+
}
159+
}
160+
},
161+
{
162+
"uri": "$URI{show_protected_objects_entries.adb}",
163+
"range": {
164+
"start": {
165+
"line": 47,
166+
"character": 13
167+
},
168+
"end": {
169+
"line": 47,
170+
"character": 18
171+
}
172+
}
173+
},
174+
{
175+
"uri": "$URI{show_protected_objects_entries.adb}",
176+
"range": {
177+
"start": {
178+
"line": 52,
179+
"character": 13
180+
},
181+
"end": {
182+
"line": 52,
183+
"character": 18
184+
}
185+
}
186+
}
187+
]
188+
}
189+
]
190+
}
191+
},
192+
{
193+
"send": {
194+
"request": {
195+
"jsonrpc": "2.0",
196+
"id": 18,
197+
"method": "textDocument/definition",
198+
"params": {
199+
"textDocument": {
200+
"uri": "$URI{show_protected_objects_entries.adb}"
201+
},
202+
"position": {
203+
"line": 47,
204+
"character": 13
205+
},
206+
"alsDisplayMethodAncestryOnNavigation": "Usage_And_Abstract_Only"
207+
}
208+
},
209+
"wait": [
210+
{
211+
"id": 18,
212+
"result": {
213+
"uri": "$URI{show_protected_objects_entries.adb}",
214+
"range": {
215+
"start": {
216+
"line": 36,
217+
"character": 12
218+
},
219+
"end": {
220+
"line": 36,
221+
"character": 17
222+
}
223+
}
224+
}
225+
}
226+
]
227+
}
228+
},
229+
{
230+
"send": {
231+
"request": {
232+
"jsonrpc": "2.0",
233+
"method": "textDocument/didClose",
234+
"params": {
235+
"textDocument": {
236+
"uri": "$URI{show_protected_objects_entries.adb}"
237+
}
238+
}
239+
},
240+
"wait": []
241+
}
242+
},
243+
{
244+
"send": {
245+
"request": {
246+
"jsonrpc": "2.0",
247+
"id": 21,
248+
"method": "shutdown"
249+
},
250+
"wait": [
251+
{
252+
"id": 21,
253+
"result": null
254+
}
255+
]
256+
}
257+
},
258+
{
259+
"stop": {
260+
"exit_code": 0
261+
}
262+
}
263+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'definition_protected'

0 commit comments

Comments
 (0)