Skip to content

Commit 3af8181

Browse files
committed
Merge branch 'topic/sort_deps_range' into 'master'
Take into account selection for 'sort dependencies' Closes #1355 See merge request eng/ide/ada_language_server!1566
2 parents 81035f4 + 7b8a0b6 commit 3af8181

File tree

13 files changed

+387
-16
lines changed

13 files changed

+387
-16
lines changed

source/ada/lsp-ada_handlers-refactor-sort_dependencies.adb

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2023, AdaCore --
4+
-- Copyright (C) 2023-2024, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -133,22 +133,24 @@ package body LSP.Ada_Handlers.Refactor.Sort_Dependencies is
133133

134134
Message_Handler : LSP.Ada_Handlers.Message_Handler renames
135135
LSP.Ada_Handlers.Message_Handler (Handler.all);
136+
Document : constant LSP.Ada_Documents.Document_Access :=
137+
Message_Handler.Get_Open_Document (URI => Self.Where.uri);
136138
Context : LSP.Ada_Contexts.Context renames
137139
Message_Handler.Contexts.Get (Self.Context).all;
138140
File : constant GNATCOLL.VFS.Virtual_File :=
139141
Message_Handler.To_File (Self.Where.uri);
140142
Analysis_Unit : constant Libadalang.Analysis.Analysis_Unit :=
141143
Context.Get_AU (File);
142-
Sloc : constant Source_Location :=
143-
(Langkit_Support.Slocs.Line_Number
144-
(Self.Where.a_range.start.line) + 1,
145-
Langkit_Support.Slocs.Column_Number
146-
(Self.Where.a_range.start.character) + 1);
144+
Where : constant Source_Location_Range :=
145+
Document.To_Source_Location_Range (Self.Where.a_range);
147146
Compilation_Unit : constant Libadalang.Analysis.Compilation_Unit :=
148-
Analysis_Unit.Root.Lookup (Sloc).P_Enclosing_Compilation_Unit;
147+
Analysis_Unit
148+
.Root
149+
.Lookup (Where.Start_Sloc)
150+
.P_Enclosing_Compilation_Unit;
151+
Sorter : constant Dependencies_Sorter :=
152+
Create_Dependencies_Sorter (Compilation_Unit, Where);
149153

150-
Sorter : constant Dependencies_Sorter :=
151-
Create_Dependencies_Sorter (Compilation_Unit);
152154
begin
153155
Edits := Sorter.Refactor (null);
154156
end Refactor;

source/ada/lsp-ada_handlers.adb

+2-4
Original file line numberDiff line numberDiff line change
@@ -1032,10 +1032,8 @@ package body LSP.Ada_Handlers is
10321032
use LSP.Ada_Handlers.Refactor.Sort_Dependencies;
10331033
use LSP.Structures;
10341034

1035-
Location : constant Source_Location :=
1036-
(Langkit_Support.Slocs.Line_Number
1037-
(Value.a_range.start.line) + 1,
1038-
Column_Number (Value.a_range.start.character) + 1);
1035+
Location : constant Langkit_Support.Slocs.Source_Location_Range :=
1036+
Document.To_Source_Location_Range (Value.a_range);
10391037

10401038
Sort_Dependencies_Command :
10411039
LSP.Ada_Handlers.Refactor.Sort_Dependencies.Command;

