Skip to content

Commit a77520b

Browse files
U415-027 Added file renaming of top level decls
Added test cases for this functionality. Updated test suite baseline.
1 parent 5397463 commit a77520b

File tree

10 files changed

+474
-189
lines changed

10 files changed

+474
-189
lines changed

source/ada/lsp-ada_handlers.adb

Lines changed: 129 additions & 176 deletions
Large diffs are not rendered by default.

source/ada/lsp-lal_utils.adb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,8 @@ package body LSP.Lal_Utils is
941941

942942
begin
943943
return WE : LSP.Messages.WorkspaceEdit do
944+
-- Text edits
945+
944946
while Text_Edit_Ordered_Maps.Has_Element (Text_Edits_Cursor) loop
945947
Text_Edits.Clear;
946948

@@ -977,6 +979,11 @@ package body LSP.Lal_Utils is
977979
Text_Edit_Ordered_Maps.Next (Text_Edits_Cursor);
978980
end loop;
979981

982+
-- File creations
983+
-- TODO
984+
985+
-- File deletions
986+
980987
if not Rename then
981988
while Unbounded_String_Ordered_Sets.Has_Element
982989
(File_Deletions_Cursor)
@@ -1016,6 +1023,18 @@ package body LSP.Lal_Utils is
10161023
Unbounded_String_Ordered_Sets.Next (File_Deletions_Cursor);
10171024
end loop;
10181025
end if;
1026+
1027+
-- File renames
1028+
1029+
for File_Rename of Edits.File_Renames loop
1030+
WE.documentChanges.Append
1031+
(LSP.Messages.Document_Change'(
1032+
(Kind => LSP.Messages.Rename_File,
1033+
Rename_File => LSP.Messages.RenameFile'
1034+
(oldUri => LSP.Types.File_To_URI (File_Rename.Filepath),
1035+
newUri => LSP.Types.File_To_URI (File_Rename.New_Name),
1036+
others => <>))));
1037+
end loop;
10191038
end return;
10201039
end To_Workspace_Edit;
10211040

