File tree Expand file tree Collapse file tree 16 files changed +55
-30
lines changed
U915-024.completion.invisible_snippets
U921-010.completion.no_generic_duplicates
completion.invisible.runtime
completion.lazy_computation Expand file tree Collapse file tree 16 files changed +55
-30
lines changed Original file line number Diff line number Diff line change @@ -128,7 +128,8 @@ package body LSP.Ada_Completions.Names is
128
128
(Is_Dot_Call => False,
129
129
Is_Visible => True,
130
130
Use_Snippets => Use_Snippets,
131
- Pos => 1 ));
131
+ Pos => 1 ,
132
+ Weight => 0 ));
132
133
return ;
133
134
end if ;
134
135
end if ;
@@ -174,7 +175,8 @@ package body LSP.Ada_Completions.Names is
174
175
(Is_Dot_Call (Item),
175
176
Is_Visible (Item),
176
177
Use_Snippets,
177
- Completion_Count));
178
+ Completion_Count,
179
+ Weight (Item)));
178
180
end if ;
179
181
end loop ;
180
182
end if ;
Original file line number Diff line number Diff line change @@ -99,6 +99,7 @@ package body LSP.Ada_Completions is
99
99
Is_Dot_Call => Info.Is_Dot_Call,
100
100
Is_Visible => Info.Is_Visible,
101
101
Pos => Info.Pos,
102
+ Weight => Info.Weight,
102
103
Completions_Count => Length));
103
104
end if ;
104
105
end ;
Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ package LSP.Ada_Completions is
43
43
-- for completion, since LAL can return several times the same declaration
44
44
-- and specially subprograms from generic instantiations.
45
45
46
+ subtype Completion_Item_Weight_Type is Integer range 0 .. 100 ;
47
+ -- Type representing the weight returned by LAL for each completion item.
48
+ -- Used to sort them accordingly on the client-side.
49
+
46
50
type Name_Information is record
47
51
Is_Dot_Call : Boolean;
48
52
-- True if we are dealing with a dotted call.
@@ -57,6 +61,9 @@ package LSP.Ada_Completions is
57
61
Pos : Integer := -1 ;
58
62
-- The position of the item in the fully computed completion list. Used
59
63
-- for sorting properly the items on client-side.
64
+
65
+ Weight : Completion_Item_Weight_Type := 0 ;
66
+ -- The completion item's weight. Used for sorting on the client-side.
60
67
end record ;
61
68
62
69
package Completion_Maps is new Ada.Containers.Hashed_Maps
Original file line number Diff line number Diff line change @@ -1838,6 +1838,7 @@ package body LSP.Ada_Documents is
1838
1838
Is_Dot_Call : Boolean;
1839
1839
Is_Visible : Boolean;
1840
1840
Pos : Integer;
1841
+ Weight : Completion_Item_Weight_Type;
1841
1842
Completions_Count : Natural)
1842
1843
return LSP.Messages.CompletionItem
1843
1844
is
@@ -1860,14 +1861,22 @@ package body LSP.Ada_Documents is
1860
1861
1861
1862
function Get_Sort_Text
1862
1863
(Base_Label : VSS.Strings.Virtual_String)
1863
- return VSS.Strings.Virtual_String is
1864
+ return VSS.Strings.Virtual_String
1865
+ is
1866
+ use VSS.Strings;
1864
1867
begin
1865
1868
return Sort_Text : VSS.Strings.Virtual_String do
1866
- if Pos /= -1 then
1867
- Sort_Text :=
1868
- VSS.Strings.Conversions.To_Virtual_String
1869
- (GNATCOLL.Utils.Image (Pos, Min_Width => Min_Width));
1870
- end if ;
1869
+
1870
+ Sort_Text :=
1871
+ VSS.Strings.Conversions.To_Virtual_String
1872
+ (GNATCOLL.Utils.Image
1873
+ (Value => Completion_Item_Weight_Type'Last - Weight,
1874
+ Min_Width =>
1875
+ Completion_Item_Weight_Type'Last'Img'Length - 1 )) & " &" ;
1876
+
1877
+ Sort_Text := Sort_Text &
1878
+ VSS.Strings.Conversions.To_Virtual_String
1879
+ (GNATCOLL.Utils.Image (Pos, Min_Width => Min_Width));
1871
1880
1872
1881
Sort_Text.Append (Base_Label);
1873
1882
@@ -2146,7 +2155,8 @@ package body LSP.Ada_Documents is
2146
2155
(Is_Dot_Call => False,
2147
2156
Is_Visible => False,
2148
2157
Use_Snippets => False,
2149
- Pos => <>));
2158
+ Pos => <>,
2159
+ Weight => <>));
2150
2160
end if ;
2151
2161
end Insert ;
2152
2162
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ with GNATCOLL.Traces;
33
33
with Pp.Command_Lines ;
34
34
35
35
limited with LSP.Ada_Contexts ;
36
- with LSP.Ada_Completions ;
36
+ with LSP.Ada_Completions ; use LSP.Ada_Completions;
37
37
with LSP.Ada_Highlighters ;
38
38
with LSP.Diagnostic_Sources ;
39
39
with LSP.Messages ;
@@ -252,6 +252,7 @@ package LSP.Ada_Documents is
252
252
Is_Dot_Call : Boolean;
253
253
Is_Visible : Boolean;
254
254
Pos : Integer;
255
+ Weight : Completion_Item_Weight_Type;
255
256
Completions_Count : Natural)
256
257
return LSP.Messages.CompletionItem;
257
258
-- Compute a completion item.
@@ -264,6 +265,8 @@ package LSP.Ada_Documents is
264
265
-- named notation is used for subprogram completion snippets.
265
266
-- Is_Dot_Call is used to know if we should omit the first parameter
266
267
-- when computing subprogram snippets.
268
+ -- Weight is used for sorting: items with an higher weight will be placed
269
+ -- at the top.
267
270
-- Completions_Count is the total number of completion items.
268
271
269
272
procedure Set_Completion_Item_Documentation
Original file line number Diff line number Diff line change @@ -68,7 +68,8 @@ package body LSP.Ada_Handlers.Invisibles is
68
68
(Is_Dot_Call => False,
69
69
Is_Visible => False,
70
70
Use_Snippets => False,
71
- Pos => Pos));
71
+ Pos => Pos,
72
+ Weight => <>));
72
73
73
74
Pos := Pos + 1 ;
74
75
Original file line number Diff line number Diff line change @@ -5121,7 +5121,8 @@ package body LSP.Ada_Handlers is
5121
5121
(Is_Dot_Call => False,
5122
5122
Is_Visible => False,
5123
5123
Use_Snippets => False,
5124
- Pos => <>));
5124
+ Pos => <>,
5125
+ Weight => <>));
5125
5126
end if ;
5126
5127
5127
5128
Stop := Canceled.Has_Been_Canceled;
Original file line number Diff line number Diff line change 204
204
{
205
205
"label" : " Do_Something (invisible)" ,
206
206
"kind" : 3 ,
207
- "sortText" : " ~0Do_Something" ,
207
+ "sortText" : " ~100& 0Do_Something" ,
208
208
"filterText" : " Do_Something" ,
209
209
"insertText" : " Do_Something" ,
210
210
"additionalTextEdits" : [],
Original file line number Diff line number Diff line change 244
244
{
245
245
"label" : " Primitive" ,
246
246
"kind" : 3 ,
247
- "sortText" : " 2Primitive" ,
247
+ "sortText" : " 100& 2Primitive" ,
248
248
"insertText" : " Primitive (${1:Obj : Parent})$0" ,
249
249
"insertTextFormat" : 2 ,
250
250
"additionalTextEdits" : [],
Original file line number Diff line number Diff line change 199
199
{
200
200
"label" : " Do_Something" ,
201
201
"kind" : 3 ,
202
- "sortText" : " 2Do_Something" ,
202
+ "sortText" : " 100& 2Do_Something" ,
203
203
"additionalTextEdits" : [],
204
204
"data" : {
205
205
"uri" : " $URI{main.adb}" ,
You can’t perform that action at this time.
0 commit comments