Skip to content

Commit f56621f

Browse files
Add defensive code when computing tooltip text
In particular we should not even try to compute the variables' declarations if the root project could not be parsed. Add automatic test for this. For eng/ide/gnatstudio#345
1 parent 9b94c68 commit f56621f

File tree

7 files changed

+205
-10
lines changed

7 files changed

+205
-10
lines changed

source/gpr/lsp-gpr_documents.adb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ package body LSP.GPR_Documents is
123123
----------------
124124

125125
function Has_Errors
126-
(Self : Document)
126+
(Self : Document)
127127
return Boolean is
128128
begin
129-
return Self.Tree.Log_Messages.Has_Error;
129+
return Self.Tree.Log_Messages.Has_Error
130+
or else not Self.Tree.Root_Project.Is_Defined;
130131
end Has_Errors;
131132

132133
----------------
@@ -300,7 +301,7 @@ package body LSP.GPR_Documents is
300301

301302
begin
302303
if LSP.GPR_Files.References.Is_Variable_Reference (Reference)
303-
and then not Self.Tree.Log_Messages.Has_Error
304+
and then not Self.Has_Errors
304305
then
305306
declare
306307
File : constant LSP.GPR_Files.File_Access :=
@@ -373,7 +374,7 @@ package body LSP.GPR_Documents is
373374

374375
begin
375376
if LSP.GPR_Files.References.Is_Attribute_Reference (Reference)
376-
and then not Self.Tree.Log_Messages.Has_Error
377+
and then not Self.Has_Errors
377378
then
378379
declare
379380
File : constant LSP.GPR_Files.File_Access :=
@@ -446,7 +447,7 @@ package body LSP.GPR_Documents is
446447

447448
begin
448449
if LSP.GPR_Files.References.Is_Type_Reference (Reference)
449-
and then not Self.Tree.Log_Messages.Has_Error
450+
and then not Self.Has_Errors
450451
then
451452
declare
452453
File : constant LSP.GPR_Files.File_Access :=

source/gpr/lsp-gpr_documents.ads

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ package LSP.GPR_Documents is
103103
function Has_Errors
104104
(Self : Document)
105105
return Boolean;
106-
-- Returns True when errors found during document parsing.
106+
-- Returns True when errors found during document parsing or if
107+
-- the tree could not be parsed properly (no defined root project).
107108

108109
-----------------------
109110
-- Document_Provider --

