Skip to content

Commit bcceff7

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 0e6a3ee + 0a9d559 commit bcceff7

File tree

17 files changed

+528
-330
lines changed

17 files changed

+528
-330
lines changed

source/ada/lsp-ada_completions-filters.adb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,45 @@ package body LSP.Ada_Completions.Filters is
309309
return Self.Is_Comma.Value;
310310
end Is_Comma;
311311

312+
-------------------------
313+
-- Is_Open_Parenthesis --
314+
-------------------------
315+
316+
function Is_Open_Parenthesis
317+
(Self : in out Filter'Class;
318+
Exclude_Trivia : Boolean := True) return Boolean
319+
is
320+
begin
321+
if not Self.Is_Open_Parenthesis.Is_Set then
322+
declare
323+
use all type Libadalang.Common.Token_Kind;
324+
use all type Libadalang.Common.Token_Reference;
325+
326+
Token_Kind : constant Libadalang.Common.Token_Kind := Self.Token.Data.Kind;
327+
begin
328+
Self.Is_Open_Parenthesis := (True, Token_Kind = Ada_Par_Open);
329+
330+
-- The curent token is not an open parenthesis: check for the previous
331+
-- one if we are on a trivia.
332+
if not Self.Is_Open_Parenthesis.Value
333+
and then (Self.Token.Is_Trivia and then Exclude_Trivia)
334+
then
335+
declare
336+
Previous_Token :
337+
constant Libadalang.Common.Token_Reference :=
338+
Self.Token.Previous (Exclude_Trivia => True);
339+
begin
340+
Self.Is_Open_Parenthesis :=
341+
(True,
342+
Previous_Token /= Libadalang.Common.No_Token
343+
and then Previous_Token.Data.Kind =
344+
Ada_Par_Open);
345+
end;
346+
end if;
347+
end;
348+
end if;
349+
350+
return Self.Is_Open_Parenthesis.Value;
351+
end Is_Open_Parenthesis;
352+
312353
end LSP.Ada_Completions.Filters;

