Skip to content

Commit 41f417a

Browse files
committed
T826-026 Correction for cancelling Workspace_Symbols_Request
1 parent 0c9e5a0 commit 41f417a

9 files changed

+44
-27
lines changed

source/ada/lsp-ada_completions.adb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ package body LSP.Ada_Completions is
102102
end loop;
103103
end Write_Completions;
104104

105-
-------------------
106-
-- Write_Symbols --
107-
-------------------
105+
---------------------------
106+
-- Generic_Write_Symbols --
107+
---------------------------
108108

109-
procedure Write_Symbols
109+
procedure Generic_Write_Symbols
110110
(Names : Completion_Maps.Map;
111111
Result : in out LSP.Messages.Symbol_Vector) is
112112
begin
@@ -139,6 +139,6 @@ package body LSP.Ada_Completions is
139139
exit when Has_Been_Canceled;
140140
end;
141141
end loop;
142-
end Write_Symbols;
142+
end Generic_Write_Symbols;
143143

144144
end LSP.Ada_Completions;

source/ada/lsp-ada_completions.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ package LSP.Ada_Completions is
9292

9393
generic
9494
with function Has_Been_Canceled return Boolean;
95-
procedure Write_Symbols
95+
procedure Generic_Write_Symbols
9696
(Names : Completion_Maps.Map;
9797
Result : in out LSP.Messages.Symbol_Vector);
9898

source/ada/lsp-ada_contexts.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ package LSP.Ada_Contexts is
232232
(Self : Context;
233233
Pattern : LSP.Search.Search_Pattern'Class;
234234
Only_Public : Boolean;
235-
Callback : not null access procedure
235+
Callback : not null access procedure
236236
(File : GNATCOLL.VFS.Virtual_File;
237237
Name : Libadalang.Analysis.Defining_Name;
238238
Stop : in out Boolean));

source/ada/lsp-ada_documents.adb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,6 +2018,7 @@ package body LSP.Ada_Documents is
20182018
Pattern : LSP.Search.Search_Pattern'Class;
20192019
Limit : Ada.Containers.Count_Type;
20202020
Only_Public : Boolean;
2021+
Canceled : access function return Boolean;
20212022
Result : in out LSP.Ada_Completions.Completion_Maps.Map)
20222023
is
20232024
use type LSP.Messages.Search_Kind;
@@ -2121,19 +2122,23 @@ package body LSP.Ada_Documents is
21212122
then
21222123
Insert (Item);
21232124
end if;
2125+
2126+
exit when Canceled.all;
21242127
end loop;
21252128

21262129
elsif Pattern.Match (Symbol_Maps.Key (Cursor)) then
21272130
-- Symbol_Cache is case insensitive so if the key is matched
21282131
-- this means that all elements are also matched the pattern
21292132
for Item of Self.Symbol_Cache (Cursor) loop
21302133
Insert (Item);
2134+
2135+
exit when Canceled.all;
21312136
end loop;
21322137

21332138
else
21342139
-- Symbol_Cache is ordered so we will not find any
21352140
-- matches more
2136-
exit when Use_Celling;
2141+
exit when Use_Celling or else Canceled.all;
21372142
end if;
21382143

21392144
Symbol_Maps.Next (Cursor);

source/ada/lsp-ada_documents.ads

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ package LSP.Ada_Documents is
147147
Pattern : LSP.Search.Search_Pattern'Class;
148148
Limit : Ada.Containers.Count_Type;
149149
Only_Public : Boolean;
150+
Canceled : access function return Boolean;
150151
Result : in out LSP.Ada_Completions.Completion_Maps.Map);
151152
-- See Contexts.Get_Any_Symbol
152153

source/ada/lsp-ada_handlers-invisibles.adb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ package body LSP.Ada_Handlers.Invisibles is
8282
then Libadalang.Common.Previous (Token, True)
8383
else Token);
8484

85+
function Dummy_Canceled return Boolean is (False);
86+
8587
begin
8688
if Libadalang.Common.Kind (Dot_Token) = Ada_Dot then
8789
-- Don't provide completion after a dot
@@ -140,6 +142,7 @@ package body LSP.Ada_Handlers.Invisibles is
140142
Pattern,
141143
Limit,
142144
True,
145+
Dummy_Canceled'Access,
143146
Names);
144147
end loop;
145148
end;

