Skip to content

Commit 4cefdec

Browse files
Merge branch 'topic/invisible_units' into 'master'
Do not add qualifier when completing invisible units See merge request eng/ide/ada_language_server!1575
2 parents 6eee76d + 1832adc commit 4cefdec

File tree

6 files changed

+210
-7
lines changed

6 files changed

+210
-7
lines changed

source/ada/lsp-ada_documents.adb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ package body LSP.Ada_Documents is
166166

167167
procedure Append_Auto_Import_Command is
168168
use LSP.Ada_Handlers.Refactor;
169+
use Libadalang.Analysis;
169170

170171
Auto_Import_Command : Auto_Import.Command;
171172
-- The auto-import command.
@@ -179,20 +180,28 @@ package body LSP.Ada_Documents is
179180
-- Check if we are completing a dotted name. We want to prepend the
180181
-- right qualifier only if it's not the case.
181182

183+
Missing_Unit_Root_Decl : constant Libadalang.Analysis.Basic_Decl :=
184+
BD.P_Enclosing_Compilation_Unit.P_Decl;
185+
-- The missing unit root declaration for this invisible symbol (e.g:
186+
-- the "Ada.Text_IO" package declaration for the
187+
-- "Ada.Text_IO.Put_Line" subprogram).
188+
182189
Missing_Unit_Name : VSS.Strings.Virtual_String :=
183190
VSS.Strings.Conversions.To_Virtual_String
184191
(Langkit_Support.Text.To_UTF8
185-
(BD.P_Enclosing_Compilation_Unit.P_Decl.
186-
P_Fully_Qualified_Name));
192+
(Missing_Unit_Root_Decl.P_Fully_Qualified_Name));
187193
-- Get the missing unit name.
188194

189195
Missing_Qualifier : VSS.Strings.Virtual_String :=
190-
(if not Is_Dotted_Name then
191-
Missing_Unit_Name
196+
(if Is_Dotted_Name or else BD = Missing_Unit_Root_Decl then
197+
VSS.Strings.Empty_Virtual_String
192198
else
193-
VSS.Strings.Empty_Virtual_String);
194-
-- The missing qualifier. We should not add any qualifier if it's
195-
-- already present (i.e: when completing a dotted name).
199+
Missing_Unit_Name);
200+
-- The missing qualifier. We should not add any qualifier if the
201+
-- user accepted the completion item corresponding to the missing
202+
-- unit itself (e.g: if the user selects "Ada.Text_IO" in the
203+
-- completion window, we do not need to add any qualifier) or if
204+
-- he's completing a dotted name.
196205
begin
197206
Auto_Import_Command.Initialize
198207
(Context => Context,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package Bar is
2+
3+
type My_Int is tagged record
4+
A : Integer;
5+
end record;
6+
7+
procedure Do_Nothing (Obj : My_Int; A :Integer; B : Integer) is null;
8+
9+
end Bar;
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+
2+
procedure Main is
3+
Obj : My_Int := (A => 10);
4+
begin
5+
Ba
6+
end Main;
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
[
2+
{
3+
"comment": [
4+
"This test checks that we do not add any qualifier to the 'auto-import'",
5+
"command attached to invisible units' completion items."
6+
]
7+
},
8+
{
9+
"start": {
10+
"cmd": ["${ALS}"]
11+
}
12+
},
13+
{
14+
"send": {
15+
"request": {
16+
"jsonrpc": "2.0",
17+
"id": 1,
18+
"method": "initialize",
19+
"params": {
20+
"processId": 199714,
21+
"rootUri": "$URI{.}",
22+
"capabilities": {
23+
"workspace": {
24+
"applyEdit": true
25+
},
26+
"textDocument": {
27+
"completion": {
28+
"completionItem": {
29+
"snippetSupport": true,
30+
"documentationFormat": ["markdown", "plaintext"]
31+
}
32+
}
33+
},
34+
"window": {
35+
"workDoneProgress": true
36+
}
37+
}
38+
}
39+
},
40+
"wait": [
41+
{
42+
"jsonrpc": "2.0",
43+
"id": 1,
44+
"result": {
45+
"capabilities": {
46+
"textDocumentSync": 2,
47+
"completionProvider": {
48+
"triggerCharacters": [".", ",", "'", "("],
49+
"resolveProvider": true
50+
}
51+
}
52+
}
53+
}
54+
]
55+
}
56+
},
57+
{
58+
"send": {
59+
"request": {
60+
"jsonrpc": "2.0",
61+
"method": "initialized"
62+
},
63+
"wait": []
64+
}
65+
},
66+
{
67+
"send": {
68+
"request": {
69+
"jsonrpc": "2.0",
70+
"method": "textDocument/didOpen",
71+
"params": {
72+
"textDocument": {
73+
"uri": "$URI{main.adb}",
74+
"languageId": "ada",
75+
"version": 1,
76+
"text": "\nprocedure Main is\n Obj : My_Int := (A => 10);\nbegin\n Ba\nend Main;\n"
77+
}
78+
}
79+
},
80+
"wait": []
81+
}
82+
},
83+
{
84+
"send": {
85+
"request": {
86+
"jsonrpc": "2.0",
87+
"method": "workspace/didChangeConfiguration",
88+
"params": {
89+
"settings": {
90+
"ada": {
91+
"projectFile": "default.gpr"
92+
}
93+
}
94+
}
95+
},
96+
"wait": [
97+
{
98+
"jsonrpc": "2.0",
99+
"method": "$/progress",
100+
"params": {
101+
"token": "<ANY>",
102+
"value": {
103+
"kind": "end"
104+
}
105+
}
106+
}
107+
]
108+
}
109+
},
110+
{
111+
"send": {
112+
"request": {
113+
"jsonrpc": "2.0",
114+
"id": 13,
115+
"method": "textDocument/completion",
116+
"params": {
117+
"textDocument": {
118+
"uri": "$URI{main.adb}"
119+
},
120+
"position": {
121+
"line": 4,
122+
"character": 5
123+
},
124+
"context": {
125+
"triggerKind": 1
126+
}
127+
}
128+
},
129+
"wait": [
130+
{
131+
"id": 13,
132+
"result": {
133+
"isIncomplete": false,
134+
"items": [
135+
"<HAS>",
136+
{
137+
"label": "Bar (invisible)",
138+
"kind": 9,
139+
"detail": "package Bar",
140+
"documentation": "at bar.ads (1:1)",
141+
"sortText": "~100&00001Bar",
142+
"filterText": "Bar",
143+
"insertText": "Bar",
144+
"command": {
145+
"title": "",
146+
"command": "als-auto-import",
147+
"arguments": [
148+
{
149+
"context": "Default",
150+
"where": {
151+
"textDocument": {
152+
"uri": "$URI{main.adb}"
153+
},
154+
"position": {
155+
"line": 4,
156+
"character": 5
157+
}
158+
},
159+
"import": "Bar",
160+
"qualifier": ""
161+
}
162+
]
163+
}
164+
}
165+
]
166+
}
167+
}
168+
]
169+
}
170+
},
171+
{
172+
"stop": {
173+
"exit_code": 0
174+
}
175+
}
176+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'completion.invisible.insert_with_clause.invisible_unit'

0 commit comments

Comments
 (0)