Skip to content

Commit 5a376d5

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 91b229c + ad4d590 commit 5a376d5

File tree

27 files changed

+2005
-18
lines changed

27 files changed

+2005
-18
lines changed

source/gpr/lsp-gpr_documents.adb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18+
with Ada.Exceptions;
19+
1820
with GPR2.Message;
21+
with GPR2.Source_Reference;
1922

2023
package body LSP.GPR_Documents is
2124

@@ -171,12 +174,26 @@ package body LSP.GPR_Documents is
171174
Update_Diagnostics;
172175

173176
exception
177+
when GPR2.Project_Error | GPR2.Processing_Error =>
178+
179+
Update_Diagnostics;
180+
174181
when E : others =>
175182

176183
Self.Tracer.Trace_Exception (E);
177184

178-
Update_Diagnostics;
185+
Self.Tree.Log_Messages.Append
186+
(GPR2.Message.Create
187+
(Level => GPR2.Message.Error,
188+
Message => "GPR parser unexpected " &
189+
Ada.Exceptions.Exception_Name (E) & " " &
190+
Ada.Exceptions.Exception_Message (E),
191+
Sloc => GPR2.Source_Reference.Create
192+
(Filename => Self.File.Value,
193+
Line => 1,
194+
Column => 1)));
179195

196+
Update_Diagnostics;
180197
end Load;
181198

182199
-----------------------------

source/gpr/lsp-gpr_external_tools.adb

Lines changed: 2 additions & 2 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- --
@@ -184,7 +184,7 @@ package body LSP.GPR_External_Tools is
184184
Inherit_From_Extended => Inherit_From_Extended,
185185
Is_Set => Is_Set);
186186
end if;
187-
if Get_Attribute_Description (Name)'Length > 0
187+
if Get_Attribute_Description (Name)'Length = 0
188188
and then Description'Length > 0
189189
then
190190
Set_Attribute_Description (Name, Description);

source/gpr/lsp-gpr_files.adb

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,47 @@ package body LSP.GPR_Files is
468468

469469
package LKD renames LSP.Text_Documents.Langkit_Documents;
470470

471+
function To_Valid_Name
472+
(Name : VSS.Strings.Virtual_String)
473+
return VSS.Strings.Virtual_String;
474+
-- Avoid empty Name, set Name to " " when required.
475+
476+
procedure Append_New_To_Current (New_Symbol : Symbol);
477+
-- Append New_Symbol to current list.
478+
479+
---------------------------
480+
-- Append_New_To_Current --
481+
---------------------------
482+
483+
procedure Append_New_To_Current (New_Symbol : Symbol) is
484+
begin
485+
Current_Symbols.Append (New_Symbol);
486+
end Append_New_To_Current;
487+
488+
-------------------
489+
-- To_Valid_Name --
490+
-------------------
491+
492+
function To_Valid_Name
493+
(Name : VSS.Strings.Virtual_String)
494+
return VSS.Strings.Virtual_String is
495+
496+
begin
497+
if Name.Is_Empty
498+
then
499+
-- avoid name: "", in documentSymbol.
500+
return " ";
501+
else
502+
return Name;
503+
end if;
504+
end To_Valid_Name;
505+
471506
New_Symbol : Symbol :=
472507
(New_Id,
473508
Current_Symbol.Id,
474509
Token.Ref,
475510
Kind,
476-
Name,
511+
To_Valid_Name (Name),
477512
LKD.To_A_Range
478513
(Start_Line_Text =>
479514
File.Get_Line (Location_Range.Start_Line),
@@ -489,18 +524,6 @@ package body LSP.GPR_Files is
489524
LK_Slocs.Column_Number
490525
(Location_Range.End_Column))));
491526

492-
procedure Append_New_To_Current (New_Symbol : Symbol);
493-
-- Append New_Symbol to current list.
494-
495-
---------------------------
496-
-- Append_New_To_Current --
497-
---------------------------
498-
499-
procedure Append_New_To_Current (New_Symbol : Symbol) is
500-
begin
501-
Current_Symbols.Append (New_Symbol);
502-
end Append_New_To_Current;
503-
504527
begin
505528
case Kind is
506529
when K_Imported =>
@@ -1466,6 +1489,10 @@ package body LSP.GPR_Files is
14661489
else
14671490
return Path_Name.Undefined;
14681491
end if;
1492+
exception
1493+
when E : others =>
1494+
File.Tracer.Trace_Exception (E);
1495+
return Path_Name.Undefined;
14691496
end Get_Referenced_GPR;
14701497

14711498
end LSP.GPR_Files;

source/gpr/lsp-gpr_files.ads

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ package LSP.GPR_Files is
112112
return LSP.Structures.DocumentUri is abstract;
113113
-- Turn GPR2 path object into URI.
114114

115+
function Tracer
116+
(Self : access File_Provider)
117+
return LSP.Tracers.Tracer_Access is abstract;
118+
115119
procedure Initialize
116120
(Self : in out File;
117121
Path : GPR2.Path_Name.Object;

source/gpr/lsp-gpr_handlers.ads

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,9 @@ private
242242
Document : not null LSP.GPR_Documents.Document_Access);
243243
-- Publish diagnostic messages for given document if needed
244244

