Skip to content

Commit 5a9f20c

Browse files
committed
Handle exceptions in Project_Tree.Update_Sources
and report as errors. Add the test case.
1 parent 2c3403f commit 5a9f20c

File tree

5 files changed

+124
-1
lines changed

5 files changed

+124
-1
lines changed

source/ada/lsp-ada_handlers.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5016,6 +5016,8 @@ package body LSP.Ada_Handlers is
50165016
Build_Path => Self.Project_Environment.Build_Path,
50175017
Environment => Environment);
50185018

5019+
Self.Project_Tree.Update_Sources (With_Runtime => True);
5020+
50195021
exception
50205022
when E : GPR2.Project_Error
50215023
| GPR2.Processing_Error
@@ -5045,7 +5047,6 @@ package body LSP.Ada_Handlers is
50455047
Self.Project_Status := No_Runtime_Found;
50465048
end if;
50475049

5048-
Self.Project_Tree.Update_Sources (With_Runtime => True);
50495050
Update_Project_Predefined_Sources (Self);
50505051

50515052
if Self.Project_Tree.Root_Project.Kind in GPR2.Aggregate_Kind then
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Main is
2+
begin
3+
null;
4+
end Main;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project Prj1 is
2+
for Source_Files use ("missing.ads", "main.adb");
3+
end Prj1;
4+
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
[
2+
{
3+
"comment":[
4+
"This test check language server is able to report errors",
5+
"when loading a project with missing files."
6+
]
7+
}, {
8+
"start": {
9+
"cmd": ["${ALS}"]
10+
}
11+
}, {
12+
"send": {
13+
"request": {"jsonrpc":"2.0","id":0,"method":"initialize","params":{
14+
"processId":1,
15+
"rootUri":"$URI{.}",
16+
"capabilities":{}}
17+
},
18+
"wait":[{
19+
"id": 0,
20+
"result":{
21+
"capabilities":{
22+
"textDocumentSync": 2,
23+
"definitionProvider":true
24+
}
25+
}
26+
}]
27+
}
28+
}, {
29+
"send": {
30+
"request": {
31+
"jsonrpc":"2.0",
32+
"method":"workspace/didChangeConfiguration",
33+
"params":{
34+
"settings":{
35+
"ada":{
36+
"projectFile": "prj1.gpr"
37+
}
38+
}
39+
}
40+
},
41+
"wait":[
42+
{
43+
"jsonrpc": "2.0",
44+
"method": "window/showMessage",
45+
"params": {
46+
"type": 1,
47+
"message": "<ANY>"
48+
}
49+
}
50+
]
51+
}
52+
}, {
53+
"send": {
54+
"request": {
55+
"jsonrpc":"2.0",
56+
"method":"textDocument/didOpen",
57+
"params":{
58+
"textDocument": {
59+
"uri": "$URI{main.adb}",
60+
"languageId": "ada",
61+
"version": 1,
62+
"text": "procedure Main is\nbegin\n null;\nend Main;"
63+
}
64+
}
65+
},
66+
"wait":[
67+
{
68+
"jsonrpc": "2.0",
69+
"method": "textDocument/publishDiagnostics",
70+
"params": {
71+
"uri":"$URI{main.adb}",
72+
"diagnostics":[
73+
{
74+
"range": {
75+
"start": {
76+
"line": 0,
77+
"character": 0
78+
},
79+
"end": {
80+
"line":0,
81+
"character":0
82+
}
83+
},
84+
"severity": 1,
85+
"source": "project",
86+
"message": "Project file has error and can't be loaded."
87+
}
88+
]
89+
}
90+
}
91+
]
92+
}
93+
}, {
94+
"send": {
95+
"request": {
96+
"jsonrpc":"2.0",
97+
"id": "shutdown",
98+
"method":"shutdown",
99+
"params":null
100+
},
101+
"wait":[{ "id": "shutdown", "result": null }]
102+
}
103+
}, {
104+
"send": {
105+
"request": {"jsonrpc":"2.0", "method":"exit", "params":{}},
106+
"wait":[]
107+
}
108+
}, {
109+
"stop": {
110+
"exit_code": 0
111+
}
112+
}
113+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'project_config.missing_file'

0 commit comments

Comments
 (0)