Skip to content

Commit 4706bfc

Browse files
Merge branch 'topic/als.1516.allow_null' into 'master'
Allow null as the kind when parsing a configuration setting See merge request eng/ide/ada_language_server!1903
2 parents 84fc4ee + 1868fb9 commit 4706bfc

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

source/ada/lsp-ada_configurations.adb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ package body LSP.Ada_Configurations is
155155
Variables_Names : VSS.String_Vectors.Virtual_String_Vector;
156156
Variables_Values : VSS.String_Vectors.Virtual_String_Vector;
157157

158-
Configuration_Error : exception;
158+
Skip_Value_Exception : exception;
159159
-- Raise when we have a configuration exception
160160

161161
procedure Parse_Variables (From : Positive);
@@ -215,6 +215,10 @@ package body LSP.Ada_Configurations is
215215
if Var_Kind = Expected_Kind then
216216
-- Only valid case: good name, casing and kind
217217
return True;
218+
elsif Var_Kind = Null_Value then
219+
-- Null kind correspond to the default configuration just
220+
-- ignore this Variable
221+
raise Skip_Value_Exception;
218222
else
219223
Messages.Append
220224
("Invalid type for the Ada setting """
@@ -231,7 +235,7 @@ package body LSP.Ada_Configurations is
231235
end if;
232236

233237
-- Found an invalid configuration for Var_Name, skip it
234-
raise Configuration_Error;
238+
raise Skip_Value_Exception;
235239
else
236240
-- Didn't match Var_Name
237241
return False;
@@ -433,7 +437,7 @@ package body LSP.Ada_Configurations is
433437
Skip_Value (JSON, Index);
434438

435439
exception
436-
when Configuration_Error =>
440+
when Skip_Value_Exception =>
437441
-- A message was produced for this value, skip it
438442
Skip_Value (JSON, Index);
439443
when others =>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Verify we are sending showMessages in response of invalid configuration but
3+
not when resetting it using a null value for a setting.
4+
"""
5+
6+
import asyncio
7+
from drivers.pylsp import (
8+
ALSLanguageClient,
9+
assertEqual,
10+
test,
11+
)
12+
13+
EXPECTED = [
14+
'Unknown Ada setting "unknownAttr".',
15+
'Ada settings are case sensitive: "USEGNATFORMAT" has been ignored '
16+
+ 'please set it to "useGnatformat".',
17+
'Invalid type for the Ada setting "logThreshold" please check the value.',
18+
]
19+
20+
21+
@test()
22+
async def main(lsp: ALSLanguageClient) -> None:
23+
# There is no config file
24+
lsp.didOpenVirtual()
25+
26+
# Disable mypy warning for the ignore below, it's detecting unknown
27+
# attribute for didChangeConfig which is the goal of the test
28+
lsp.didChangeConfig(
29+
{
30+
"unknownAttr": "Hello", # type: ignore
31+
"USEGNATFORMAT": False, # type: ignore
32+
"logThreshold": False,
33+
"insertWithClauses": True,
34+
"gprConfigurationFile": None,
35+
}
36+
)
37+
38+
# Wait for didChangeConfig to be handled
39+
await asyncio.sleep(2)
40+
41+
total_log_msg = len(lsp.log_messages)
42+
total_show_msg = len(lsp.messages)
43+
# the first logMessage is about the log file location, ignore it
44+
assertEqual([msg.message for msg in lsp.log_messages[1:]], EXPECTED)
45+
assertEqual([msg.message for msg in lsp.messages], EXPECTED)
46+
47+
lsp.didChangeConfig({"logThreshold": None, "insertWithClauses": None})
48+
49+
# Wait for didChangeConfig to be handled
50+
await asyncio.sleep(2)
51+
52+
# Check that no messages were sent after using None/null as the value for
53+
# a setting
54+
assertEqual(len(lsp.log_messages), total_log_msg)
55+
assertEqual(len(lsp.messages), total_show_msg)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
driver: pylsp

0 commit comments

Comments
 (0)