Skip to content

Commit 6dbe48a

Browse files
author
mergerepo
committed
Merge remote branch 'origin/master' into edge
(no-precommit-check no-tn-check)
2 parents 9740cf2 + 0c9e5a0 commit 6dbe48a

File tree

13 files changed

+451
-47
lines changed

13 files changed

+451
-47
lines changed

source/ada/lsp-ada_contexts.adb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,8 @@ package body LSP.Ada_Contexts is
841841
procedure Index_File
842842
(Self : in out Context;
843843
File : GNATCOLL.VFS.Virtual_File;
844-
Reparse : Boolean := True)
844+
Reparse : Boolean := True;
845+
PLE : Boolean := True)
845846
is
846847
Unit : constant Libadalang.Analysis.Analysis_Unit :=
847848
Self.LAL_Context.Get_From_File
@@ -850,34 +851,32 @@ package body LSP.Ada_Contexts is
850851
Reparse => Reparse);
851852
begin
852853
Self.Source_Files.Index_File (File, Unit);
854+
855+
if PLE then
856+
Libadalang.Analysis.Populate_Lexical_Env (Unit);
857+
end if;
853858
end Index_File;
854859

855860
--------------------
856861
-- Index_Document --
857862
--------------------
858863

859864
procedure Index_Document
860-
(Self : Context;
865+
(Self : in out Context;
861866
Document : in out LSP.Ada_Documents.Document)
862867
is
863-
File : constant Ada.Strings.UTF_Encoding.UTF_8_String :=
868+
Filename : constant Ada.Strings.UTF_Encoding.UTF_8_String :=
864869
Self.URI_To_File (Document.URI);
865-
Unit : Libadalang.Analysis.Analysis_Unit;
866870
begin
867-
Document.Reset_Symbol_Cache;
868871
-- Reset cache of symbols to avoid access to stale references
872+
Document.Reset_Symbol_Cache;
869873

870-
-- Preprocess the buffer
871-
Unit := Self.LAL_Context.Get_From_File
872-
(Filename => File,
873-
Charset => Ada.Strings.Unbounded.To_String (Self.Charset),
874-
Reparse => True);
875-
876-
-- After creating an analysis unit, populate the lexical env with it:
877-
-- we do this to allow Libadalang to do some work in reaction to
878-
-- a file being open in the IDE, in order to speed up the response
879-
-- to user queries.
880-
Libadalang.Analysis.Populate_Lexical_Env (Unit);
874+
-- Index the file, calling Populate_Lexical_Env on it to speed up the
875+
-- response to user queries.
876+
Self.Index_File
877+
(File => Create_From_UTF8 (Filename),
878+
Reparse => True,
879+
PLE => True);
881880
end Index_Document;
882881

883882
-------------

source/ada/lsp-ada_contexts.ads

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,15 @@ package LSP.Ada_Contexts is
190190
procedure Index_File
191191
(Self : in out Context;
192192
File : GNATCOLL.VFS.Virtual_File;
193-
Reparse : Boolean := True);
193+
Reparse : Boolean := True;
194+
PLE : Boolean := True);
194195
-- Index the given file. This translates to refreshing the Libadalang
195196
-- Analysis_Unit associated to it.
197+
-- If PLE is True, Populate_Lexical_Env is called at the end, which will
198+
-- increase the speed of semantic requests.
196199

197200
procedure Index_Document
198-
(Self : Context;
201+
(Self : in out Context;
199202
Document : in out LSP.Ada_Documents.Document);
200203
-- Index/reindex the given document in this context
201204

source/ada/lsp-ada_handlers-invisibles.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ package body LSP.Ada_Handlers.Invisibles is
9797

9898
if Node.Is_Null or else
9999
(not Node.Parent.Is_Null and then Node.Parent.Kind in
100-
Libadalang.Common.Ada_Defining_Name_Range)
100+
Libadalang.Common.Ada_Defining_Name_Range
101+
| Libadalang.Common.Ada_Dotted_Name_Range)
101102
then
102103
return;
103104
end if;

source/ada/lsp-ada_handlers.adb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ package body LSP.Ada_Handlers is
8989
Notifications_For_Imprecise : constant GNATCOLL.Traces.Trace_Handle :=
9090
GNATCOLL.Traces.Create ("ALS.NOTIFICATIONS_FOR_IMPRECISE_NAVIGATION",
9191
GNATCOLL.Traces.Off);
92-
-- Whether to send notifications to the client for "imprecise"
93-
-- navigation operations.
92+
93+
Runtime_Indexing : constant GNATCOLL.Traces.Trace_Handle :=
94+
GNATCOLL.Traces.Create ("ALS.RUNTIME_INDEXING",
95+
GNATCOLL.Traces.On);
96+
-- Trace to enable/disable runtime indexing. Useful for the testsuite.
9497

