Skip to content

Commit

Permalink
Merge branch 'topic/als.1516.allow_null' into 'master'
Browse files Browse the repository at this point in the history
Allow null as the kind when parsing a configuration setting

See merge request eng/ide/ada_language_server!1903
  • Loading branch information
AdrienBoulanger committed Jan 24, 2025
2 parents 84fc4ee + 1868fb9 commit 4706bfc
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
10 changes: 7 additions & 3 deletions source/ada/lsp-ada_configurations.adb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ package body LSP.Ada_Configurations is
Variables_Names : VSS.String_Vectors.Virtual_String_Vector;
Variables_Values : VSS.String_Vectors.Virtual_String_Vector;

Configuration_Error : exception;
Skip_Value_Exception : exception;
-- Raise when we have a configuration exception

procedure Parse_Variables (From : Positive);
Expand Down Expand Up @@ -215,6 +215,10 @@ package body LSP.Ada_Configurations is
if Var_Kind = Expected_Kind then
-- Only valid case: good name, casing and kind
return True;
elsif Var_Kind = Null_Value then
-- Null kind correspond to the default configuration just
-- ignore this Variable
raise Skip_Value_Exception;
else
Messages.Append
("Invalid type for the Ada setting """
Expand All @@ -231,7 +235,7 @@ package body LSP.Ada_Configurations is
end if;

-- Found an invalid configuration for Var_Name, skip it
raise Configuration_Error;
raise Skip_Value_Exception;
else
-- Didn't match Var_Name
return False;
Expand Down Expand Up @@ -433,7 +437,7 @@ package body LSP.Ada_Configurations is
Skip_Value (JSON, Index);

exception
when Configuration_Error =>
when Skip_Value_Exception =>
-- A message was produced for this value, skip it
Skip_Value (JSON, Index);
when others =>
Expand Down
55 changes: 55 additions & 0 deletions testsuite/ada_lsp/configuration_warning_null_setting/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Verify we are sending showMessages in response of invalid configuration but
not when resetting it using a null value for a setting.
"""

import asyncio
from drivers.pylsp import (
ALSLanguageClient,
assertEqual,
test,
)

EXPECTED = [
'Unknown Ada setting "unknownAttr".',
'Ada settings are case sensitive: "USEGNATFORMAT" has been ignored '
+ 'please set it to "useGnatformat".',
'Invalid type for the Ada setting "logThreshold" please check the value.',
]


@test()
async def main(lsp: ALSLanguageClient) -> None:
# There is no config file
lsp.didOpenVirtual()

# Disable mypy warning for the ignore below, it's detecting unknown
# attribute for didChangeConfig which is the goal of the test
lsp.didChangeConfig(
{
"unknownAttr": "Hello", # type: ignore
"USEGNATFORMAT": False, # type: ignore
"logThreshold": False,
"insertWithClauses": True,
"gprConfigurationFile": None,
}
)

# Wait for didChangeConfig to be handled
await asyncio.sleep(2)

total_log_msg = len(lsp.log_messages)
total_show_msg = len(lsp.messages)
# the first logMessage is about the log file location, ignore it
assertEqual([msg.message for msg in lsp.log_messages[1:]], EXPECTED)
assertEqual([msg.message for msg in lsp.messages], EXPECTED)

lsp.didChangeConfig({"logThreshold": None, "insertWithClauses": None})

# Wait for didChangeConfig to be handled
await asyncio.sleep(2)

# Check that no messages were sent after using None/null as the value for
# a setting
assertEqual(len(lsp.log_messages), total_log_msg)
assertEqual(len(lsp.messages), total_show_msg)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
driver: pylsp

0 comments on commit 4706bfc

Please sign in to comment.