245+
overriding function Tracer
246+
(Self : access Message_Handler)
247+
return LSP.Tracers.Tracer_Access is
248+
(Self.Tracer);
249+
245250
end LSP.GPR_Handlers;

testsuite/gpr_lsp/gpr2_assertions/test.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@
8282
"params": {
8383
"uri": "$URI{prj.gpr}",
8484
"diagnostics": [
85+
{
86+
"range": {
87+
"start": {
88+
"line": 0,
89+
"character": 0
90+
},
91+
"end": {
92+
"line": 0,
93+
"character": 0
94+
}
95+
},
96+
"severity": 1,
97+
"message": "GPR parser unexpected ADA.ASSERTIONS.ASSERTION_ERROR DYNAMIC_PREDICATE failed at gpr2-message.adb:23"
98+
}
8599
]
86100
}
87101
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
with "";
2+
project Prj is
3+
for Source_List_File use "";
4+
for Excluded_Source_List_File use "";
5+
for Warning_Message use "";
6+
package Naming is
7+
for Body ("Ada") use "" ;
8+
for Implementation ("Ada") use "";
9+
for Spec ("Ada") use "";
10+
for Specification ("Ada") use "";
11+
end Naming;
12+
end Prj;
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
[
2+
{
3+
"comment": [
4+
"test gpr unexpected exception handling"
5+
]
6+
},
7+
{
8+
"start": {
9+
"cmd": [
10+
"${ALS}",
11+
"--language-gpr"
12+
]
13+
}
14+
},
15+
{
16+
"send": {
17+
"request": {
18+
"params": {
19+
"processId": 30612,
20+
"capabilities": {
21+
"workspace": {
22+
"applyEdit": false
23+
}
24+
},
25+
"rootUri": "$URI{.}"
26+
},
27+
"jsonrpc": "2.0",
28+
"id": 1,
29+
"method": "initialize"
30+
},
31+
"wait": [
32+
{
33+
"jsonrpc": "2.0",
34+
"id": 1,
35+
"result": {
36+
"capabilities": {
37+
"textDocumentSync": {
38+
"openClose": true,
39+
"change": 1
40+
},
41+
"completionProvider": {
42+
"triggerCharacters": [
43+
" "
44+
],
45+
"resolveProvider": true
46+
},
47+
"hoverProvider": true,
48+
"definitionProvider": true,
49+
"documentSymbolProvider": {}
50+
}
51+
}
52+
}
53+
]
54+
}
55+
},
56+
{
57+
"send": {
58+
"request": {
59+
"jsonrpc": "2.0",
60+
"method": "initialized"
61+
},
62+
"wait": []
63+
}
64+
},
65+
{
66+
"send": {
67+
"request": {
68+
"params": {
69+
"textDocument": {
70+
"text": "with \"\";\nproject Prj is\n for Source_List_File use \"\";\n for Excluded_Source_List_File use \"\";\n for Warning_Message use \"\";\n package Naming is\n for Body (\"Ada\") use \"\" ;\n for Implementation (\"Ada\") use \"\";\n for Spec (\"Ada\") use \"\";\n for Specification (\"Ada\") use \"\";\n end Naming;\nend Prj;",
71+
"version": 0,
72+
"uri": "$URI{prj.gpr}",
73+
"languageId": "Gpr"
74+
}
75+
},
76+
"jsonrpc": "2.0",
77+
"method": "textDocument/didOpen"
78+
},
79+
"wait": [
80+
{
81+
"jsonrpc": "2.0",
82+
"method": "textDocument/publishDiagnostics",
83+
"params": {
84+
"uri": "$URI{prj.gpr}",
85+
"diagnostics": [
86+
{
87+
"range": {
88+
"start": {
89+
"line": 0,
90+
"character": 0
91+
},
92+
"end": {
93+
"line": 0,
94+
"character": 0
95+
}
96+
},
97+
"severity": 1,
98+
"message": "GPR parser unexpected ADA.ASSERTIONS.ASSERTION_ERROR DYNAMIC_PREDICATE failed at gpr2-project-parser.adb:83"
99+
}
100+
]
101+
}
102+
}
103+
]
104+
}
105+
},
106+
{
107+
"send": {
108+
"request": {
109+
"jsonrpc": "2.0",
110+
"id": "shutdown",
111+
"method": "shutdown",
112+
"params": null
113+
},
114+
"wait": [
115+
{
116+
"id": "shutdown",
117+
"result": null
118+
}
119+
]
120+
}
121+
},
122+
{
123+
"send": {
124+
"request": {
125+
"jsonrpc": "2.0",
126+
"method": "exit"
127+
},
128+
"wait": []
129+
}
130+
},
131+
{
132+
"stop": {
133+
"exit_code": 0
134+
}
135+
}
136+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'gpr2 parsing assertions error handling'

testsuite/gpr_lsp/hover/prj1.gpr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ for Source_Dirs use ("src");
33
package Compiler is
44
for Switches ("Ada") use ();
55
end Compiler;
6+
package IDE is
7+
for Artifacts_Dir use "";
8+
end IDE;
69
end Prj1;

0 commit comments

Comments
 (0)