Skip to content

Commit 753d5f6

Browse files
U622-021: Fix bug in lazy completion and add a test
. Some completion items (predefined keywords, attributes...) already have their doc pre-computed, so don't try to resolve it lazily. . Add an automatic test.
1 parent d34f141 commit 753d5f6

File tree

6 files changed

+374
-4
lines changed

6 files changed

+374
-4
lines changed

source/ada/lsp-ada_handlers.adb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3937,15 +3937,26 @@ package body LSP.Ada_Handlers is
39373937
Request.params;
39383938
Response : LSP.Messages.Server_Responses.CompletionItemResolve_Response
39393939
(Is_Error => False);
3940-
C : constant Context_Access :=
3941-
Self.Contexts.Get_Best_Context (Item.data.Value.uri);
3942-
Node : Libadalang.Analysis.Ada_Node := Get_Node_At
3940+
C : Context_Access;
3941+
Node : Libadalang.Analysis.Ada_Node;
3942+
begin
3943+
-- Return immediately if we don't have data that allows us to compute
3944+
-- additional information for the given item.
3945+
-- This is the case when all the completion item's fields have already
3946+
-- been computed.
3947+
if not Item.data.Is_Set then
3948+
Response.result := Item;
3949+
return Response;
3950+
end if;
3951+
3952+
C := Self.Contexts.Get_Best_Context (Item.data.Value.uri);
3953+
Node := Get_Node_At
39433954
(Self => C.all,
39443955
Document => null,
39453956
Position => LSP.Messages.TextDocumentPositionParams'
39463957
(textDocument => (uri => Item.data.Value.uri),
39473958
position => Item.data.Value.span.first));
3948-
begin
3959+
39493960
-- Retrieve the Basic_Decl from the completion item's SLOC
39503961
while not Node.Is_Null
39513962
and then Node.Kind not in Libadalang.Common.Ada_Basic_Decl
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
with Test; use Test;
2+
3+
procedure Main is
4+
begin
5+
Selec
6+
end Main;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package Test is
2+
3+
procedure Select_Some is null;
4+
-- This a very useful comment.
5+
6+
end Test;
Lines changed: 344 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,344 @@
1+
[
2+
{
3+
"comment": [
4+
"This test checks that the completionItems' 'documentation' and ",
5+
"'detail' fields are computed lazily via the completionItem/resolve ",
6+
"request, and not directly when seinding the results in response ",
7+
"to 'textDocument/completion' request."
8+
]
9+
},
10+
{
11+
"start": {
12+
"cmd": [
13+
"${ALS}"
14+
]
15+
}
16+
},
17+
{
18+
"send": {
19+
"request": {
20+
"jsonrpc": "2.0",
21+
"id": 1,
22+
"method": "initialize",
23+
"params": {
24+
"processId": 199714,
25+
"rootUri": "$URI{.}",
26+
"capabilities": {
27+
"workspace": {
28+
"applyEdit": true
29+
},
30+
"textDocument": {
31+
"completion": {
32+
"completionItem": {
33+
"snippetSupport": true,
34+
"documentationFormat": [
35+
"markdown",
36+
"plaintext"
37+
],
38+
"resolveSupport":{
39+
"properties":[
40+
"documentation",
41+
"detail"]}
42+
}
43+
}
44+
},
45+
"window": {
46+
"workDoneProgress": true
47+
}
48+
}
49+
}
50+
},
51+
"wait": [
52+
{
53+
"jsonrpc": "2.0",
54+
"id": 1,
55+
"result": {
56+
"capabilities": {
57+
"textDocumentSync": 2,
58+
"completionProvider": {
59+
"triggerCharacters": [
60+
".",
61+
"("
62+
],
63+
"resolveProvider": true
64+
}
65+
}
66+
}
67+
}
68+
]
69+
}
70+
},
71+
{
72+
"send": {
73+
"request": {
74+
"jsonrpc": "2.0",
75+
"method": "initialized",
76+
"params": {}
77+
},
78+
"wait": []
79+
}
80+
},
81+
{
82+
"send": {
83+
"request": {
84+
"jsonrpc": "2.0",
85+
"method": "workspace/didChangeConfiguration",
86+
"params": {
87+
"settings": {
88+
"ada": {
89+
"trace": {
90+
"server": "verbose"
91+
},
92+
"projectFile": "",
93+
"scenarioVariables": {},
94+
"defaultCharset": "iso-8859-1",
95+
"displayMethodAncestryOnNavigation": "usage_and_abstract_only",
96+
"enableDiagnostics": true,
97+
"renameInComments": false
98+
}
99+
}
100+
}
101+
},
102+
"wait": []
103+
}
104+
},
105+
{
106+
"send": {
107+
"request": {
108+
"jsonrpc": "2.0",
109+
"method": "textDocument/didOpen",
110+
"params": {
111+
"textDocument": {
112+
"uri": "$URI{main.adb}",
113+
"languageId": "ada",
114+
"version": 1,
115+
"text": "with Test; use Test;\n\nprocedure Main is\nbegin\n Selec\nend Main;\n"
116+
}
117+
}
118+
},
119+
"wait": []
120+
}
121+
},
122+
{
123+
"send": {
124+
"request": {
125+
"jsonrpc": "2.0",
126+
"id": 18,
127+
"method": "textDocument/completion",
128+
"params": {
129+
"textDocument": {
130+
"uri": "$URI{main.adb}"
131+
},
132+
"position": {
133+
"line": 4,
134+
"character": 8
135+
},
136+
"context": {
137+
"triggerKind": 1
138+
}
139+
}
140+
},
141+
"wait": [
142+
{
143+
"id": 18,
144+
"result": {
145+
"isIncomplete": false,
146+
"items": [
147+
{
148+
"label": "select",
149+
"kind": 14,
150+
"insertText": "select",
151+
"insertTextFormat": 1,
152+
"additionalTextEdits": []
153+
},
154+
{
155+
"label": "Select_Some",
156+
"kind": 3,
157+
"sortText": "1Select_Some",
158+
"additionalTextEdits": [],
159+
"data": {
160+
"uri": "$URI{test.ads}",
161+
"range": {
162+
"start": {
163+
"line": 2,
164+
"character": 3
165+
},
166+
"end": {
167+
"line": 2,
168+
"character": 33
169+
}
170+
}
171+
}
172+
}
173+
]
174+
}
175+
}
176+
]
177+
}
178+
},
179+
{
180+
"send": {
181+
"request": {
182+
"jsonrpc": "2.0",
183+
"id": 19,
184+
"method": "completionItem/resolve",
185+
"params": {
186+
"label": "Select_Some",
187+
"insertTextFormat": 1,
188+
"kind": 3,
189+
"sortText": "1Select_Some",
190+
"additionalTextEdits": [],
191+
"data": {
192+
"uri": "$URI{test.ads}",
193+
"range": {
194+
"start": {
195+
"line": 2,
196+
"character": 3
197+
},
198+
"end": {
199+
"line": 2,
200+
"character": 33
201+
}
202+
}
203+
}
204+
}
205+
},
206+
"wait": [
207+
{
208+
"id": 19,
209+
"result": {
210+
"label": "Select_Some",
211+
"kind": 3,
212+
"detail": "procedure Select_Some is null",
213+
"documentation": "at test.ads (3:4)\n\nThis a very useful comment.",
214+
"sortText": "1Select_Some",
215+
"insertTextFormat": 1,
216+
"additionalTextEdits": [],
217+
"data": {
218+
"uri": "$URI{test.ads}",
219+
"range": {
220+
"start": {
221+
"line": 2,
222+
"character": 3
223+
},
224+
"end": {
225+
"line": 2,
226+
"character": 33
227+
}
228+
}
229+
}
230+
}
231+
}
232+
]
233+
}
234+
},
235+
{
236+
"send": {
237+
"request": {
238+
"jsonrpc": "2.0",
239+
"id": 20,
240+
"method": "textDocument/codeAction",
241+
"params": {
242+
"textDocument": {
243+
"uri": "$URI{main.adb}"
244+
},
245+
"range": {
246+
"start": {
247+
"line": 4,
248+
"character": 8
249+
},
250+
"end": {
251+
"line": 4,
252+
"character": 8
253+
}
254+
},
255+
"context": {
256+
"diagnostics": []
257+
}
258+
}
259+
},
260+
"wait": [
261+
{
262+
"id": 20,
263+
"result": []
264+
}
265+
]
266+
}
267+
},
268+
{
269+
"send": {
270+
"request": {
271+
"jsonrpc": "2.0",
272+
"id": 21,
273+
"method": "textDocument/codeAction",
274+
"params": {
275+
"textDocument": {
276+
"uri": "$URI{main.adb}"
277+
},
278+
"range": {
279+
"start": {
280+
"line": 4,
281+
"character": 8
282+
},
283+
"end": {
284+
"line": 4,
285+
"character": 8
286+
}
287+
},
288+
"context": {
289+
"diagnostics": []
290+
}
291+
}
292+
},
293+
"wait": []
294+
}
295+
},
296+
{
297+
"send": {
298+
"request": {
299+
"jsonrpc": "2.0",
300+
"id": 23,
301+
"method": "completionItem/resolve",
302+
"params": {
303+
"label": "select",
304+
"insertTextFormat": 1,
305+
"insertText": "select",
306+
"kind": 14,
307+
"additionalTextEdits": []
308+
}
309+
},
310+
"wait": [
311+
{
312+
"id": 23,
313+
"result": {
314+
"label": "select",
315+
"kind": 14,
316+
"insertText": "select",
317+
"insertTextFormat": 1,
318+
"additionalTextEdits": []
319+
}
320+
}
321+
]
322+
}
323+
},
324+
{
325+
"send": {
326+
"request": {
327+
"jsonrpc": "2.0",
328+
"id": 24,
329+
"method": "shutdown"
330+
},
331+
"wait": [
332+
{
333+
"id": 24,
334+
"result": null
335+
}
336+
]
337+
}
338+
},
339+
{
340+
"stop": {
341+
"exit_code": 0
342+
}
343+
}
344+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'completion.lazy_computation'

0 commit comments

Comments
 (0)