source/ada/lsp-ada_handlers.adb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ with LSP.Messages.Client_Requests;
6060
with LSP.Messages.Server_Notifications;
6161
with LSP.Servers.FS_Watch;
6262
with LSP.Types; use LSP.Types;
63+
with LSP.Generic_Cancel_Check;
6364

6465
with Langkit_Support.Slocs;
6566
with Langkit_Support.Text;
@@ -3740,23 +3741,13 @@ package body LSP.Ada_Handlers is
37403741
Name : Libadalang.Analysis.Defining_Name;
37413742
Stop : in out Boolean);
37423743

3743-
function Has_Been_Canceled return Boolean;
3744-
3745-
procedure Write_Symbols is
3746-
new LSP.Ada_Completions.Write_Symbols (Has_Been_Canceled);
3747-
3748-
Count : Cancel_Countdown := 0;
37493744
Names : LSP.Ada_Completions.Completion_Maps.Map;
37503745

3751-
-----------------------
3752-
-- Has_Been_Canceled --
3753-
-----------------------
3746+
package Canceled is new LSP.Generic_Cancel_Check (Request, 127);
37543747

3755-
function Has_Been_Canceled return Boolean is
3756-
begin
3757-
Count := Count - 1;
3758-
return Count = 0 and then Request.Canceled;
3759-
end Has_Been_Canceled;
3748+
procedure Write_Symbols is
3749+
new LSP.Ada_Completions.Generic_Write_Symbols
3750+
(Canceled.Has_Been_Canceled);
37603751

37613752
--------------------------
37623753
-- On_Inaccessible_Name --
@@ -3778,8 +3769,9 @@ package body LSP.Ada_Handlers is
37783769
Is_Visible => False,
37793770
Use_Snippets => False,
37803771
Pos => <>));
3781-
Stop := Has_Been_Canceled;
37823772
end if;
3773+
3774+
Stop := Canceled.Has_Been_Canceled;
37833775
end On_Inaccessible_Name;
37843776

37853777
Pattern : constant Search_Pattern'Class := Build
@@ -3802,7 +3794,9 @@ package body LSP.Ada_Handlers is
38023794
Only_Public => False,
38033795
Callback => On_Inaccessible_Name'Access);
38043796

3805-
exit when Request.Canceled;
3797+
if Canceled.Has_Been_Canceled then
3798+
return Response;
3799+
end if;
38063800
end loop;
38073801

38083802
for Doc of Self.Open_Documents loop
@@ -3815,8 +3809,13 @@ package body LSP.Ada_Handlers is
38153809
Pattern,
38163810
Ada.Containers.Count_Type'Last,
38173811
False,
3812+
Canceled.Has_Been_Canceled'Access,
38183813
Names);
38193814
end;
3815+
3816+
if Canceled.Has_Been_Canceled then
3817+
return Response;
3818+
end if;
38203819
end loop;
38213820

38223821
Write_Symbols (Names, Response.result);

source/server/lsp-generic_cancel_check.adb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,26 @@ package body LSP.Generic_Cancel_Check is
2020
Count : Natural := Max_Skip_Count;
2121
-- Counter to restrict frequency of Request.Canceled checks
2222

23+
Is_Canceled : Boolean := False;
24+
2325
-----------------------
2426
-- Has_Been_Canceled --
2527
-----------------------
2628

2729
function Has_Been_Canceled return Boolean is
2830
begin
31+
if Is_Canceled then
32+
return True;
33+
end if;
34+
2935
Count := Count - 1;
3036

3137
if Count = 0 then
32-
Count := Max_Skip_Count;
33-
return Request.Canceled;
38+
Count := Max_Skip_Count;
39+
Is_Canceled := Request.Canceled;
40+
41+
return Is_Canceled;
42+
3443
else
3544
return False;
3645
end if;

source/server/lsp-generic_cancel_check.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
with LSP.Messages.Server_Requests;
2424

2525
generic
26-
Request : in out LSP.Messages.Server_Requests.Server_Request'Class;
26+
Request : LSP.Messages.Server_Requests.Server_Request'Class;
2727
-- A request to check cancelation
2828
Max_Skip_Count : Natural;
2929
-- How much checks to skip before make a real atomic flag check

0 commit comments

Comments
 (0)