Skip to content

Commit 52b4880

Browse files
committed
Merge branch 'topic/fix_folding' into 'master'
Fix foldingRange failures on a new file Closes #1276 See merge request eng/ide/ada_language_server!1475
2 parents 5ede42a + d9ee91e commit 52b4880

File tree

4 files changed

+211
-4
lines changed

4 files changed

+211
-4
lines changed

source/ada/lsp-ada_documents.adb

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,13 @@ package body LSP.Ada_Documents is
830830
procedure Store_Span (Span : LSP.Structures.A_Range);
831831
-- Include Span to the result .
832832

833+
function Traverse_Node
834+
(Node : Ada_Node;
835+
Visit : access function (Node : Ada_Node'Class) return Visit_Status)
836+
return Visit_Status;
837+
-- The same as Libadalang.Analysis.Traverse, but without raising
838+
-- exception on a null node.
839+
833840
-----------
834841
-- Parse --
835842
-----------
@@ -1007,12 +1014,53 @@ package body LSP.Ada_Documents is
10071014
end if;
10081015
end Store_Span;
10091016

1010-
Token : Token_Reference;
1011-
Span : LSP.Structures.A_Range;
1017+
-------------------
1018+
-- Traverse_Node --
1019+
-------------------
10121020

1013-
begin
1014-
Traverse (Self.Unit (Context).Root, Parse'Access);
1021+
function Traverse_Node
1022+
(Node : Ada_Node;
1023+
Visit : access function (Node : Ada_Node'Class) return Visit_Status)
1024+
return Visit_Status
1025+
is
1026+
Status : Visit_Status := Into;
1027+
begin
1028+
if not Node.Is_Null then
1029+
Status := Visit (Node);
1030+
-- Skip processing the child nodes if the returned status is Over
1031+
-- or Stop. In the former case the previous call to Visit has
1032+
-- taken care of processing the needed childs, and in the latter
1033+
-- case we must immediately stop processing the tree.
1034+
if Status = Into then
1035+
for I in 1 .. Children_Count (Node) loop
1036+
declare
1037+
Cur_Child : constant Ada_Node :=
1038+
Child (Node, I);
1039+
begin
1040+
if not Cur_Child.Is_Null then
1041+
Status := Traverse_Node (Cur_Child, Visit);
1042+
exit when Status /= Into;
1043+
end if;
1044+
end;
1045+
end loop;
1046+
end if;
1047+
end if;
10151048

1049+
if Status = Stop then
1050+
return Stop;
1051+
-- At this stage the Over status has no sense and we just continue
1052+
-- processing the tree.
1053+
else
1054+
return Into;
1055+
end if;
1056+
end Traverse_Node;
1057+
1058+
Token : Token_Reference;
1059+
Span : LSP.Structures.A_Range;
1060+
Ignore : constant Visit_Status :=
1061+
Traverse_Node (Self.Unit (Context).Root, Parse'Access);
1062+
1063+
begin
10161064
if not Comments then
10171065
-- do not process comments
10181066
return;
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: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
[
2+
{
3+
"comment": [
4+
"Check code folding for a new file"
5+
]
6+
},
7+
{
8+
"start": {
9+
"cmd": [
10+
"${ALS}"
11+
]
12+
}
13+
},
14+
{
15+
"send": {
16+
"request": {
17+
"params": {
18+
"processId": 2505,
19+
"capabilities": {
20+
"textDocument": {
21+
"foldingRange": {
22+
"lineFoldingOnly": true
23+
}
24+
}
25+
},
26+
"rootUri": "$URI{.}"
27+
},
28+
"jsonrpc": "2.0",
29+
"id": 1,
30+
"method": "initialize"
31+
},
32+
"wait": [
33+
{
34+
"id": 1,
35+
"result": {
36+
"capabilities": {
37+
"textDocumentSync": 2,
38+
"foldingRangeProvider": true
39+
}
40+
}
41+
}
42+
]
43+
}
44+
},
45+
{
46+
"send": {
47+
"request": {
48+
"jsonrpc": "2.0",
49+
"method": "initialized"
50+
},
51+
"wait": []
52+
}
53+
},
54+
{
55+
"send": {
56+
"request": {
57+
"params": {
58+
"settings": {
59+
"ada": {
60+
"projectFile": "$URI{default.gpr}",
61+
"scenarioVariables": {},
62+
"enableDiagnostics": false,
63+
"defaultCharset": "ISO-8859-1"
64+
}
65+
}
66+
},
67+
"jsonrpc": "2.0",
68+
"method": "workspace/didChangeConfiguration"
69+
},
70+
"wait": []
71+
}
72+
},
73+
{
74+
"send": {
75+
"request": {
76+
"params": {
77+
"textDocument": {
78+
"text": "",
79+
"version": 0,
80+
"uri": "$URI{main.adb}",
81+
"languageId": "Ada"
82+
}
83+
},
84+
"jsonrpc": "2.0",
85+
"method": "textDocument/didOpen"
86+
},
87+
"wait": []
88+
}
89+
}, {
90+
"send": {
91+
"request": {
92+
"jsonrpc":"2.0",
93+
"method":"textDocument/didChange",
94+
"params":{
95+
"textDocument":{
96+
"uri": "$URI{main.adb}",
97+
"version":0
98+
},
99+
"contentChanges":[{
100+
"range":{
101+
"start":{
102+
"line":0,
103+
"character":0
104+
},
105+
"end":{
106+
"line":0,
107+
"character":0
108+
}
109+
},
110+
"text":"with G"
111+
}]
112+
}
113+
},
114+
"wait":[]
115+
}
116+
}, {
117+
"send": {
118+
"request": {
119+
"params": {
120+
"textDocument": {
121+
"uri": "$URI{main.adb}"
122+
}
123+
},
124+
"jsonrpc": "2.0",
125+
"id": 2,
126+
"method": "textDocument/foldingRange"
127+
},
128+
"wait": [
129+
{
130+
"id": 2,
131+
"result": null
132+
}
133+
]
134+
}
135+
},
136+
{
137+
"send": {
138+
"request": {
139+
"jsonrpc": "2.0",
140+
"id": 3,
141+
"method": "shutdown"
142+
},
143+
"wait": [
144+
{
145+
"id": 3,
146+
"result": null
147+
}
148+
]
149+
}
150+
},
151+
{
152+
"stop": {
153+
"exit_code": 0
154+
}
155+
}
156+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'folding.on_new_file'

0 commit comments

Comments
 (0)