Skip to content

Commit 6749c1c

Browse files
Merge branch 'als_1716' into 'master'
Added gifs for new refactoring tools See merge request eng/ide/ada_language_server!2127
2 parents b771d3e + c82ccf9 commit 6749c1c

File tree

8 files changed

+93
-61
lines changed

8 files changed

+93
-61
lines changed

doc/media/extract_variable.gif

58 KB
Loading

doc/media/inline_variable.gif

70.2 KB
Loading
78.6 KB
Loading

doc/media/swap_if_else.gif

55.2 KB
Loading

doc/refactoring_tools.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* [Sort Case](#sort-case)
1818
* [Suppress Separate](#suppress-separate)
1919
* [Delete Entity](#delete-entity)
20+
* [Inline variable](#inline-variable)
2021
* [Introduce Parameter](#introduce-parameter)
2122
* [Replace Type](#replace-type)
2223
* [Auto Import](#auto-import)
@@ -146,6 +147,8 @@ Demo source is `extract_subprogram/` in [Code Samples](https://github.com/AdaCor
146147

147148
See `src/lal_refactor-extract_variable.ads` in [LAL Refactor repository](https://github.com/AdaCore/lal-refactor).
148149

150+
![extract-variable](media/extract_variable.gif)
151+
149152
## Pull Up Declaration
150153

151154
**Command name:** `als-refactor-pull_up_declaration`
@@ -167,6 +170,8 @@ Demo source is `pull_up_declaration/` in [Code Samples](https://github.com/AdaCo
167170

168171
See `src/lal_refactor-sort_case.ads` in [LAL Refactor repository](https://github.com/AdaCore/lal-refactor).
169172

173+
![sort-case-alphabetical](media/sort_case_alphabetical.gif)
174+
170175
## Suppress Separate
171176

172177
**Command name:** `als-suppress-separate`
@@ -199,6 +204,17 @@ Demo source is `delete_entity/` in [Code Samples](https://github.com/AdaCore/ada
199204

200205
![delete_entity](media/delete_entity.gif)
201206

207+
## Inline variable
208+
209+
**Command name:** `als-refactor-inline_variable`
210+
211+
* Delete the variable with the initialization expression and replace all
212+
references to this expression.
213+
214+
See `src/lal_refactor-inline_variable.ads` in [LAL Refactor repository](https://github.com/AdaCore/lal-refactor).
215+
216+
![inline_variable](media/inline_variable.gif)
217+
202218
## Introduce Parameter
203219

204220
**Command name:** `als-refactor-introduce-parameter`
@@ -256,3 +272,5 @@ Demo source is `sort_dependencies/` in [Code Samples](https://github.com/AdaCore
256272
* Swap If and else code branches and invert condition.
257273

258274
See `src/lal_refactor-swap_if_else` in [LAL Refactor repository](https://github.com/AdaCore/lal-refactor).
275+
276+
![swap_if_else](media/swap_if_else.gif)

source/ada/lsp-ada_handlers.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,8 +1331,9 @@ package body LSP.Ada_Handlers is
13311331
(Natural (Location.Line) - 1,
13321332
Natural (Location.Column) - 1)),
13331333
LSP.Constants.Empty));
1334+
end if;
13341335

1335-
elsif Is_Sort_Declaration_Available (Node.Unit, Location) then
1336+
if Is_Sort_Declaration_Available (Node.Unit, Location) then
13361337
Declaration.Append_Code_Action
13371338
(Context => Context,
13381339
Commands_Vector => Result,

testsuite/ada_lsp/refactoring_sort_case/main.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ begin
1717
case K1 is
1818
when Blue =>
1919
Ada.Text_IO.Put_Line ("Blue");
20-
when Green =>
21-
Ada.Text_IO.Put_Line ("Green");
2220
when Red =>
2321
Ada.Text_IO.Put_Line ("Red");
22+
when Green =>
23+
Ada.Text_IO.Put_Line ("Green");
2424
end case;
2525
end Main;

testsuite/ada_lsp/refactoring_sort_case/test.json

Lines changed: 71 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
"uri": "$URI{main.adb}",
139139
"languageId": "Ada",
140140
"version": 0,
141-
"text": "\nwith Ada.Text_IO;\n\nprocedure Main is\n type Kind is (Red, Blue, Green);\n K, K1 : Kind := Red;\nbegin\n case K is\n when Red =>\n Ada.Text_IO.Put_Line (\"Red\");\n when Blue =>\n Ada.Text_IO.Put_Line (\"Blue\");\n when Green =>\n Ada.Text_IO.Put_Line (\"Green\");\n end case;\n\n case K1 is\n when Blue =>\n Ada.Text_IO.Put_Line (\"Blue\");\n when Green =>\n Ada.Text_IO.Put_Line (\"Green\");\n when Red =>\n Ada.Text_IO.Put_Line (\"Red\");\n end case;\nend Main;\n"
141+
"text": "\nwith Ada.Text_IO;\n\nprocedure Main is\n type Kind is (Red, Blue, Green);\n K, K1 : Kind := Red;\nbegin\n case K is\n when Red =>\n Ada.Text_IO.Put_Line (\"Red\");\n when Blue =>\n Ada.Text_IO.Put_Line (\"Blue\");\n when Green =>\n Ada.Text_IO.Put_Line (\"Green\");\n end case;\n\n case K1 is\n when Blue =>\n Ada.Text_IO.Put_Line (\"Blue\");\n when Red =>\n Ada.Text_IO.Put_Line (\"Red\");\n when Green =>\n Ada.Text_IO.Put_Line (\"Green\");\n end case;\nend Main;\n"
142142
}
143143
}
144144
},
@@ -358,6 +358,32 @@
358358
}
359359
]
360360
}
361+
},
362+
{
363+
"title": "Sort Cases by Alphabetical Order",
364+
"kind": "refactor.extract",
365+
"command": {
366+
"title": "",
367+
"command": "als-refactor-sort-case-alphabetical",
368+
"arguments": [
369+
{
370+
"context_id": "$URI{default.gpr}",
371+
"location": {
372+
"uri": "$URI{main.adb}",
373+
"range": {
374+
"start": {
375+
"line": 16,
376+
"character": 3
377+
},
378+
"end": {
379+
"line": 16,
380+
"character": 3
381+
}
382+
}
383+
}
384+
}
385+
]
386+
}
361387
}
362388
]
363389
}
@@ -394,65 +420,52 @@
394420
},
395421
"wait": [
396422
{
397-
"id": 3,
398-
"method": "workspace/applyEdit",
399-
"params": {
400-
"label": "Sort Cases by Declaration Order",
401-
"edit": {
402-
"documentChanges": [
423+
"id": 3,
424+
"jsonrpc": "2.0",
425+
"method": "workspace/applyEdit",
426+
"params": {
427+
"edit": {
428+
"documentChanges": [
429+
{
430+
"edits": [
403431
{
404-
"textDocument": {
405-
"uri": "$URI{main.adb}",
406-
"version": 0
407-
},
408-
"edits": [
409-
{
410-
"range": {
411-
"start": {
412-
"line": 17,
413-
"character": 6
414-
},
415-
"end": {
416-
"line": 18,
417-
"character": 39
418-
}
419-
},
420-
"newText": "when Red =>\n Ada.Text_IO.Put_Line (\"Red\");",
421-
"annotationId": ""
422-
},
423-
{
424-
"range": {
425-
"start": {
426-
"line": 19,
427-
"character": 6
428-
},
429-
"end": {
430-
"line": 20,
431-
"character": 40
432-
}
433-
},
434-
"newText": "when Blue =>\n Ada.Text_IO.Put_Line (\"Blue\");",
435-
"annotationId": ""
436-
},
437-
{
438-
"range": {
439-
"start": {
440-
"line": 21,
441-
"character": 6
442-
},
443-
"end": {
444-
"line": 22,
445-
"character": 38
446-
}
447-
},
448-
"newText": "when Green =>\n Ada.Text_IO.Put_Line (\"Green\");",
449-
"annotationId": ""
450-
}
451-
]
432+
"annotationId": "",
433+
"newText": "when Red =>\n Ada.Text_IO.Put_Line (\"Red\");",
434+
"range": {
435+
"end": {
436+
"character": 39,
437+
"line": 18
438+
},
439+
"start": {
440+
"character": 6,
441+
"line": 17
442+
}
443+
}
444+
},
445+
{
446+
"annotationId": "",
447+
"newText": "when Blue =>\n Ada.Text_IO.Put_Line (\"Blue\");",
448+
"range": {
449+
"end": {
450+
"character": 38,
451+
"line": 20
452+
},
453+
"start": {
454+
"character": 6,
455+
"line": 19
456+
}
457+
}
452458
}
453-
]
454-
}
455-
}
459+
],
460+
"textDocument": {
461+
"uri": "$URI{main.adb}",
462+
"version": 0
463+
}
464+
}
465+
]
466+
},
467+
"label": "Sort Cases by Declaration Order"
468+
}
456469
},
457470
{
458471
"id": 9,

0 commit comments

Comments
 (0)