Skip to content

Commit 8ea341f

Browse files
V511-027: Fix snippet for DottedName with Keywords
Add extra error recovery to detect dotted names even when having Obj.XXX and XXX a keyword (for exemple Obj.Loop or Obj.Do) Add a test.
1 parent 23a61ea commit 8ea341f

File tree

6 files changed

+412
-1
lines changed

6 files changed

+412
-1
lines changed

source/ada/lsp-ada_completions-names.adb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ package body LSP.Ada_Completions.Names is
3939
is
4040
use all type Libadalang.Analysis.Base_Id;
4141
use all type Libadalang.Common.Ada_Node_Kind_Type;
42+
use type Libadalang.Common.Token_Kind;
4243

4344
Parent : Libadalang.Analysis.Ada_Node;
4445
-- The parent of the node to complete.
@@ -50,6 +51,21 @@ package body LSP.Ada_Completions.Names is
5051

5152
Use_Snippets : Boolean := Self.Snippets_Enabled;
5253

54+
-- Error recovery for Obj.XXX with XXX a keyword => LAL will often
55+
-- consider it as:
56+
-- - CallStmt
57+
-- - Dotted_Name
58+
-- - ErrorStmt/LoopStmt/etc.
59+
Error_Dotted_Recovery : constant Boolean :=
60+
Libadalang.Analysis.Is_Keyword
61+
(Token => Token,
62+
Version => Libadalang.Common.Ada_2012)
63+
and then
64+
Libadalang.Common.Kind
65+
(Libadalang.Common.Data
66+
(Libadalang.Common.Previous
67+
(Token, Exclude_Trivia => True)))
68+
= Libadalang.Common.Ada_Dot;
5369
begin
5470
-- Get the outermost dotted name of which node is a prefix, so that when
5571
-- completing in a situation such as the following:
@@ -172,7 +188,7 @@ package body LSP.Ada_Completions.Names is
172188

173189
Names.Include
174190
(DN.P_Canonical_Part,
175-
(Is_Dot_Call (Item),
191+
(Error_Dotted_Recovery or else Is_Dot_Call (Item),
176192
Is_Visible (Item),
177193
Use_Snippets,
178194
Completion_Count,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package Bar is
2+
3+
type My_Int is tagged record
4+
A : Integer;
5+
end record;
6+
7+
procedure Do_Nothing (Obj : My_Int; A :Integer; B : Integer) is null;
8+
9+
end Bar;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project Default is
2+
3+
for Languages use ("Ada");
4+
for Main use ("main.adb");
5+
end Default;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
with Bar; use Bar;
2+
with Ada.Text_IO;
3+
4+
procedure Main is
5+
Obj : My_Int := (A => 10);
6+
begin
7+
Obj.
8+
end Main;

0 commit comments

Comments
 (0)