9598
Is_Parent : constant LSP.Messages.AlsReferenceKind_Set :=
9699
(Is_Server_Side => True,
@@ -3373,12 +3376,29 @@ package body LSP.Ada_Handlers is
33733376
procedure Mark_Source_Files_For_Indexing (Self : access Message_Handler) is
33743377
begin
33753378
Self.Files_To_Index.Clear;
3379+
3380+
-- Mark all the project's source files
33763381
for C of Self.Contexts.Each_Context loop
33773382
for F in C.List_Files loop
33783383
Self.Files_To_Index.Include
33793384
(LSP.Ada_File_Sets.File_Sets.Element (F));
33803385
end loop;
33813386
end loop;
3387+
3388+
if Runtime_Indexing.Is_Active then
3389+
-- Mark all the predefined sources too (runtime)
3390+
for F in Self.Project_Predefined_Sources.Iterate loop
3391+
declare
3392+
File : GNATCOLL.VFS.Virtual_File renames
3393+
LSP.Ada_File_Sets.File_Sets.Element (F);
3394+
begin
3395+
for Context of Self.Contexts_For_File (File) loop
3396+
Self.Files_To_Index.Include (File);
3397+
end loop;
3398+
end;
3399+
end loop;
3400+
end if;
3401+
33823402
Self.Total_Files_Indexed := 0;
33833403
Self.Total_Files_To_Index := Positive'Max
33843404
(1, Natural (Self.Files_To_Index.Length));
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018-2021, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
18+
package body LSP.Generic_Cancel_Check is
19+
20+
Count : Natural := Max_Skip_Count;
21+
-- Counter to restrict frequency of Request.Canceled checks
22+
23+
-----------------------
24+
-- Has_Been_Canceled --
25+
-----------------------
26+
27+
function Has_Been_Canceled return Boolean is
28+
begin
29+
Count := Count - 1;
30+
31+
if Count = 0 then
32+
Count := Max_Skip_Count;
33+
return Request.Canceled;
34+
else
35+
return False;
36+
end if;
37+
end Has_Been_Canceled;
38+
39+
end LSP.Generic_Cancel_Check;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018-2021, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
--
18+
-- Each server request has an atomic flag to inform the handler that
19+
-- the request has been canceled. But, under a havy load, a frequent atomic
20+
-- checking cound generate overhead. This package provides a function to
21+
-- avoid an extra overhread by reducing atomic flag check frequency.
22+
23+
with LSP.Messages.Server_Requests;
24+
25+
generic
26+
Request : in out LSP.Messages.Server_Requests.Server_Request'Class;
27+
-- A request to check cancelation
28+
Max_Skip_Count : Natural;
29+
-- How much checks to skip before make a real atomic flag check
30+
31+
package LSP.Generic_Cancel_Check is
32+
33+
function Has_Been_Canceled return Boolean
34+
with Inline;
35+
36+
end LSP.Generic_Cancel_Check;

source/tester/tester-tests.adb

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ package body Tester.Tests is
3939
type Command_Kind is (Start, Stop, Send, Shell, Comment);
4040

4141
procedure Do_Start
42-
(Self : in out Test'Class);
42+
(Self : in out Test'Class;
43+
Command : GNATCOLL.JSON.JSON_Value);
4344

4445
procedure Do_Stop
4546
(Self : in out Test'Class;
@@ -53,10 +54,11 @@ package body Tester.Tests is
5354
(Self : in out Test'Class;
5455
Command : GNATCOLL.JSON.JSON_Value);
5556

56-
function Wait_Factor return Integer;
57-
-- Return the factor to multiply the delays with - useful for valgrind
58-
-- runs. This is an integer read from the environment variable
59-
-- $ALS_WAIT_FACTOR if it is defined.
57+
function Wait_Factor (Command : GNATCOLL.JSON.JSON_Value) return Integer;
58+
-- Return the factor to multiply the delays with - useful for valgrind runs
59+
-- or commands that take longer time.
60+
-- This is an integer read from either the "waitFactor" field of Command
61+
-- (if any) or the $ALS_WAIT_FACTOR environment variable (if any).
6062

6163
function Is_Has_Pattern (List : GNATCOLL.JSON.JSON_Array) return Boolean;
6264
-- Check if List in form of ["<HAS>", item1, item2, ...]
@@ -124,6 +126,7 @@ package body Tester.Tests is
124126
Request : constant GNATCOLL.JSON.JSON_Value := Command.Get ("request");
125127
Wait : constant GNATCOLL.JSON.JSON_Array := Command.Get ("wait").Get;
126128
Sort : constant GNATCOLL.JSON.JSON_Value := Command.Get ("sortReply");
129+
127130
Text : constant Ada.Strings.Unbounded.Unbounded_String :=
128131
Request.Write;
129132

@@ -139,7 +142,7 @@ package body Tester.Tests is
139142
exit when GNATCOLL.JSON.Length (Self.Waits) = 0;
140143

141144
Total_Milliseconds_Waited := Total_Milliseconds_Waited + Timeout;
142-
if Total_Milliseconds_Waited > Max_Wait * Wait_Factor
145+
if Total_Milliseconds_Waited > Max_Wait * Wait_Factor (Command)
143146
and then not Self.In_Debug
144147
then
145148
declare
@@ -351,7 +354,8 @@ package body Tester.Tests is
351354
--------------
352355

353356
procedure Do_Start
354-
(Self : in out Test'Class)
357+
(Self : in out Test'Class;
358+
Command : GNATCOLL.JSON.JSON_Value)
355359
is
356360
function Program_Name (Path : String) return String;
357361
-- Return full path to an exacutable designated by Path
@@ -371,25 +375,28 @@ package body Tester.Tests is
371375
end if;
372376
end Program_Name;
373377

374-
Command_Line : constant GNAT.OS_Lib.String_Access := Getenv ("ALS");
375-
376-
Args : Spawn.String_Vectors.UTF_8_String_Vector;
378+
Command_Line : constant JSON_Array := Command.Get ("cmd").Get;
379+
ALS_Var : constant GNAT.OS_Lib.String_Access := Getenv ("ALS");
380+
ALS_Exe : constant String :=
381+
(if ALS_Var /= null then ALS_Var.all else "");
382+
Args : Spawn.String_Vectors.UTF_8_String_Vector;
377383
begin
378-
if Command_Line = null or else Command_Line.all = "" then
384+
if ALS_Exe = "" then
379385
raise Program_Error with
380386
"You must specify the language server command line in $ALS";
381387
end if;
382388

383-
declare
384-
Splits : constant Unbounded_String_Array :=
385-
Split (Command_Line.all, ' ');
386-
begin
387-
Self.Set_Program (Program_Name (To_String (Splits (Splits'First))));
389+
-- Set the program using $ALS env variable
390+
Self.Set_Program (Program_Name (ALS_Exe));
388391

389-
for J in Splits'First + 1 .. Splits'Last loop
390-
Args.Append (To_String (Splits (J)));
391-
end loop;
392-
end;
392+
-- Set the arguments using the 'cmd' field. Skip the first one, since
393+
-- it's "${ALS}".
394+
for J in
395+
GNATCOLL.JSON.Array_First (Command_Line) + 1 ..
396+
GNATCOLL.JSON.Length (Command_Line)
397+
loop
398+
Args.Append (GNATCOLL.JSON.Get (Command_Line, J).Get);
399+
end loop;
393400

394401
Self.Set_Arguments (Args);
395402
Self.Start;
@@ -781,7 +788,7 @@ package body Tester.Tests is
781788

782789
case Kind is
783790
when Start =>
784-
Self.Do_Start;
791+
Self.Do_Start (Value);
785792
when Stop =>
786793
Self.Do_Stop (Value);
787794
when Send =>
@@ -802,7 +809,7 @@ package body Tester.Tests is
802809
select
803810
accept Cancel;
804811
or
805-
delay 20.0 * Wait_Factor;
812+
delay 20.0 * Wait_Factor (Command);
806813

807814
Ada.Text_IO.Put_Line ("Timeout on command:");
808815
Ada.Text_IO.Put_Line (Command.Write);
@@ -845,14 +852,26 @@ package body Tester.Tests is
845852
-- Wait_Factor --
846853
-----------------
847854

848-
function Wait_Factor return Integer is
849-
Factor : constant GNAT.OS_Lib.String_Access
855+
function Wait_Factor (Command : GNATCOLL.JSON.JSON_Value) return Integer is
856+
Command_Factor : constant String :=
857+
(if Command.Has_Field ("waitFactor") then
858+
Command.Get ("waitFactor")
859+
else
860+
"");
861+
Env_Factor : constant GNAT.OS_Lib.String_Access
850862
:= Getenv ("ALS_WAIT_FACTOR");
863+
Factor : constant String :=
864+
(if Command_Factor /= "" then
865+
Command_Factor
866+
elsif Env_Factor /= null then
867+
Env_Factor.all
868+
else
869+
"");
851870
begin
852-
if Factor = null or else Factor.all = "" then
871+
if Factor = "" then
853872
return 1;
854873
else
855-
return Integer'Value (Factor.all);
874+
return Integer'Value (Factor);
856875
end if;
857876
end Wait_Factor;
858877

testsuite/.als/traces.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ ALS.ALLOW_INCREMENTAL_TEXT_CHANGES=yes > inout.txt:buffer_size=0
1212

1313
# Activate navigation warnings in test mode
1414
ALS.NOTIFICATIONS_FOR_IMPRECISE_NAVIGATION=yes
15+
16+
# Disable runtime indexing for most tests
17+
ALS.RUNTIME_INDEXING=no
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
procedure Main is
3+
begin
4+
Ada.Te
5+
end Main;

0 commit comments

Comments
 (0)