Skip to content

Commit 14d1b16

Browse files
author
Philippe Gil
committed
Merge branch '1295-fix-als-crashes' into 'master'
Fix ALS crashes on: Closes #1295 See merge request eng/ide/ada_language_server!1500
2 parents 04fb53d + 576dcb3 commit 14d1b16

File tree

14 files changed

+443
-45
lines changed

14 files changed

+443
-45
lines changed

source/ada/lsp-ada_handlers-project_loading.adb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2018-2023, AdaCore --
4+
-- Copyright (C) 2018-2024, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -426,9 +426,7 @@ package body LSP.Ada_Handlers.Project_Loading is
426426
Self.Project_Tree.Update_Sources (With_Runtime => True);
427427

428428
exception
429-
when E : GPR2.Project_Error
430-
| GPR2.Processing_Error
431-
| GPR2.Attribute_Error =>
429+
when E : others =>
432430

433431
Self.Tracer.Trace_Exception (E);
434432

source/gpr/lsp-gpr_documents.adb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2023, AdaCore --
4+
-- Copyright (C) 2023-2024, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -171,8 +171,9 @@ package body LSP.GPR_Documents is
171171
Update_Diagnostics;
172172

173173
exception
174-
when GPR2.Project_Error | GPR2.Processing_Error
175-
| GPR2.Attribute_Error =>
174+
when E : others =>
175+
176+
Self.Tracer.Trace_Exception (E);
176177

177178
Update_Diagnostics;
178179

source/gpr/lsp-gpr_files-references.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ package body LSP.GPR_Files.References is
621621
File.Get_Referenced_GPR (Token);
622622
Referenced : File_Access;
623623
begin
624-
if Path.Exists then
624+
if Path.Is_Defined and then Path.Exists then
625625
Referenced := Parse (File.File_Provider, Path);
626626
return Referenced.Name_Token;
627627
end if;

source/gpr/lsp-gpr_files.adb

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,24 +1108,29 @@ package body LSP.GPR_Files is
11081108
File.Get_Referenced_GPR (Token.Ref);
11091109
Imported : File_Access;
11101110
begin
1111-
if Path.Exists then
1111+
if Path.Is_Defined and then Path.Exists then
11121112
File.Token_To_File_Map.Insert (Index, Path);
11131113
Imported := Parse (File.File_Provider, Path);
11141114

1115-
File.Name_To_File_Map.Insert (Imported.Name, Path);
1116-
File.Limited_Imported.Append (Imported.Name);
1117-
if not Limited_Import then
1118-
File.Imported.Append (Imported.Name);
1119-
Add_Symbol
1120-
(Token => Token,
1121-
Kind => K_Imported,
1122-
Name => Image (Imported.Name));
1123-
else
1124-
Add_Symbol
1125-
(Token => Token,
1126-
Kind => K_Imported,
1127-
Name => "limited " &
1128-
Image (Imported.Name));
1115+
if not File.Name_To_File_Map.Contains
1116+
(Imported.Name)
1117+
then
1118+
File.Name_To_File_Map.Insert
1119+
(Imported.Name, Path);
1120+
File.Limited_Imported.Append (Imported.Name);
1121+
if not Limited_Import then
1122+
File.Imported.Append (Imported.Name);
1123+
Add_Symbol
1124+
(Token => Token,
1125+
Kind => K_Imported,
1126+
Name => Image (Imported.Name));
1127+
else
1128+
Add_Symbol
1129+
(Token => Token,
1130+
Kind => K_Imported,
1131+
Name => "limited " &
1132+
Image (Imported.Name));
1133+
end if;
11291134
end if;
11301135
else
11311136
declare
@@ -1253,7 +1258,10 @@ package body LSP.GPR_Files is
12531258
end;
12541259
end loop;
12551260
Project_Name := Name;
1256-
if Extends and then Extended_Path.Exists then
1261+
if Extends
1262+
and then Extended_Path.Is_Defined
1263+
and then Extended_Path.Exists
1264+
then
12571265
declare
12581266
Extended : File_Access;
12591267
begin
@@ -1449,11 +1457,15 @@ package body LSP.GPR_Files is
14491457
function Get_Referenced_GPR
14501458
(File : LSP.GPR_Files.File;
14511459
Token : Gpr_Parser.Common.Token_Reference) return Path_Name.Object is
1460+
Name : constant String := Remove_Quote (To_String (Token));
14521461
begin
1453-
return GPR2.Project.Create
1454-
(GPR2.Filename_Type
1455-
(Remove_Quote (To_String (Token))),
1456-
File.Search_Paths);
1462+
if Name'Length > 0 then
1463+
return GPR2.Project.Create
1464+
(GPR2.Filename_Type (Name),
1465+
File.Search_Paths);
1466+
else
1467+
return Path_Name.Undefined;
1468+
end if;
14571469
end Get_Referenced_GPR;
14581470

