Avoid exception on unknown predefined entities

When computing tooltips from the static predefined
entities' documentation database.

Display a 'not found' tooltip instead.

For eng/ide/ada_language_server#1453
This commit is contained in:
Anthony Leonardo Gracio
2024-10-04 15:42:35 +00:00
parent 1e0ac71a8e
commit 0a855f20b4
5 changed files with 199 additions and 3 deletions

View File

@@ -321,10 +321,12 @@ package body LSP.Predefined_Completion is
return;
end case;
Item := Filtered_Items.First_Element;
if not Filtered_Items.Is_Empty then
Item := Filtered_Items.First_Element;
Declaration_Text := Item.detail;
Documentation_Text := Item.documentation.Value.Virtual_String;
Declaration_Text := Item.detail;
Documentation_Text := Item.documentation.Value.Virtual_String;
end if;
end Get_Tooltip_Text;
end LSP.Predefined_Completion;

View File

@@ -0,0 +1,2 @@
project Default is
end Default;

View File

@@ -0,0 +1,10 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Main
with Unknown => Off
is
Foo : Integer := 30;
pragma Unknown (C, Foo);
begin
Put_Line (Foo'Unknown);
end Main;

View File

@@ -0,0 +1,181 @@
[
{
"comment": [
"This test checks that the textDocument/hover request does not ",
"fail when hovering on unknown predefined entities."
]
},
{
"start": {
"cmd": ["${ALS}"]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"rootUri": "$URI{.}",
"capabilities": {
"textDocument": {
"rangeFormatting": {
"dynamicRegistration": true
}
}
}
}
},
"wait": [
{
"id": 1,
"result": {
"capabilities": {
"hoverProvider": true
}
}
}
]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "initialized"
},
"wait": []
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "workspace/didChangeConfiguration",
"params": {
"settings": {
"ada": {
"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; use Ada.Text_IO;\n\nprocedure Main \n with Unknown => Off\nis\n Foo : Integer := 30;\n pragma Unknown (C, Foo);\nbegin\n Put_Line (Foo'Unknown);\nend Main;\n"
}
}
},
"wait": []
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 4,
"method": "textDocument/hover",
"params": {
"textDocument": {
"uri": "$URI{main.adb}"
},
"position": {
"line": 3,
"character": 7
}
}
},
"wait": [{ "result": null }]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 5,
"method": "textDocument/hover",
"params": {
"textDocument": {
"uri": "$URI{main.adb}"
},
"position": {
"line": 6,
"character": 10
}
}
},
"wait": [{ "result": null }]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"id": 6,
"method": "textDocument/hover",
"params": {
"textDocument": {
"uri": "$URI{main.adb}"
},
"position": {
"line": 8,
"character": 17
}
}
},
"wait": [{ "result": null }]
}
},
{
"send": {
"request": {
"jsonrpc": "2.0",
"method": "textDocument/didClose",
"params": {
"textDocument": {
"uri": "$URI{main.adb}"
}
}
},
"wait": []
}
},
{
"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.predefined_entities.unknown'