source/gpr/lsp-gpr_handlers.adb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ package body LSP.GPR_Handlers is
302302
Documentation_Text : VSS.Strings.Virtual_String;
303303
Location_Text : VSS.Strings.Virtual_String;
304304
begin
305-
306305
LSP.GPR_Documentation.Get_Tooltip_Text
307306
(Self => File,
308307
URI => Value.textDocument.uri,
@@ -620,9 +619,7 @@ package body LSP.GPR_Handlers is
620619
declare
621620
Message : constant VSS.Strings.Virtual_String :=
622621
VSS.Strings.Conversions.To_Virtual_String
623-
("Exception: " &
624-
Ada.Exceptions.Exception_Name (E) & " (" &
625-
Ada.Exceptions.Exception_Message (E) & ")");
622+
("Exception: " & Ada.Exceptions.Exception_Information (E));
626623

627624
begin
628625
Self.Tracer.Trace_Exception (E, "On_Server_Request");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project Prj1 is
2+
for Source_Dirs use ("src");
3+
package Compiler is
4+
for Switches ("Ada") use ();
5+
end Compiler;
6+
package IDE is
7+
for Artifacts_Dir use "";
8+
end IDE;
9+
end Prj1;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
with "unknown";
2+
project Prj3 is
3+
type T is ("project.Var value ");
4+
Var : T := "project.Var value ";
5+
package Builder is
6+
Var := "project.Builder.Var value ";
7+
for Global_Configuration_Pragmas use "project.Builder'Global_Configuration_Pragmas value ";
8+
end Builder;
9+
Var1 := Var & project.Var & project.Builder.Var & project'Name & Prj3'Name & Prj3.Builder'Global_Configuration_Pragmas;
10+
package Compiler is
11+
for Switches ("main.adb") use ("value1");
12+
for Switches ("main.adb" at 1) use ("value2");
13+
for Switches (others) use ("value3");
14+
Var := Compiler'Switches ("main.adb") & Compiler'Switches (others);
15+
end Compiler;
16+
end Prj3;
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
[
2+
{
3+
"comment": [
4+
"Check that we don't get any exception when computing variables'",
5+
"tooltips on non-valid projects"
6+
]
7+
},
8+
{
9+
"start": {
10+
"cmd": ["${ALS}", "--language-gpr"]
11+
}
12+
},
13+
{
14+
"send": {
15+
"request": {
16+
"jsonrpc": "2.0",
17+
"id": "init",
18+
"method": "initialize",
19+
"params": {
20+
"processId": 441587,
21+
"rootUri": "$URI{.}",
22+
"capabilities": {
23+
"workspace": {
24+
"applyEdit": true,
25+
"workspaceEdit": {},
26+
"didChangeConfiguration": {},
27+
"didChangeWatchedFiles": {},
28+
"executeCommand": {}
29+
},
30+
"textDocument": {
31+
"synchronization": {},
32+
"completion": {
33+
"dynamicRegistration": true,
34+
"completionItem": {
35+
"snippetSupport": true,
36+
"documentationFormat": ["plaintext", "markdown"]
37+
}
38+
},
39+
"hover": {},
40+
"signatureHelp": {},
41+
"declaration": {},
42+
"definition": {},
43+
"typeDefinition": {},
44+
"implementation": {},
45+
"references": {},
46+
"documentHighlight": {},
47+
"documentSymbol": {
48+
"hierarchicalDocumentSymbolSupport": true
49+
},
50+
"codeLens": {},
51+
"colorProvider": {},
52+
"formatting": {
53+
"dynamicRegistration": false
54+
},
55+
"rangeFormatting": {
56+
"dynamicRegistration": false
57+
},
58+
"onTypeFormatting": {
59+
"dynamicRegistration": false
60+
},
61+
"foldingRange": {
62+
"lineFoldingOnly": true
63+
},
64+
"selectionRange": {},
65+
"linkedEditingRange": {},
66+
"callHierarchy": {},
67+
"moniker": {}
68+
}
69+
}
70+
}
71+
},
72+
"wait": [
73+
{
74+
"jsonrpc": "2.0",
75+
"id": "init",
76+
"result": {
77+
"capabilities": {
78+
"textDocumentSync": {
79+
"openClose": true,
80+
"change": 1
81+
}
82+
}
83+
}
84+
}
85+
]
86+
}
87+
},
88+
{
89+
"send": {
90+
"request": {
91+
"jsonrpc": "2.0",
92+
"method": "initialized"
93+
},
94+
"wait": []
95+
}
96+
},
97+
{
98+
"send": {
99+
"request": {
100+
"jsonrpc": "2.0",
101+
"method": "textDocument/didOpen",
102+
"params": {
103+
"textDocument": {
104+
"uri": "$URI{prj3.gpr}",
105+
"languageId": "Gpr",
106+
"version": 1,
107+
"text": "with \"unknown\";\nproject Prj3 is\n type T is (\"project.Var value \");\n Var : T := \"project.Var value \";\n package Builder is\n Var := \"project.Builder.Var value \";\n for Global_Configuration_Pragmas use \"project.Builder'Global_Configuration_Pragmas value \";\n end Builder;\n Var1 := Var & project.Var & project.Builder.Var & project'Name & Prj3'Name & Prj3.Builder'Global_Configuration_Pragmas;\n package Compiler is\n for Switches (\"main.adb\") use (\"value1\");\n for Switches (\"main.adb\" at 1) use (\"value2\");\n for Switches (others) use (\"value3\");\n Var := Compiler'Switches (\"main.adb\") & Compiler'Switches (others);\n end Compiler;\nend Prj3;\n"
108+
}
109+
}
110+
},
111+
"wait": []
112+
}
113+
},
114+
{
115+
"send": {
116+
"request": {
117+
"params": {
118+
"position": {
119+
"line": 3,
120+
"character": 3
121+
},
122+
"textDocument": {
123+
"uri": "$URI{prj3.gpr}"
124+
}
125+
},
126+
"jsonrpc": "2.0",
127+
"id": 9,
128+
"method": "textDocument/hover"
129+
},
130+
"wait": [
131+
{
132+
"id": 9,
133+
"result": null
134+
}
135+
]
136+
}
137+
},
138+
{
139+
"send": {
140+
"request": {
141+
"jsonrpc": "2.0",
142+
"id": "shutdown",
143+
"method": "shutdown",
144+
"params": null
145+
},
146+
"wait": [
147+
{
148+
"id": "shutdown",
149+
"result": null
150+
}
151+
]
152+
}
153+
},
154+
{
155+
"send": {
156+
"request": {
157+
"jsonrpc": "2.0",
158+
"method": "exit"
159+
},
160+
"wait": []
161+
}
162+
},
163+
{
164+
"stop": {
165+
"exit_code": 0
166+
}
167+
}
168+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
title: 'hover.no_exception_when_failed_to_load'
2+
skip:
3+
- ['SKIP', 'env.build.os.name not in ("linux","windows")']

0 commit comments

Comments
 (0)