Skip to content

Commit 9550e40

Browse files
committed
Merge branch 'als_1614' into 'master'
Fixing auto-import command. See merge request eng/ide/ada_language_server!2007
2 parents 1b62ead + b4836ff commit 9550e40

File tree

20 files changed

+363
-35
lines changed

20 files changed

+363
-35
lines changed

source/ada/lsp-ada_completions.adb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ package body LSP.Ada_Completions is
116116
Context : LSP.Ada_Contexts.Context;
117117
Document : LSP.Ada_Documents.Document;
118118
Sloc : Langkit_Support.Slocs.Source_Location;
119+
Token : Libadalang.Common.Token_Reference;
119120
Node : Libadalang.Analysis.Ada_Node;
120121
Names : Completion_Maps.Map;
121122
Named_Notation_Threshold : Natural;
@@ -131,6 +132,10 @@ package body LSP.Ada_Completions is
131132
Seen : String_Sets.Set;
132133
-- Set of found visible names in canonical form
133134
Length : constant Natural := Natural (Names.Length);
135+
From : constant Langkit_Support.Slocs.Source_Location :=
136+
Langkit_Support.Slocs.Start_Sloc
137+
(Libadalang.Common.Sloc_Range (Libadalang.Common.Data (Token)));
138+
134139
begin
135140

136141
-- Write Result in two pases. Firstly append all visible names and
@@ -166,6 +171,7 @@ package body LSP.Ada_Completions is
166171
(Handler => Handler,
167172
Context => Context,
168173
Sloc => Sloc,
174+
From => From,
169175
Node => Node,
170176
BD => Name.P_Basic_Decl,
171177
Label => Label,

source/ada/lsp-ada_completions.ads

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ package LSP.Ada_Completions is
103103
Context : LSP.Ada_Contexts.Context;
104104
Document : LSP.Ada_Documents.Document;
105105
Sloc : Langkit_Support.Slocs.Source_Location;
106+
Token : Libadalang.Common.Token_Reference;
106107
Node : Libadalang.Analysis.Ada_Node;
107108
Names : Completion_Maps.Map;
108109
Named_Notation_Threshold : Natural;

source/ada/lsp-ada_documents.adb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ package body LSP.Ada_Documents is
107107
Handler : in out LSP.Ada_Handlers.Message_Handler;
108108
Context : LSP.Ada_Contexts.Context;
109109
Sloc : Langkit_Support.Slocs.Source_Location;
110+
From : Langkit_Support.Slocs.Source_Location;
110111
Node : Libadalang.Analysis.Ada_Node;
111112
BD : Libadalang.Analysis.Basic_Decl;
112113
Label : VSS.Strings.Virtual_String;
@@ -276,7 +277,7 @@ package body LSP.Ada_Documents is
276277
(Context => Context,
277278
Where =>
278279
((uri => Document.URI),
279-
Document.To_LSP_Position (Sloc)),
280+
Document.To_LSP_Position (From)),
280281
With_Clause => Missing_Unit_Name,
281282
Prefix => Missing_Qualifier);
282283

@@ -875,14 +876,12 @@ package body LSP.Ada_Documents is
875876
return Token;
876877
end Completion_Token;
877878
begin
878-
Sloc := Self.To_Source_Location (Position);
879+
Sloc := Self.To_Source_Location (Position);
879880
Token := Completion_Token (Sloc);
880881
declare
881882
From : constant Langkit_Support.Slocs.Source_Location :=
882883
Langkit_Support.Slocs.Start_Sloc
883-
(Libadalang.Common.Sloc_Range
884-
(Libadalang.Common.Data (Token)));
885-
884+
(Libadalang.Common.Sloc_Range (Libadalang.Common.Data (Token)));
886885
Root : constant Libadalang.Analysis.Ada_Node :=
887886
Self.Unit (Context).Root;
888887
begin

source/ada/lsp-ada_documents.ads

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ package LSP.Ada_Documents is
246246
Handler : in out LSP.Ada_Handlers.Message_Handler;
247247
Context : LSP.Ada_Contexts.Context;
248248
Sloc : Langkit_Support.Slocs.Source_Location;
249+
From : Langkit_Support.Slocs.Source_Location;
249250
Node : Libadalang.Analysis.Ada_Node;
250251
BD : Libadalang.Analysis.Basic_Decl;
251252
Label : VSS.Strings.Virtual_String;

source/ada/lsp-ada_handlers.adb

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -924,21 +924,23 @@ package body LSP.Ada_Handlers is
924924
return;
925925
end if;
926926

927-
for Suggestion of Import_Suggestions loop
928-
declare
929-
Name_Location : constant LSP.Structures.Location :=
930-
LSP.Utils.Get_Node_Location (Name);
931-
Command :
932-
LSP.Ada_Handlers.Refactor.Auto_Import.Command;
927+
declare
928+
Name_Location : constant LSP.Structures.Location :=
929+
LSP.Utils.Get_Node_Location (Name);
930+
begin
931+
for Suggestion of Import_Suggestions loop
932+
declare
933+
Command : LSP.Ada_Handlers.Refactor.Auto_Import.Command;
933934

934-
begin
935-
Command.Append_Suggestion
936-
(Context => Context,
937-
Where => Name_Location,
938-
Commands_Vector => Result,
939-
Suggestion => Suggestion);
940-
end;
941-
end loop;
935+
begin
936+
Command.Append_Suggestion
937+
(Context => Context,
938+
Where => Name_Location,
939+
Commands_Vector => Result,
940+
Suggestion => Suggestion);
941+
end;
942+
end loop;
943+
end;
942944

943945
if not Import_Suggestions.Is_Empty then
944946
Found := True;
@@ -1625,6 +1627,7 @@ package body LSP.Ada_Handlers is
16251627
Context => Context.all,
16261628
Document => Document.all,
16271629
Sloc => Sloc,
1630+
Token => Token,
16281631
Node => Node,
16291632
Names => Names,
16301633
Named_Notation_Threshold =>

testsuite/ada_lsp/aggregate.runtime_completion/test.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
},
172172
"position": {
173173
"line": 3,
174-
"character": 5
174+
"character": 3
175175
}
176176
},
177177
"import": "common_pack",
@@ -302,7 +302,7 @@
302302
},
303303
"position": {
304304
"line": 3,
305-
"character": 5
305+
"character": 3
306306
}
307307
},
308308
"import": "common_pack",
@@ -341,7 +341,7 @@
341341
"qualifier": "common_pack",
342342
"where": {
343343
"position": {
344-
"character": 5,
344+
"character": 3,
345345
"line": 3
346346
},
347347
"textDocument": {
@@ -386,7 +386,7 @@
386386
"qualifier": "common_pack",
387387
"where": {
388388
"position": {
389-
"character": 5,
389+
"character": 3,
390390
"line": 3
391391
},
392392
"textDocument": {
@@ -476,7 +476,7 @@
476476
},
477477
"position": {
478478
"line": 4,
479-
"character": 9
479+
"character": 3
480480
}
481481
},
482482
"import": "Ada.Strings.Unbounded.Text_IO",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package A is
2+
LFtip : constant String := "test";
3+
end A;
Lines changed: 3 additions & 0 deletions
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;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
with Ada.Text_IO;
2+
With A;
3+
4+
procedure Main is
5+
begin
6+
Ada.Text_IO.Put (LFtip);
7+
end Main;

0 commit comments

Comments
 (0)