testsuite/ada_lsp/refactoring_sort_dependencies/SA22-035/test.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@
252252
"character": 0
253253
},
254254
"end": {
255-
"line": 51,
256-
"character": 0
255+
"line": 47,
256+
"character": 14
257257
}
258258
},
259-
"newText": "-- Comment 1\nwith Ada.Containers; -- Comment 2\n-- Comment 3\nwith Ada.Containers.Hashed_Sets;\nwith Ada.Containers.Vectors;\nwith Ada.Strings;\nwith Ada.Strings.Hash;\n-- Comment 29\n-- Comment 30\nwith Ada.Strings.Unbounded; -- Comment 6\nwith Bar; use Bar; -- Comment 24\n-- Comment 25\npragma Warnings (Off, -- Comment 26\n Bar);\n-- Comment 16\n-- Comment 17\n-- Comment 18\nwith Foo; -- Comment 19\nuse Foo;\n-- Comment 27\n-- Comment 28\npragma Elaborate_All (Foo);\npragma Warnings (Off, -- Comment 20\n Foo); -- Comment 21\n-- Comment 22\n\nprivate with Ada.Finalization; -- Comment 4\n-- Comment 5\nprivate with Ada.Unchecked_Deallocation; -- Comment 7\n-- Comment 8\n-- Comment 9\n-- Comment 10\nprivate with Qux; -- Comment 11\npragma Elaborate (Qux); -- Comment 12\n\n-- Comment 13\n-- Comment 14\n\n-- Comment 15\n\nlimited with Corge;\n-- Comment 23\n\n"
259+
"newText": "-- Comment 1\nwith Ada.Containers; -- Comment 2\n-- Comment 3\nwith Ada.Containers.Hashed_Sets;\nwith Ada.Containers.Vectors;\nwith Ada.Strings;\nwith Ada.Strings.Hash;\n-- Comment 29\n-- Comment 30\nwith Ada.Strings.Unbounded; -- Comment 6\nwith Bar; use Bar; -- Comment 24\n-- Comment 25\npragma Warnings (Off, -- Comment 26\n Bar);\n-- Comment 16\n-- Comment 17\n-- Comment 18\nwith Foo; -- Comment 19\nuse Foo;\n-- Comment 27\n-- Comment 28\npragma Elaborate_All (Foo);\npragma Warnings (Off, -- Comment 20\n Foo); -- Comment 21\n-- Comment 22\n\nprivate with Ada.Finalization; -- Comment 4\n-- Comment 5\nprivate with Ada.Unchecked_Deallocation; -- Comment 7\n-- Comment 8\n-- Comment 9\n-- Comment 10\nprivate with Qux; -- Comment 11\npragma Elaborate (Qux); -- Comment 12\n\n-- Comment 13\n-- Comment 14\n\n-- Comment 15\n\nlimited with Corge;\n-- Comment 23"
260260
}
261261
]
262262
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package Bar is
2+
end Bar;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package Corge is
2+
end Corge;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project Default is
2+
for Main use ("main.adb");
3+
end Default;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package Foo is
2+
end Foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
with Main_Package;
2+
3+
procedure Main is
4+
begin
5+
null;
6+
end Main;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package body Main_Package is
2+
begin
3+
null;
4+
end Main_Package;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
pragma Ada_2012;
2+
3+
-- Comment 1
4+
with Ada.Containers; -- Comment 2
5+
-- Comment 3
6+
private with Ada.Finalization; -- Comment 4
7+
-- Comment 5
8+
with Ada.Strings.Unbounded; -- Comment 6
9+
private with Ada.Unchecked_Deallocation; -- Comment 7
10+
-- Comment 8
11+
12+
-- Comment 9
13+
-- Comment 10
14+
private with Qux; -- Comment 11
15+
pragma Elaborate (Qux); -- Comment 12
16+
17+
-- Comment 13
18+
-- Comment 14
19+
20+
-- Comment 15
21+
22+
-- Comment 16
23+
-- Comment 17
24+
-- Comment 18
25+
with Foo; -- Comment 19
26+
pragma Elaborate_All (Foo);
27+
pragma Warnings (Off, -- Comment 20
28+
Foo); -- Comment 21
29+
-- Comment 22
30+
31+
limited with Corge;
32+
-- Comment 23
33+
with Bar; use Bar; -- Comment 24
34+
-- Comment 25
35+
pragma Warnings (Off, -- Comment 26
36+
Bar);
37+
38+
use Foo;
39+
-- Comment 27
40+
-- Comment 28
41+
42+
with Ada.Strings;
43+
with Ada.Containers.Vectors;
44+
with Ada.Containers.Hashed_Sets;
45+
46+
with Ada.Strings.Hash;
47+
-- Comment 29
48+
-- Comment 30
49+
50+
51+
52+
package Main_Package is
53+
pragma Elaborate_Body;
54+
55+
end Main_Package;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package Qux is
2+
end Qux;

0 commit comments

Comments
 (0)