Skip to content

Commit 148a70b

Browse files
author
Philippe Gil
committed
Avoid falsy name in textDocument/documentSymbol reply
See #1296
1 parent 14d1b16 commit 148a70b

File tree

4 files changed

+259
-13
lines changed

4 files changed

+259
-13
lines changed

source/gpr/lsp-gpr_files.adb

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,47 @@ package body LSP.GPR_Files is
468468

469469
package LKD renames LSP.Text_Documents.Langkit_Documents;
470470

471+
function To_Valid_Name
472+
(Name : VSS.Strings.Virtual_String)
473+
return VSS.Strings.Virtual_String;
474+
-- Avoid empty Name, set Name to " " when required.
475+
476+
procedure Append_New_To_Current (New_Symbol : Symbol);
477+
-- Append New_Symbol to current list.
478+
479+
---------------------------
480+
-- Append_New_To_Current --
481+
---------------------------
482+
483+
procedure Append_New_To_Current (New_Symbol : Symbol) is
484+
begin
485+
Current_Symbols.Append (New_Symbol);
486+
end Append_New_To_Current;
487+
488+
-------------------
489+
-- To_Valid_Name --
490+
-------------------
491+
492+
function To_Valid_Name
493+
(Name : VSS.Strings.Virtual_String)
494+
return VSS.Strings.Virtual_String is
495+
496+
begin
497+
if Name.Is_Empty
498+
then
499+
-- avoid name: "", in documentSymbol.
500+
return " ";
501+
else
502+
return Name;
503+
end if;
504+
end To_Valid_Name;
505+
471506
New_Symbol : Symbol :=
472507
(New_Id,
473508
Current_Symbol.Id,
474509
Token.Ref,
475510
Kind,
476-
Name,
511+
To_Valid_Name (Name),
477512
LKD.To_A_Range
478513
(Start_Line_Text =>
479514
File.Get_Line (Location_Range.Start_Line),
@@ -489,18 +524,6 @@ package body LSP.GPR_Files is
489524
LK_Slocs.Column_Number
490525
(Location_Range.End_Column))));
491526

492-
procedure Append_New_To_Current (New_Symbol : Symbol);
493-
-- Append New_Symbol to current list.
494-
495-
---------------------------
496-
-- Append_New_To_Current --
497-
---------------------------
498-
499-
procedure Append_New_To_Current (New_Symbol : Symbol) is
500-
begin
501-
Current_Symbols.Append (New_Symbol);
502-
end Append_New_To_Current;
503-
504527
begin
505528
case Kind is
506529
when K_Imported =>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
with"";project P is end P;
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
[
2+
{
3+
"comment": [
4+
"with \"\"; statement support"
5+
]
6+
},
7+
{
8+
"start": {
9+
"cmd": [
10+
"${ALS}",
11+
"--language-gpr"
12+
]
13+
}
14+
},
15+
{
16+
"send": {
17+
"request": {
18+
"params": {
19+
"processId": 30612,
20+
"capabilities": {
21+
"workspace": {
22+
"applyEdit": false
23+
},
24+
"textDocument": {
25+
"documentSymbol": {
26+
"hierarchicalDocumentSymbolSupport": true
27+
}
28+
}
29+
},
30+
"rootUri": "$URI{.}"
31+
},
32+
"jsonrpc": "2.0",
33+
"id": 1,
34+
"method": "initialize"
35+
},
36+
"wait": [
37+
{
38+
"jsonrpc": "2.0",
39+
"id": 1,
40+
"result": {
41+
"capabilities": {
42+
"textDocumentSync": {
43+
"openClose": true,
44+
"change": 1
45+
},
46+
"completionProvider": {
47+
"triggerCharacters": [
48+
" "
49+
],
50+
"resolveProvider": true
51+
},
52+
"hoverProvider": true,
53+
"definitionProvider": true,
54+
"documentSymbolProvider": {}
55+
}
56+
}
57+
}
58+
]
59+
}
60+
},
61+
{
62+
"send": {
63+
"request": {
64+
"jsonrpc": "2.0",
65+
"method": "initialized"
66+
},
67+
"wait": []
68+
}
69+
},
70+
{
71+
"send": {
72+
"request": {
73+
"params": {
74+
"textDocument": {
75+
"text": "with\"\";project P is end P;",
76+
"version": 0,
77+
"uri": "$URI{p.gpr}",
78+
"languageId": "Gpr"
79+
}
80+
},
81+
"jsonrpc": "2.0",
82+
"method": "textDocument/didOpen"
83+
},
84+
"wait": [
85+
{
86+
"method": "textDocument/publishDiagnostics",
87+
"params": {
88+
"uri": "$URI{p.gpr}",
89+
"diagnostics": []
90+
}
91+
}
92+
]
93+
}
94+
},
95+
{
96+
"send": {
97+
"request": {
98+
"jsonrpc": "2.0",
99+
"id": "textDocument/documentSymbol",
100+
"method": "textDocument/documentSymbol",
101+
"params": {
102+
"textDocument": {
103+
"uri": "$URI{p.gpr}"
104+
}
105+
}
106+
},
107+
"wait": [
108+
{
109+
"jsonrpc": "2.0",
110+
"id": "textDocument/documentSymbol",
111+
"result": [
112+
{
113+
"name": "with clauses",
114+
"kind": 3,
115+
"range": {
116+
"start": {
117+
"line": 0,
118+
"character": 0
119+
},
120+
"end": {
121+
"line": 0,
122+
"character": 0
123+
}
124+
},
125+
"selectionRange": {
126+
"start": {
127+
"line": 0,
128+
"character": 0
129+
},
130+
"end": {
131+
"line": 0,
132+
"character": 0
133+
}
134+
},
135+
"children": [
136+
{
137+
"name": " ",
138+
"kind": 3,
139+
"range": {
140+
"start": {
141+
"line": 0,
142+
"character": 4
143+
},
144+
"end": {
145+
"line": 0,
146+
"character": 6
147+
}
148+
},
149+
"selectionRange": {
150+
"start": {
151+
"line": 0,
152+
"character": 4
153+
},
154+
"end": {
155+
"line": 0,
156+
"character": 6
157+
}
158+
}
159+
}
160+
]
161+
},
162+
{
163+
"name": "P",
164+
"kind": 2,
165+
"range": {
166+
"start": {
167+
"line": 0,
168+
"character": 7
169+
},
170+
"end": {
171+
"line": 0,
172+
"character": 14
173+
}
174+
},
175+
"selectionRange": {
176+
"start": {
177+
"line": 0,
178+
"character": 7
179+
},
180+
"end": {
181+
"line": 0,
182+
"character": 14
183+
}
184+
}
185+
}
186+
]
187+
}
188+
]
189+
}
190+
},
191+
{
192+
"send": {
193+
"request": {
194+
"jsonrpc": "2.0",
195+
"id": "shutdown",
196+
"method": "shutdown",
197+
"params": null
198+
},
199+
"wait": [
200+
{
201+
"id": "shutdown",
202+
"result": null
203+
}
204+
]
205+
}
206+
},
207+
{
208+
"send": {
209+
"request": {
210+
"jsonrpc": "2.0",
211+
"method": "exit"
212+
},
213+
"wait": []
214+
}
215+
},
216+
{
217+
"stop": {
218+
"exit_code": 0
219+
}
220+
}
221+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'with empty string statement support'

0 commit comments

Comments
 (0)