source/ada/lsp-ada_completions-filters.ads

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,26 @@ package LSP.Ada_Completions.Filters is
4848
function Is_Comma (Self : in out Filter'Class) return Boolean;
4949
-- Check if we complete right after ","
5050

51+
function Is_Open_Parenthesis
52+
(Self : in out Filter'Class;
53+
Exclude_Trivia : Boolean := True) return Boolean;
54+
-- Check if we complete right after "(".
55+
-- If Exclude_Trivia is True and if the current token is a trivia
56+
-- (e.g: whitespace), the first previous non-trivia token ill be
57+
-- checked too.
58+
5159
private
5260

5361
type Filter is tagged limited record
54-
Token : Libadalang.Common.Token_Reference;
55-
Node : Libadalang.Analysis.Ada_Node;
56-
Is_End_Label : LSP.Structures.Boolean_Optional;
57-
Is_Numeric_Literal : LSP.Structures.Boolean_Optional;
58-
Is_Attribute : LSP.Structures.Boolean_Optional;
59-
Is_Aspect : LSP.Structures.Boolean_Optional;
60-
Is_Semicolon : LSP.Structures.Boolean_Optional;
61-
Is_Comma : LSP.Structures.Boolean_Optional;
62+
Token : Libadalang.Common.Token_Reference;
63+
Node : Libadalang.Analysis.Ada_Node;
64+
Is_End_Label : LSP.Structures.Boolean_Optional;
65+
Is_Numeric_Literal : LSP.Structures.Boolean_Optional;
66+
Is_Attribute : LSP.Structures.Boolean_Optional;
67+
Is_Aspect : LSP.Structures.Boolean_Optional;
68+
Is_Semicolon : LSP.Structures.Boolean_Optional;
69+
Is_Comma : LSP.Structures.Boolean_Optional;
70+
Is_Open_Parenthesis : LSP.Structures.Boolean_Optional;
6271
end record;
6372

6473
end LSP.Ada_Completions.Filters;

source/ada/lsp-ada_completions-names.adb

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
with Langkit_Support.Errors;
1919

2020
with VSS.Strings;
21-
with VSS.Transformers.Caseless;
2221

2322
with LSP.Ada_Completions.Filters;
23+
with LSP.Enumerations;
24+
with LSP.Search;
25+
with LSP.Utils;
2426

2527
package body LSP.Ada_Completions.Names is
2628

@@ -114,11 +116,13 @@ package body LSP.Ada_Completions.Names is
114116
return;
115117
end if;
116118

117-
-- Don't complete numeric literals, attributes nor end labels or aspects
119+
-- Don't complete numeric literals, attributes, end labels, aspects
120+
-- or right after typing an open parenthesis
118121
if Filter.Is_Numeric_Literal
119122
or else Filter.Is_Attribute_Ref
120123
or else Filter.Is_Aspect
121124
or else Filter.Is_End_Label
125+
or else Filter.Is_Open_Parenthesis
122126
then
123127
return;
124128
end if;
@@ -156,9 +160,24 @@ package body LSP.Ada_Completions.Names is
156160

157161
declare
158162
use Libadalang.Analysis;
159-
160-
Prefix : constant VSS.Strings.Virtual_String :=
161-
VSS.Strings.To_Virtual_String (Node.Text);
163+
use Libadalang.Common;
164+
165+
Word : constant VSS.Strings.Virtual_String :=
166+
VSS.Strings.To_Virtual_String
167+
(if
168+
Libadalang.Common.Is_Trivia (Token)
169+
or else Token.Data.Kind = Libadalang.Common.Ada_Dot
170+
then ""
171+
else Libadalang.Common.Text (Token));
172+
Canonical_Prefix : constant VSS.Strings.Virtual_String :=
173+
LSP.Utils.Canonicalize (Word);
174+
Pattern : constant LSP.Search.Search_Pattern'Class :=
175+
LSP.Search.Build
176+
(Pattern => Canonical_Prefix,
177+
Case_Sensitive => False,
178+
Whole_Word => False,
179+
Negate => False,
180+
Kind => LSP.Enumerations.Start_Word_Text);
162181
Raw_Completions : constant Completion_Item_Iterator :=
163182
Dotted_Node.P_Complete;
164183

@@ -167,28 +186,22 @@ package body LSP.Ada_Completions.Names is
167186
Completion_Count : Natural := Natural (Result.items.Length);
168187
Name : VSS.Strings.Virtual_String;
169188
Underscore : constant VSS.Strings.Virtual_String := "_";
170-
171189
begin
172190
while Next (Raw_Completions, Item) loop
173191
BD := Decl (Item).As_Basic_Decl;
174192

175193
if not BD.Is_Null then
176194
for DN of BD.P_Defining_Names loop
195+
177196
Name := VSS.Strings.To_Virtual_String
178197
(DN.P_Relative_Name.Text);
179198

180199
if Name.Ends_With (Underscore) then
181200
-- Skip `root_types_` until UB30-020 is fixed.
182201
null;
183202

184-
-- If we are not completing a dotted name, filter the
185-
-- raw completion results by the node's prefix.
186-
elsif Dotted_Node.Kind in
187-
Libadalang.Common.Ada_Dotted_Name_Range
188-
or else Name.Starts_With
189-
(Prefix,
190-
VSS.Transformers.Caseless.To_Identifier_Caseless)
191-
then
203+
-- Filter the raw completion results by the node's prefix.
204+
elsif Pattern.Match (Name) then
192205
Completion_Count := Completion_Count + 1;
193206

194207
Names.Include

source/ada/lsp-ada_handlers-invisibles.adb

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18-
with GNATCOLL;
19-
with GNATCOLL.Utils;
2018
with GNATCOLL.VFS;
2119

22-
with Langkit_Support.Text;
2320
with VSS.Strings;
2421

2522
with LSP.Enumerations;
@@ -42,6 +39,8 @@ package body LSP.Ada_Handlers.Invisibles is
4239
Result : in out LSP.Structures.CompletionList)
4340
is
4441
pragma Unreferenced (Result);
42+
use all type Libadalang.Common.Token_Kind;
43+
use all type Libadalang.Common.Token_Reference;
4544
use type Ada.Containers.Count_Type;
4645

