Skip to content

Commit 19265fe

Browse files
Merge branch 'topic/#1728' into 'master'
Handle DottedName nodes in completionResolve request See merge request eng/ide/ada_language_server!2145
2 parents 613729a + f74422c commit 19265fe

File tree

8 files changed

+245
-10
lines changed

8 files changed

+245
-10
lines changed

source/ada/lsp-ada_handlers.adb

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,10 +1945,12 @@ package body LSP.Ada_Handlers is
19451945
Id : LSP.Structures.Integer_Or_Virtual_String;
19461946
Value : LSP.Structures.CompletionItem)
19471947
is
1948+
use VSS.Strings;
19481949
use all type Libadalang.Common.Ada_Node_Kind_Type;
19491950

19501951
Context : LSP.Ada_Context_Sets.Context_Access;
1951-
Node : Libadalang.Analysis.Ada_Node;
1952+
Node : Libadalang.Analysis.Ada_Node;
1953+
Definition : Libadalang.Analysis.Defining_Name;
19521954
C : LSP.Structures.JSON_Event_Vectors.Cursor;
19531955
Location : LSP.Structures.Location;
19541956
Response : LSP.Structures.CompletionItem := Value;
@@ -1963,6 +1965,7 @@ package body LSP.Ada_Handlers is
19631965
return;
19641966
end if;
19651967

1968+
-- Retrieve the node at the location stored in the completion item's data
19661969
C := Value.data.First;
19671970
Location := LSP.Structures.LSPAny_Vectors.From_Any (C);
19681971
Context := Self.Contexts.Get_Best_Context (Location.uri);
@@ -1974,18 +1977,25 @@ package body LSP.Ada_Handlers is
19741977
(textDocument => (uri => Location.uri),
19751978
position => Location.a_range.start));
19761979

1977-
if Node.Kind = Libadalang.Common.Ada_Identifier then
1978-
-- When node is an identifier, take parent node to resolve to
1979-
-- defining name. It is a case of names of package identifiers.
1980-
1981-
Node := Node.Parent;
1980+
-- Return immediately if the retrieved node is not a name node
1981+
if Node.Is_Null or else Node.Kind not in Libadalang.Common.Ada_Name then
1982+
Self.Sender.On_Error_Response
1983+
(Id,
1984+
(code => LSP.Enumerations.InvalidParams,
1985+
message =>
1986+
"Could not resolve completion item: no name "
1987+
& "node found at given location"));
1988+
return;
19821989
end if;
19831990

1991+
-- Get the node's enclosing defining name: in some cases, the node
1992+
-- can be a simple name that is part of a larger defining name
1993+
-- (e.g: dotted names in the case of child packages).
1994+
Definition := Node.As_Name.P_Enclosing_Defining_Name;
1995+
19841996
-- Compute the completion item's details
1985-
if not Node.Is_Null then
1997+
if not Definition.Is_Null then
19861998
declare
1987-
use type VSS.Strings.Virtual_String;
1988-
19891999
Qual_Text : VSS.Strings.Virtual_String;
19902000
Loc_Text : VSS.Strings.Virtual_String;
19912001
Doc_Text : VSS.Strings.Virtual_String;
@@ -1994,7 +2004,7 @@ package body LSP.Ada_Handlers is
19942004

