Skip to content

Commit c3a6032

Browse files
thvnxsetton
authored andcommitted
Do not call p_canonical_type for aggregate completion
This patch removes the call to `p_canonical_type` when looking for aggregate completions. This call seems useless and can leads to a property error exception when an incomplete type is involved in the completion. TN: V225-032
1 parent 4b5ec95 commit c3a6032

File tree

5 files changed

+277
-5
lines changed

5 files changed

+277
-5
lines changed

source/ada/lsp-ada_completions-aggregates.adb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ package body LSP.Ada_Completions.Aggregates is
4343
use LSP.Messages;
4444

4545
Expr_Type : constant Base_Type_Decl := Node.P_Expression_Type;
46-
Aggr_Type : constant Base_Type_Decl :=
47-
(if not Expr_Type.Is_Null then
48-
Expr_Type.P_Canonical_Type
49-
else
50-
No_Base_Type_Decl);
46+
Aggr_Type : constant Base_Type_Decl :=
47+
(if Expr_Type.Is_Null then No_Base_Type_Decl else Expr_Type);
48+
5149
Use_Named_Notation : Boolean := False;
5250

5351
function Get_Snippet_For_Component
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project Default is
2+
3+
package Compiler is
4+
for Switches ("Ada") use ("-g", "-O2");
5+
end Compiler;
6+
7+
for Main use ("main.adb") & project'Main;
8+
9+
end Default;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
procedure Main is
2+
3+
type Cell;
4+
type Link is access Cell;
5+
6+
type Cell is
7+
record
8+
Value : Integer;
9+
Succ : Link;
10+
Pred : Link;
11+
end record;
12+
13+
Head : Link := new Cell'(
14+
15+
begin
16+
null;
17+
end Main;
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
[
2+
{
3+
"comment": [
4+
"This test checks that aggregate completion works fine when ",
5+
"an incomplete type is involved in the aggregate declaration"
6+
]
7+
},
8+
{
9+
"start": {
10+
"cmd": [
11+
"${ALS}"
12+
]
13+
}
14+
},
15+
{
16+
"send": {
17+
"request": {
18+
"params": {
19+
"processId": 31570,
20+
"capabilities": {
21+
"textDocument": {
22+
"completion": {
23+
"completionItem": {
24+
"documentationFormat": [
25+
"plaintext",
26+
"markdown"
27+
],
28+
"snippetSupport": true
29+
},
30+
"dynamicRegistration": true
31+
},
32+
"definition": {},
33+
"hover": {},
34+
"formatting": {
35+
"dynamicRegistration": true
36+
},
37+
"implementation": {},
38+
"codeLens": {},
39+
"typeDefinition": {},
40+
"selectionRange": {},
41+
"documentHighlight": {},
42+
"documentSymbol": {
43+
"hierarchicalDocumentSymbolSupport": true
44+
},
45+
"synchronization": {},
46+
"references": {},
47+
"rangeFormatting": {},
48+
"onTypeFormatting": {},
49+
"declaration": {},
50+
"foldingRange": {
51+
"lineFoldingOnly": true
52+
},
53+
"colorProvider": {}
54+
},
55+
"workspace": {
56+
"applyEdit": true,
57+
"executeCommand": {},
58+
"didChangeWatchedFiles": {},
59+
"workspaceEdit": {},
60+
"didChangeConfiguration": {}
61+
}
62+
},
63+
"rootUri": "$URI{.}"
64+
},
65+
"jsonrpc": "2.0",
66+
"id": 1,
67+
"method": "initialize"
68+
},
69+
"wait": [
70+
{
71+
"jsonrpc": "2.0",
72+
"id": 1,
73+
"result": {
74+
"capabilities": {
75+
"textDocumentSync": 2,
76+
"completionProvider": {
77+
"triggerCharacters": [
78+
".",
79+
",",
80+
"'",
81+
"("
82+
],
83+
"resolveProvider": true
84+
},
85+
"hoverProvider": true,
86+
"declarationProvider": true,
87+
"definitionProvider": true,
88+
"typeDefinitionProvider": true,
89+
"implementationProvider": true,
90+
"referencesProvider": true,
91+
"codeActionProvider": {
92+
},
93+
"renameProvider": {
94+
},
95+
"foldingRangeProvider": true,
96+
"executeCommandProvider": {},
97+
"alsReferenceKinds": [
98+
"reference",
99+
"access",
100+
"write",
101+
"call",
102+
"dispatching call",
103+
"parent",
104+
"child",
105+
"overriding"
106+
]
107+
}
108+
}
109+
}
110+
]
111+
}
112+
},
113+
{
114+
"send": {
115+
"request": {
116+
"jsonrpc": "2.0",
117+
"method": "initialized"
118+
},
119+
"wait": []
120+
}
121+
},
122+
{
123+
"send": {
124+
"request": {
125+
"params": {
126+
"settings": {
127+
"ada": {
128+
"scenarioVariables": {},
129+
"enableDiagnostics": false,
130+
"defaultCharset": "ISO-8859-1"
131+
}
132+
}
133+
},
134+
"jsonrpc": "2.0",
135+
"method": "workspace/didChangeConfiguration"
136+
},
137+
"wait": []
138+
}
139+
},
140+
{
141+
"send": {
142+
"request": {
143+
"params": {
144+
"textDocument": {
145+
"text": "procedure Main is\n\n type Cell;\n type Link is access Cell;\n\n type Cell is\n record\n Value : Integer;\n Succ : Link;\n Pred : Link;\n end record;\n\n Head : Link := new Cell'\n\nbegin\n null;\nend Main;\n",
146+
"version": 0,
147+
"uri": "$URI{main.adb}",
148+
"languageId": "Ada"
149+
}
150+
},
151+
"jsonrpc": "2.0",
152+
"method": "textDocument/didOpen"
153+
},
154+
"wait": []
155+
}
156+
},
157+
{
158+
"send": {
159+
"request": {
160+
"params": {
161+
"contentChanges": [
162+
{
163+
"text": "procedure Main is\n\n type Cell;\n type Link is access Cell;\n\n type Cell is\n record\n Value : Integer;\n Succ : Link;\n Pred : Link;\n end record;\n\n Head : Link := new Cell'(\n\nbegin\n null;\nend Main;\n"
164+
}
165+
],
166+
"textDocument": {
167+
"version": 1,
168+
"uri": "$URI{main.adb}"
169+
}
170+
},
171+
"jsonrpc": "2.0",
172+
"method": "textDocument/didChange"
173+
},
174+
"wait": []
175+
}
176+
},
177+
{
178+
"send": {
179+
"request": {
180+
"params": {
181+
"position": {
182+
"line": 13,
183+
"character": 29
184+
},
185+
"textDocument": {
186+
"uri": "$URI{main.adb}"
187+
}
188+
},
189+
"jsonrpc": "2.0",
190+
"id": 3,
191+
"method": "textDocument/completion"
192+
},
193+
"wait": [
194+
{
195+
"id": 3,
196+
"result": {
197+
"isIncomplete": false,
198+
"items": [
199+
{
200+
"insertText": "Value => ${1:Integer}, Succ => ${2:Link}, Pred => ${3:Link})$0",
201+
"kind": 15,
202+
"detail": "type Cell is\nrecord\n Value : Integer;\n Succ : Link;\n Pred : Link;\nend record;",
203+
"label": "Aggregate for Cell",
204+
"additionalTextEdits": [],
205+
"insertTextFormat": 2
206+
}
207+
]
208+
}
209+
}
210+
]
211+
}
212+
},
213+
{
214+
"send": {
215+
"request": {
216+
"params": {
217+
"textDocument": {
218+
"uri": "$URI{main.adb}"
219+
}
220+
},
221+
"jsonrpc": "2.0",
222+
"method": "textDocument/didClose"
223+
},
224+
"wait": []
225+
}
226+
},
227+
{
228+
"send": {
229+
"request": {
230+
"jsonrpc": "2.0",
231+
"id": 6,
232+
"method": "shutdown"
233+
},
234+
"wait": [
235+
{
236+
"id": 6,
237+
"result": null
238+
}
239+
]
240+
}
241+
},
242+
{
243+
"stop": {
244+
"exit_code": 0
245+
}
246+
}
247+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'completion.aggregates.incomplete_type'

0 commit comments

Comments
 (0)