Skip to content

Commit 0bcd113

Browse files
V705-026: Compute predefined types' completion doc immediately
When computing completion items' details, compute the documentation immediately for predefined types (e.g: Integer) since the standard package does not correspond to any actual URI. This fixes an exception on the completionItem/resolve request, where we are trying to retrieve a node from an URI and a SLOC which does not actually exist. Add an automatic test.
1 parent cf9783f commit 0bcd113

File tree

5 files changed

+333
-2
lines changed

5 files changed

+333
-2
lines changed

source/ada/lsp-ada_documents.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,8 +2074,8 @@ package body LSP.Ada_Documents is
20742074
begin
20752075
-- Compute the 'documentation' and 'detail' fields immediately if
20762076
-- requested (i.e: when the client does not support lazy computation
2077-
-- for these fields).
2078-
if Compute_Doc_And_Details then
2077+
-- for these fields or if we are dealing with predefined types).
2078+
if Compute_Doc_And_Details or else LSP.Lal_Utils.Is_Synthetic (BD) then
20792079
Item.detail := (True, LSP.Lal_Utils.Compute_Completion_Detail (BD));
20802080

20812081
-- Property_Errors can occur when calling
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
procedure Main is
2+
A : Int
3+
begin
4+
null;
5+
end Main;
Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
[
2+
{
3+
"comment": [
4+
"This test checks that the completionItem/resolve request",
5+
"does not fail on predefined types defined in the standard ",
6+
"package"
7+
]
8+
},
9+
{
10+
"start": {
11+
"cmd": [
12+
"${ALS}"
13+
]
14+
}
15+
},
16+
{
17+
"send": {
18+
"request": {
19+
"jsonrpc": "2.0",
20+
"id": 1,
21+
"method": "initialize",
22+
"params": {
23+
"processId": 422450,
24+
"rootUri": "$URI{.}",
25+
"capabilities": {
26+
"workspace": {
27+
"applyEdit": true,
28+
"workspaceEdit": {
29+
"documentChanges": true,
30+
"resourceOperations": [
31+
"rename"
32+
]
33+
}
34+
},
35+
"textDocument": {
36+
"synchronization": {},
37+
"completion": {
38+
"dynamicRegistration": true,
39+
"completionItem": {
40+
"snippetSupport": false,
41+
"documentationFormat": [
42+
"plaintext",
43+
"markdown"
44+
],
45+
"resolveSupport": {
46+
"properties": [
47+
"detail",
48+
"documentation"
49+
]
50+
}
51+
}
52+
},
53+
"hover": {},
54+
"signatureHelp": {},
55+
"declaration": {},
56+
"definition": {},
57+
"typeDefinition": {},
58+
"implementation": {},
59+
"documentSymbol": {
60+
"hierarchicalDocumentSymbolSupport": true
61+
},
62+
"formatting": {
63+
"dynamicRegistration": false
64+
},
65+
"rangeFormatting": {
66+
"dynamicRegistration": false
67+
},
68+
"onTypeFormatting": {
69+
"dynamicRegistration": false
70+
},
71+
"foldingRange": {
72+
"lineFoldingOnly": true
73+
}
74+
}
75+
}
76+
}
77+
},
78+
"wait": [
79+
{
80+
"id": 1,
81+
"result": {
82+
"capabilities": {
83+
"textDocumentSync": 2,
84+
"completionProvider": {
85+
"triggerCharacters": [
86+
".",
87+
",",
88+
"'",
89+
"("
90+
],
91+
"resolveProvider": true
92+
},
93+
"hoverProvider": true,
94+
"signatureHelpProvider": {
95+
"triggerCharacters": [
96+
",",
97+
"("
98+
],
99+
"retriggerCharacters": [
100+
"\b"
101+
]
102+
},
103+
"declarationProvider": true,
104+
"definitionProvider": true,
105+
"typeDefinitionProvider": true,
106+
"implementationProvider": true,
107+
"referencesProvider": true,
108+
"documentHighlightProvider": true,
109+
"documentSymbolProvider": true,
110+
"codeActionProvider": {},
111+
"documentFormattingProvider": true,
112+
"renameProvider": {},
113+
"foldingRangeProvider": true,
114+
"executeCommandProvider": {
115+
"commands": [
116+
"als-other-file",
117+
"als-named-parameters",
118+
"als-refactor-imports",
119+
"als-suppress-separate",
120+
"als-refactor-extract-subprogram",
121+
"als-refactor-pull_up_declaration",
122+
"als-refactor-add-parameters",
123+
"als-refactor-remove-parameters",
124+
"als-refactor-move-parameter",
125+
"als-refactor-change-parameter-mode",
126+
"als-refactor-change_parameters_type",
127+
"als-refactor-change_parameters_default_value"
128+
]
129+
},
130+
"workspaceSymbolProvider": true,
131+
"callHierarchyProvider": {},
132+
"alsShowDepsProvider": true,
133+
"alsReferenceKinds": [
134+
"reference",
135+
"access",
136+
"write",
137+
"call",
138+
"dispatching call",
139+
"parent",
140+
"child",
141+
"overriding"
142+
],
143+
"alsCheckSyntaxProvider": true
144+
}
145+
}
146+
}
147+
]
148+
}
149+
},
150+
{
151+
"send": {
152+
"request": {
153+
"jsonrpc": "2.0",
154+
"method": "initialized"
155+
},
156+
"wait": []
157+
}
158+
},
159+
{
160+
"send": {
161+
"request": {
162+
"jsonrpc": "2.0",
163+
"method": "workspace/didChangeConfiguration",
164+
"params": {
165+
"settings": {
166+
"ada": {
167+
"scenarioVariables": {},
168+
"defaultCharset": "ISO-8859-1",
169+
"enableDiagnostics": false,
170+
"followSymlinks": false,
171+
"documentationStyle": "gnat",
172+
"foldComments": false
173+
}
174+
}
175+
}
176+
},
177+
"wait": []
178+
}
179+
},
180+
{
181+
"send": {
182+
"request": {
183+
"jsonrpc": "2.0",
184+
"method": "textDocument/didOpen",
185+
"params": {
186+
"textDocument": {
187+
"uri": "$URI{main.adb}",
188+
"languageId": "Ada",
189+
"version": 0,
190+
"text": "procedure Main is\n A : Int\nbegin\n null;\nend Main;\n"
191+
}
192+
}
193+
},
194+
"wait": []
195+
}
196+
},
197+
{
198+
"send": {
199+
"request": {
200+
"jsonrpc": "2.0",
201+
"method": "textDocument/didChange",
202+
"params": {
203+
"textDocument": {
204+
"uri": "$URI{main.adb}",
205+
"version": 1
206+
},
207+
"contentChanges": [
208+
{
209+
"range": {
210+
"start": {
211+
"line": 1,
212+
"character": 10
213+
},
214+
"end": {
215+
"line": 1,
216+
"character": 10
217+
}
218+
},
219+
"text": "e"
220+
}
221+
]
222+
}
223+
},
224+
"wait": []
225+
}
226+
},
227+
{
228+
"send": {
229+
"request": {
230+
"jsonrpc": "2.0",
231+
"id": 5,
232+
"method": "textDocument/completion",
233+
"params": {
234+
"textDocument": {
235+
"uri": "$URI{main.adb}"
236+
},
237+
"position": {
238+
"line": 1,
239+
"character": 11
240+
},
241+
"context": {
242+
"triggerKind": 1
243+
}
244+
}
245+
},
246+
"wait": [
247+
{
248+
"id": 5,
249+
"result": {
250+
"isIncomplete": false,
251+
"items": [
252+
{
253+
"label": "interface",
254+
"kind": 14,
255+
"insertText": "interface",
256+
"insertTextFormat": 1,
257+
"additionalTextEdits": []
258+
},
259+
{
260+
"label": "Integer",
261+
"kind": 7,
262+
"detail": "type Integer is range -(2 ** 31) .. +(2 ** 31 - 1);",
263+
"documentation": "at __standard (4:3)",
264+
"sortText": "000&2Integer",
265+
"additionalTextEdits": []
266+
}
267+
]
268+
}
269+
}
270+
]
271+
}
272+
},
273+
{
274+
"send": {
275+
"request": {
276+
"jsonrpc": "2.0",
277+
"id": 9,
278+
"method": "completionItem/resolve",
279+
"params": {
280+
"label": "Integer",
281+
"kind": 7,
282+
"detail": "type Integer is range -(2 ** 31) .. +(2 ** 31 - 1);",
283+
"documentation": "at __standard (4:3)",
284+
"sortText": "000&2Integer",
285+
"additionalTextEdits": []
286+
}
287+
},
288+
"wait": [
289+
{
290+
"id": 9,
291+
"result": {
292+
"label": "Integer",
293+
"kind": 7,
294+
"detail": "type Integer is range -(2 ** 31) .. +(2 ** 31 - 1);",
295+
"documentation": "at __standard (4:3)",
296+
"sortText": "000&2Integer",
297+
"additionalTextEdits": []
298+
}
299+
}
300+
]
301+
}
302+
},
303+
{
304+
"send": {
305+
"request": {
306+
"jsonrpc": "2.0",
307+
"id": 10,
308+
"method": "shutdown"
309+
},
310+
"wait": [
311+
{
312+
"id": 10,
313+
"result": null
314+
}
315+
]
316+
}
317+
},
318+
{
319+
"stop": {
320+
"exit_code": 0
321+
}
322+
}
323+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'V705-026.completion.predefined_types'

0 commit comments

Comments
 (0)