19952005
begin
19962006
LSP.Ada_Documentation.Get_Tooltip_Text
1997-
(Name => Node.As_Defining_Name,
2007+
(Name => Definition,
19982008
Origin => Libadalang.Analysis.No_Ada_Node,
19992009
Style => Self.Configuration.Documentation_Style,
20002010
Qualifier_Text => Qual_Text,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
with Root.Child;
2+
with Root.Child.Do_Something;
3+
procedure Main is
4+
begin
5+
Root.Child.Do_Something;
6+
Root.;
7+
end Main;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Root.Child.Do_Something is
2+
begin
3+
null;
4+
end Root.Child.Do_Something;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Description of the Root.Child package
2+
3+
package Root.Child is
4+
5+
procedure Hello is null;
6+
7+
end Root.Child;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package Root is
2+
3+
end Root;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project Test is
2+
for Source_Dirs use ("src");
3+
for Main use ("main.adb");
4+
end Test;
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
[
2+
{
3+
"comment": [
4+
"Test that that completionItem/resolve request works for dotted names."
5+
]
6+
},
7+
{
8+
"start": {
9+
"cmd": ["${ALS}"]
10+
}
11+
},
12+
{
13+
"send": {
14+
"request": {
15+
"jsonrpc": "2.0",
16+
"id": "ada-1",
17+
"method": "initialize",
18+
"params": {
19+
"rootUri": "$URI{.}",
20+
"capabilities": {
21+
"workspace": {
22+
"applyEdit": true
23+
},
24+
"textDocument": {
25+
"completion": {
26+
"dynamicRegistration": true,
27+
"completionItem": {
28+
"snippetSupport": true,
29+
"documentationFormat": ["plaintext", "markdown"]
30+
}
31+
},
32+
"documentSymbol": {
33+
"hierarchicalDocumentSymbolSupport": true
34+
}
35+
}
36+
}
37+
}
38+
},
39+
"wait": [
40+
{
41+
"id": "ada-1",
42+
"result": {
43+
"capabilities": {
44+
"textDocumentSync": 2,
45+
"callHierarchyProvider": true
46+
}
47+
}
48+
}
49+
]
50+
}
51+
},
52+
{
53+
"send": {
54+
"request": {
55+
"jsonrpc": "2.0",
56+
"method": "initialized"
57+
},
58+
"wait": []
59+
}
60+
},
61+
{
62+
"send": {
63+
"request": {
64+
"jsonrpc": "2.0",
65+
"method": "workspace/didChangeConfiguration",
66+
"params": {
67+
"settings": {
68+
"ada": {
69+
"scenarioVariables": {},
70+
"defaultCharset": "ISO-8859-1",
71+
"adaFileDiagnostics": false,
72+
"followSymlinks": false
73+
}
74+
}
75+
}
76+
},
77+
"wait": []
78+
}
79+
},
80+
{
81+
"send": {
82+
"request": {
83+
"jsonrpc": "2.0",
84+
"method": "textDocument/didOpen",
85+
"params": {
86+
"textDocument": {
87+
"uri": "$URI{src/main.adb}",
88+
"languageId": "Ada",
89+
"version": 0,
90+
"text": "with Root.Child;\nwith Root.Child.Do_Something;\nprocedure Main is\nbegin\n Root.Child.Do_Something;\n Root.;\nend Main;\n"
91+
}
92+
}
93+
},
94+
"wait": []
95+
}
96+
},
97+
{
98+
"send": {
99+
"request": {
100+
"jsonrpc": "2.0",
101+
"id": 42,
102+
"method": "completionItem/resolve",
103+
"params": {
104+
"label": "Child",
105+
"insertTextFormat": 1,
106+
"kind": 9,
107+
"sortText": "100&00001Child",
108+
"data": {
109+
"uri": "$URI{src/root-child.ads}",
110+
"range": {
111+
"start": {
112+
"line": 2,
113+
"character": 8
114+
},
115+
"end": {
116+
"line": 2,
117+
"character": 18
118+
}
119+
}
120+
}
121+
}
122+
},
123+
"wait": [
124+
{
125+
"id": 42,
126+
"result": {
127+
"data": {
128+
"range": {
129+
"end": {
130+
"character": 18,
131+
"line": 2
132+
},
133+
"start": {
134+
"character": 8,
135+
"line": 2
136+
}
137+
},
138+
"uri": "$URI{src/root-child.ads}"
139+
},
140+
"detail": "package Root.Child",
141+
"documentation": "at root-child.ads (3:1)\n\nDescription of the Root.Child package",
142+
"insertTextFormat": 1,
143+
"kind": 9,
144+
"label": "Child",
145+
"sortText": "100&00001Child"
146+
}
147+
}
148+
]
149+
}
150+
},
151+
{
152+
"send": {
153+
"request": {
154+
"jsonrpc": "2.0",
155+
"method": "textDocument/didClose",
156+
"params": {
157+
"textDocument": {
158+
"uri": "$URI{src/main.adb}"
159+
}
160+
}
161+
},
162+
"wait": []
163+
}
164+
},
165+
{
166+
"send": {
167+
"request": {
168+
"jsonrpc": "2.0",
169+
"method": "textDocument/didClose",
170+
"params": {
171+
"textDocument": {
172+
"uri": "$URI{src/root-child-do_something.adb}"
173+
}
174+
}
175+
},
176+
"wait": []
177+
}
178+
},
179+
{
180+
"send": {
181+
"request": {
182+
"jsonrpc": "2.0",
183+
"id": 22,
184+
"method": "shutdown"
185+
},
186+
"wait": [
187+
{
188+
"id": 22,
189+
"result": null
190+
}
191+
]
192+
}
193+
},
194+
{
195+
"stop": {
196+
"exit_code": 0
197+
}
198+
}
199+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'completion.resolve.dotted_names'

0 commit comments

Comments
 (0)