Add defensive code when root project is not defined

And add a test for this.

For eng/ide/ada_language_server#1476
This commit is contained in:
Anthony Leonardo Gracio
2024-10-15 10:36:48 +00:00
parent 23a648df08
commit 618f45db2b
5 changed files with 152 additions and 0 deletions

View File

@@ -428,6 +428,7 @@ private
overriding function Project_Tree_Is_Aggregate (Self : Message_Handler)
return Boolean is
(Self.Project_Tree_Is_Defined
and then Self.Project_Tree.Root_Project.Is_Defined
and then Self.Project_Tree.Root_Project.Kind in GPR2.Aggregate_Kind);
overriding procedure Reload_Project (Self : in out Message_Handler);

View File

@@ -0,0 +1,6 @@
-- Include a project that does not exist so that
-- it fails to load in the ALS.
with "unexisting";
project Default is
end Default;

View File

@@ -0,0 +1,6 @@
with Ada.Text_IO;
procedure Main is
begin
Ada.Text_IO.Put_Line ("Hello");
end Main;

View File

@@ -0,0 +1,138 @@
[
{
"comment": [
"This test checks that the textDocument/hover request does not crash ",
"even when the project could not be loaded properly."
]
},
{
"start": {
"cmd": ["${ALS}"]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 0,
"method": "initialize",
"params": {
"processId": 1,
"rootUri": "$URI{.}",
"capabilities": {}
}
},
"wait": [
{
"id": 0,
"result": {
"capabilities": {
"textDocumentSync": 2
}
}
}
]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "initialized"
},
"wait": []
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "workspace/didChangeConfiguration",
"params": {
"settings": {
"ada": {
"projectFile": "$URI{default.gpr}",
"scenarioVariables": {},
"defaultCharset": "ISO-8859-1",
"enableDiagnostics": false,
"followSymlinks": false,
"documentationStyle": "gnat",
"namedNotationThreshold": 3,
"foldComments": false
}
}
}
},
"wait": []
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"textDocument": {
"uri": "$URI{main.adb}",
"languageId": "Ada",
"version": 0,
"text": "with Ada.Text_IO;\n\nprocedure Main is\n\nbegin Ada.Text_IO.Put_Line (\"Hello\");\nend Main;\n"
}
}
},
"wait": []
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 4,
"method": "textDocument/hover",
"params": {
"textDocument": {
"uri": "$URI{main.adb}"
},
"position": {
"line": 0,
"character": 12
}
}
},
"wait": [
{
"id": 4,
"result": {
"contents": [
"<HAS>",
{
"language": "ada",
"value": "package Ada.Text_IO"
}
]
}
}
]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 7,
"method": "shutdown"
},
"wait": [
{
"id": 7,
"result": null
}
]
}
},
{
"stop": {
"exit_code": 0
}
}
]

View File

@@ -0,0 +1 @@
title: 'hover.no_root_project'