14591471
end LSP.GPR_Files;

source/tester/tester-macros.adb

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2018-2023, AdaCore --
4+
-- Copyright (C) 2018-2024, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -35,13 +35,18 @@ package body Tester.Macros is
3535
Test_Dir : String) return GNATCOLL.JSON.JSON_Value;
3636
-- Expand recursively
3737

38+
function Expand_FILE
39+
(Path : String;
40+
Test_Dir : String) return String;
41+
-- Turn Path into file absolute path
42+
3843
function Expand_URI
3944
(Path : String;
4045
Test_Dir : String) return String;
4146
-- Turn Path into URI with scheme 'file://'
4247

4348
Pattern : constant GNAT.Regpat.Pattern_Matcher :=
44-
GNAT.Regpat.Compile ("\${([\w]+)}|\$URI{([^}]*)}");
49+
GNAT.Regpat.Compile ("\${([\w]+)}|\$URI{([^}]*)}|\$FILE{([^}]*)}");
4550

4651
Replace_Slash : constant Ada.Strings.Maps.Character_Mapping :=
4752
Ada.Strings.Maps.To_Mapping
@@ -91,7 +96,7 @@ package body Tester.Macros is
9196
begin
9297
while Next < Text'Length loop
9398
declare
94-
Found : GNAT.Regpat.Match_Array (0 .. 2);
99+
Found : GNAT.Regpat.Match_Array (0 .. 3);
95100
begin
96101
GNAT.Regpat.Match (Pattern, Text, Found, Next);
97102
exit when Found (0) = GNAT.Regpat.No_Match;
@@ -116,6 +121,12 @@ package body Tester.Macros is
116121
Expand_URI
117122
(Text (Found (2).First .. Found (2).Last),
118123
Test_Dir));
124+
elsif Found (3) /= GNAT.Regpat.No_Match then -- $FILE{x}
125+
Append
126+
(Result,
127+
Expand_FILE
128+
(Text (Found (3).First .. Found (3).Last),
129+
Test_Dir));
119130
end if;
120131

121132
Next := Found (0).Last + 1;
@@ -191,11 +202,11 @@ package body Tester.Macros is
191202
Test := Expand (Test, Env_With_Dir, Directory);
192203
end Expand;
193204

194-
----------------
195-
-- Expand_URI --
196-
----------------
205+
-----------------
206+
-- Expand_FILE --
207+
-----------------
197208

198-
function Expand_URI
209+
function Expand_FILE
199210
(Path : String;
200211
Test_Dir : String) return String
201212
is
@@ -204,22 +215,31 @@ package body Tester.Macros is
204215
begin
205216
if Path = "" then
206217
-- Return normalized Test_Dir
207-
return URIs.Conversions.From_File
208-
(Ada.Directories.Full_Name (Test_Dir));
218+
return Ada.Directories.Full_Name (Test_Dir);
209219

210220
elsif Path = "/" then
211221
-- Return normalized Test_Dir & '/'
212-
return URIs.Conversions.From_File
213-
(Ada.Directories.Full_Name (Test_Dir) &
214-
GNAT.OS_Lib.Directory_Separator);
222+
return Ada.Directories.Full_Name (Test_Dir) &
223+
GNAT.OS_Lib.Directory_Separator;
215224

216225
else
217226
-- Turn a relative path into absolute path
218-
return URIs.Conversions.From_File
219-
(Ada.Directories.Full_Name (Test_Dir) &
220-
GNAT.OS_Lib.Directory_Separator &
221-
Argument);
227+
return Ada.Directories.Full_Name (Test_Dir) &
228+
GNAT.OS_Lib.Directory_Separator &
229+
Argument;
222230
end if;
231+
end Expand_FILE;
232+
233+
----------------
234+
-- Expand_URI --
235+
----------------
236+
237+
function Expand_URI
238+
(Path : String;
239+
Test_Dir : String) return String
240+
is
241+
begin
242+
return URIs.Conversions.From_File (Expand_FILE (Path, Test_Dir));
223243
end Expand_URI;
224244

225245
end Tester.Macros;

source/tester/tester-macros.ads

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Language Server Protocol --
33
-- --
4-
-- Copyright (C) 2018-2023, AdaCore --
4+
-- Copyright (C) 2018-2024, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -34,5 +34,8 @@ package Tester.Macros is
3434
--
3535
-- * $URI{x} - rewrite as "file:///path", treat x as relative to test
3636
-- directory (Path)
37+
--
38+
-- * $FILE{x} - rewrite as "/path" or "C:/path", treat x as relative to
39+
-- test directory (Path)
3740

3841
end Tester.Macros;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
project prj is for Warning_Message use ""; end prj;

0 commit comments

Comments
 (0)