Skip to content

Commit 4c1e655

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 8564d55 + e1bf297 commit 4c1e655

File tree

9 files changed

+399
-18
lines changed

9 files changed

+399
-18
lines changed

source/ada/lsp-ada_completions-aspects.adb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
with VSS.Strings;
1919

2020
with LSP.Predefined_Completion;
21+
with LSP.Ada_Completions.Filters;
2122

2223
package body LSP.Ada_Completions.Aspects is
2324

@@ -34,28 +35,29 @@ package body LSP.Ada_Completions.Aspects is
3435
Names : in out Ada_Completions.Completion_Maps.Map;
3536
Result : in out LSP.Messages.CompletionList)
3637
is
37-
pragma Unreferenced (Filter);
3838
pragma Unreferenced (Names);
3939

4040
Parent : constant Libadalang.Analysis.Ada_Node :=
4141
(if Node.Is_Null then Node else Node.Parent);
4242
begin
43-
if not Parent.Is_Null and then
44-
Parent.Kind in Libadalang.Common.Ada_Aspect_Assoc_Range
45-
then
46-
declare
47-
Prefix : constant VSS.Strings.Virtual_String :=
48-
VSS.Strings.To_Virtual_String (Node.Text);
49-
50-
begin
43+
if Filter.Is_Aspect then
44+
if not Parent.Is_Null and then
45+
Parent.Kind in Libadalang.Common.Ada_Aspect_Assoc_Range
46+
then
47+
declare
48+
Prefix : constant VSS.Strings.Virtual_String :=
49+
VSS.Strings.To_Virtual_String (Node.Text);
50+
51+
begin
52+
LSP.Predefined_Completion.Get_Aspects
53+
(Prefix => Prefix,
54+
Result => Result.items);
55+
end;
56+
elsif Node.Kind in Libadalang.Common.Ada_Aspect_Spec_Range then
5157
LSP.Predefined_Completion.Get_Aspects
52-
(Prefix => Prefix,
58+
(Prefix => VSS.Strings.Empty_Virtual_String,
5359
Result => Result.items);
54-
end;
55-
elsif Node.Kind in Libadalang.Common.Ada_Aspect_Spec_Range then
56-
LSP.Predefined_Completion.Get_Aspects
57-
(Prefix => VSS.Strings.Empty_Virtual_String,
58-
Result => Result.items);
60+
end if;
5961
end if;
6062
end Propose_Completion;
6163

source/ada/lsp-ada_completions-filters.adb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,51 @@ package body LSP.Ada_Completions.Filters is
129129
return Self.Is_Attribute.Value;
130130
end Is_Attribute_Ref;
131131

132+
---------------
133+
-- Is_Aspect --
134+
---------------
135+
136+
function Is_Aspect (Self : in out Filter'Class) return Boolean is
137+
begin
138+
if not Self.Is_Aspect.Is_Set then
139+
declare
140+
use Libadalang.Common;
141+
142+
Token_Kind : constant Libadalang.Common.Token_Kind :=
143+
Kind (Libadalang.Common.Previous
144+
(Self.Token, Exclude_Trivia => True));
145+
Parent : Libadalang.Analysis.Ada_Node :=
146+
(if Self.Node.Is_Null then Self.Node else Self.Node.Parent);
147+
begin
148+
-- Get the outermost dotted name of which node is a prefix, so
149+
-- that when completing in a situation such as the following:
150+
--
151+
-- end Ada.Tex|
152+
-- ^ Cursor here
153+
--
154+
-- we get the DottedName node rather than just the "Tex" BaseId.
155+
-- We want the DottedName rather than the Id so as to get the
156+
-- proper completions (all elements in the "Ada" namespace).
157+
158+
while not Parent.Is_Null
159+
and then Parent.Kind = Ada_Dotted_Name
160+
loop
161+
Parent := Parent.Parent;
162+
end loop;
163+
164+
Self.Is_Aspect :=
165+
(True,
166+
Token_Kind = Ada_With and then
167+
(Self.Node.Kind in Ada_Aspect_Spec_Range
168+
or else
169+
(not Parent.Is_Null
170+
and then Parent.Kind in Ada_Aspect_Assoc_Range)));
171+
end;
172+
end if;
173+
174+
return Self.Is_Aspect.Value;
175+
end Is_Aspect;
176+
132177
------------------
133178
-- Is_Semicolon --
134179
------------------

source/ada/lsp-ada_completions-filters.ads

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ package LSP.Ada_Completions.Filters is
3939
function Is_Attribute_Ref (Self : in out Filter'Class) return Boolean;
4040
-- Check if we complete "'<attribute>" text
4141

42+
function Is_Aspect (Self : in out Filter'Class) return Boolean;
43+
-- Check if we complete an Ada aspect (e.g: "with")
44+
4245
function Is_Semicolon (Self : in out Filter'Class) return Boolean;
4346
-- Check if we complete right after ";"
4447

@@ -53,6 +56,7 @@ private
5356
Is_End_Label : LSP.Types.Optional_Boolean;
5457
Is_Numeric_Literal : LSP.Types.Optional_Boolean;
5558
Is_Attribute : LSP.Types.Optional_Boolean;
59+
Is_Aspect : LSP.Types.Optional_Boolean;
5660
Is_Semicolon : LSP.Types.Optional_Boolean;
5761
Is_Comma : LSP.Types.Optional_Boolean;
5862
end record;

source/ada/lsp-ada_completions-names.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ package body LSP.Ada_Completions.Names is
112112
return;
113113
end if;
114114

115-
-- Don't complete numeric literals, attributes nor end labels
115+
-- Don't complete numeric literals, attributes nor end labels or aspects
116116
if Filter.Is_Numeric_Literal
117117
or else Filter.Is_Attribute_Ref
118+
or else Filter.Is_Aspect
118119
or else Filter.Is_End_Label
119120
then
120121
return;

source/ada/lsp-ada_handlers-invisibles.adb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ package body LSP.Ada_Handlers.Invisibles is
8989
if Libadalang.Common.Kind (Dot_Token) = Ada_Dot then
9090
-- Don't provide completion after a dot
9191
return;
92-
elsif Filter.Is_Numeric_Literal or Filter.Is_End_Label then
93-
-- Don't provide completion in a numeric literal nor end label
92+
elsif Filter.Is_Numeric_Literal
93+
or else Filter.Is_Attribute_Ref
94+
or else Filter.Is_Aspect
95+
or else Filter.Is_End_Label
96+
then
97+
-- Don't complete numeric literals, attributes nor end labels
98+
-- or aspects
9499
return;
95100
end if;
96101

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project Default is
2+
end Default;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
procedure P is
2+
subtype Even_Integer is Integer
3+
with
4+
5+
begin
6+
null;
7+
end P;

0 commit comments

Comments
 (0)