testsuite/ada_lsp/SA22-029.rename_in_comments/test.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,19 @@
209209
},
210210
"newText": "-"
211211
},
212+
{
213+
"range": {
214+
"start": {
215+
"line": 9,
216+
"character": 13
217+
},
218+
"end": {
219+
"line": 9,
220+
"character": 18
221+
}
222+
},
223+
"newText": "Print1"
224+
},
212225
{
213226
"range": {
214227
"start": {
@@ -247,19 +260,6 @@
247260
}
248261
},
249262
"newText": "-"
250-
},
251-
{
252-
"range": {
253-
"start": {
254-
"line": 9,
255-
"character": 13
256-
},
257-
"end": {
258-
"line": 9,
259-
"character": 18
260-
}
261-
},
262-
"newText": "Print1"
263263
}
264264
],
265265
"$URI{p1.adb}": [
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package Foo.Bar.Baz is
2+
end Foo.Bar.Baz;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package Foo.Bar is
2+
end Foo.Bar;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package Foo is
2+
end Foo;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
with Foo;
2+
with Foo.Bar;
3+
with Foo.Bar.Baz;
4+
procedure Test is
5+
begin
6+
null;
7+
end Test;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project Test is
2+
for Main use ("test.adb");
3+
end Test;
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
[
2+
{
3+
"comment": [
4+
""
5+
]
6+
},
7+
{
8+
"start": {
9+
"cmd": [
10+
"${ALS}"
11+
]
12+
}
13+
},
14+
{
15+
"send": {
16+
"request": {
17+
"jsonrpc": "2.0",
18+
"id": 0,
19+
"method": "initialize",
20+
"params": {
21+
"rootUri": "$URI{.}",
22+
"capabilities": {
23+
"workspace": {
24+
"applyEdit": true,
25+
"workspaceEdit": {
26+
"documentChanges": true,
27+
"resourceOperations": [
28+
"create",
29+
"rename",
30+
"delete"
31+
]
32+
}
33+
},
34+
"textDocument": {
35+
"rename": {
36+
"dynamicRegistration": true,
37+
"prepareSupport": true,
38+
"prepareSupportDefaultBehavior": 1,
39+
"honorsChangeAnnotations": true
40+
}
41+
}
42+
},
43+
"workspaceFolders": [
44+
{
45+
"uri": "$URI{.}",
46+
"name": "U415-027.refactor_safe_rename"
47+
}
48+
]
49+
}
50+
},
51+
"wait": [
52+
{
53+
"id": 0,
54+
"result": {
55+
"capabilities": {
56+
"renameProvider": {
57+
"prepareProvider": true
58+
}
59+
}
60+
}
61+
}
62+
]
63+
}
64+
},
65+
{
66+
"send": {
67+
"request": {
68+
"jsonrpc": "2.0",
69+
"method": "initialized",
70+
"params": {}
71+
},
72+
"wait": []
73+
}
74+
},
75+
{
76+
"send": {
77+
"request": {
78+
"jsonrpc": "2.0",
79+
"method": "textDocument/didOpen",
80+
"params": {
81+
"textDocument": {
82+
"uri": "$URI{foo-bar-baz.ads}",
83+
"languageId": "ada",
84+
"version": 1,
85+
"text": "package Foo.Bar.Baz is\nend Foo.Bar.Baz;\n"
86+
}
87+
}
88+
},
89+
"wait": [
90+
{
91+
"method": "$/progress",
92+
"params": {
93+
"value": {
94+
"kind": "end"
95+
}
96+
}
97+
}
98+
]
99+
}
100+
},
101+
{
102+
"send": {
103+
"request": {
104+
"jsonrpc": "2.0",
105+
"id": 5,
106+
"method": "textDocument/prepareRename",
107+
"params": {
108+
"textDocument": {
109+
"uri": "$URI{foo-bar-baz.ads}"
110+
},
111+
"position": {
112+
"line": 0,
113+
"character": 12
114+
}
115+
}
116+
},
117+
"wait": [
118+
{
119+
"id": 5,
120+
"result": {
121+
"start": {
122+
"line": 0,
123+
"character": 12
124+
},
125+
"end": {
126+
"line": 0,
127+
"character": 15
128+
}
129+
}
130+
}
131+
]
132+
}
133+
},
134+
{
135+
"send": {
136+
"request": {
137+
"jsonrpc": "2.0",
138+
"id": 6,
139+
"method": "textDocument/rename",
140+
"params": {
141+
"textDocument": {
142+
"uri": "$URI{foo-bar-baz.ads}"
143+
},
144+
"position": {
145+
"line": 0,
146+
"character": 12
147+
},
148+
"newName": "Qux"
149+
}
150+
},
151+
"wait": [
152+
{
153+
"id": 6,
154+
"result": {
155+
"documentChanges": [
156+
{
157+
"textDocument": {
158+
"uri": "$URI{foo-bar-baz.ads}",
159+
"version": 1
160+
},
161+
"edits": [
162+
{
163+
"range": {
164+
"start": {
165+
"line": 0,
166+
"character": 12
167+
},
168+
"end": {
169+
"line": 0,
170+
"character": 15
171+
}
172+
},
173+
"newText": "Qux"
174+
},
175+
{
176+
"range": {
177+
"start": {
178+
"line": 1,
179+
"character": 8
180+
},
181+
"end": {
182+
"line": 1,
183+
"character": 11
184+
}
185+
},
186+
"newText": "Qux"
187+
}
188+
]
189+
},
190+
{
191+
"textDocument": {
192+
"uri": "$URI{foo-bar.ads}",
193+
"version": null
194+
},
195+
"edits": [
196+
{
197+
"range": {
198+
"start": {
199+
"line": 0,
200+
"character": 12
201+
},
202+
"end": {
203+
"line": 0,
204+
"character": 15
205+
}
206+
},
207+
"newText": "Qux"
208+
},
209+
{
210+
"range": {
211+
"start": {
212+
"line": 1,
213+
"character": 8
214+
},
215+
"end": {
216+
"line": 1,
217+
"character": 11
218+
}
219+
},
220+
"newText": "Qux"
221+
}
222+
]
223+
},
224+
{
225+
"textDocument": {
226+
"uri": "$URI{test.adb}",
227+
"version": null
228+
},
229+
"edits": [
230+
{
231+
"range": {
232+
"start": {
233+
"line": 1,
234+
"character": 9
235+
},
236+
"end": {
237+
"line": 1,
238+
"character": 12
239+
}
240+
},
241+
"newText": "Qux"
242+
},
243+
{
244+
"range": {
245+
"start": {
246+
"line": 2,
247+
"character": 9
248+
},
249+
"end": {
250+
"line": 2,
251+
"character": 12
252+
}
253+
},
254+
"newText": "Qux"
255+
}
256+
]
257+
},
258+
{
259+
"kind": "rename",
260+
"oldUri": "$URI{foo-bar-baz.ads}",
261+
"newUri": "$URI{foo-qux-baz.ads}",
262+
"options": {}
263+
},
264+
{
265+
"kind": "rename",
266+
"oldUri": "$URI{foo-bar.ads}",
267+
"newUri": "$URI{foo-qux.ads}",
268+
"options": {}
269+
}
270+
]
271+
}
272+
}
273+
]
274+
}
275+
},
276+
{
277+
"send": {
278+
"request": {
279+
"jsonrpc": "2.0",
280+
"id": 14,
281+
"method": "shutdown"
282+
},
283+
"wait": [
284+
{
285+
"id": 14,
286+
"result": null
287+
}
288+
]
289+
}
290+
},
291+
{
292+
"stop": {
293+
"exit_code": 0
294+
}
295+
}
296+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'U415-027.refactor_safe_rename'

0 commit comments

Comments
 (0)