4746
procedure On_Inaccessible_Name
@@ -80,17 +79,23 @@ package body LSP.Ada_Handlers.Invisibles is
8079
end if;
8180
end On_Inaccessible_Name;
8281

83-
function Dummy_Canceled return Boolean is (False);
82+
Previous_Tok : constant Libadalang.Common.Token_Reference :=
83+
Libadalang.Common.Previous (Token, Exclude_Trivia => True);
84+
Dot_Token : constant Libadalang.Common.Token_Data_Type :=
85+
Libadalang.Common.Data
86+
(if Libadalang.Common.Is_Trivia (Token)
87+
and then Previous_Tok /= Libadalang.Common.No_Token
88+
then Previous_Tok
89+
else Token);
8490

85-
Unit_Prefix : VSS.Strings.Virtual_String;
86-
-- The unit prefix specified before the point of completion, if any
87-
-- (e.g: "Ada.Text_IO" when completing "Ada.Text_IO.").
88-
-- Used to filter invisible completion items: if there is a unit prefix,
89-
-- we want to show only the public symbols declared in this
90-
-- non-visible unit.
91+
function Dummy_Canceled return Boolean is (False);
9192

9293
begin
93-
if Filter.Is_Numeric_Literal
94+
if Libadalang.Common.Kind (Dot_Token) = Ada_Dot then
95+
-- Don't provide invisible completion after a dot: it's
96+
-- handled by the default LAL completion provider.
97+
return;
98+
elsif Filter.Is_Numeric_Literal
9499
or else Filter.Is_Attribute_Ref
95100
or else Filter.Is_Aspect
96101
or else Filter.Is_End_Label
@@ -107,6 +112,7 @@ package body LSP.Ada_Handlers.Invisibles is
107112
if Node.Is_Null or else
108113
(not Node.Parent.Is_Null and then Node.Parent.Kind in
109114
Libadalang.Common.Ada_Defining_Name_Range
115+
| Libadalang.Common.Ada_Dotted_Name_Range
110116
| Libadalang.Common.Ada_Ada_Node_List_Range)
111117
then
112118
return;
@@ -118,20 +124,6 @@ package body LSP.Ada_Handlers.Invisibles is
118124
return;
119125
end if;
120126

121-
-- We are completing a dotted-name: check if we have a unit prefix
122-
if Node.Kind in Libadalang.Common.Ada_Dotted_Name_Range then
123-
declare
124-
Prefix : constant String :=
125-
Langkit_Support.Text.To_UTF8 (Node.Text);
126-
Dot_Idx : Integer := -1;
127-
begin
128-
Dot_Idx := GNATCOLL.Utils.Find_Char (Prefix, '.');
129-
Unit_Prefix :=
130-
VSS.Strings.Conversions.To_Virtual_String
131-
(Prefix (Prefix'First .. Dot_Idx - 1));
132-
end;
133-
end if;
134-
135127
declare
136128
Word : constant VSS.Strings.Virtual_String :=
137129
VSS.Strings.To_Virtual_String
@@ -155,8 +147,7 @@ package body LSP.Ada_Handlers.Invisibles is
155147
Self.Context.Get_Any_Symbol
156148
(Pattern => Pattern,
157149
Only_Public => True,
158-
Callback => On_Inaccessible_Name'Access,
159-
Unit_Prefix => Unit_Prefix);
150+
Callback => On_Inaccessible_Name'Access);
160151

161152
for Doc of Self.Handler.Open_Documents loop
162153
Doc.Get_Any_Symbol

0 commit comments

Comments
 (0)