From ff3e3e0fd34a5cbdca1e94a677a61a76f4e80c9c Mon Sep 17 00:00:00 2001 From: Sergey M Date: Sat, 17 Jun 2023 14:06:09 +0200 Subject: [PATCH] Fix #291 hover multi-line parameter signature Trim trailing whitespaces. Modify one test and add one more parameter_val test with multiline definition. --- fortls/parse_fortran.py | 2 +- test/test_server_hover.py | 16 +++++++++++++++- test/test_source/hover/parameters.f90 | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/fortls/parse_fortran.py b/fortls/parse_fortran.py index 1c34e649..235b5c08 100644 --- a/fortls/parse_fortran.py +++ b/fortls/parse_fortran.py @@ -1451,7 +1451,7 @@ def parse( _, col = find_word_in_line(line, name) match = FRegex.PARAMETER_VAL.match(line[col:]) if match: - var = match.group(1).strip() + var = " ".join(match.group(1).strip().split()) new_var.set_parameter_val(var) # Check if the "variable" is external and if so cycle diff --git a/test/test_server_hover.py b/test/test_server_hover.py index c2cf57bc..285d2a97 100644 --- a/test/test_server_hover.py +++ b/test/test_server_hover.py @@ -122,7 +122,7 @@ def test_hover_parameter_var_mul(): string += hover_req(file_path, 15, 28) errcode, results = run_request(string, fortls_args=["--sort_keywords"]) assert errcode == 0 - ref_results = ["```fortran90\nINTEGER, PARAMETER :: var_mul1 = 1 * 23\n```"] + ref_results = ["```fortran90\nINTEGER, PARAMETER :: var_mul1 = 1 * 23\n```"] validate_hover(results, ref_results) @@ -137,6 +137,20 @@ def test_hover_parameter_var_div(): validate_hover(results, ref_results) +def test_hover_parameter_var_multiline2(): + """Test that hover parameters display value correctly with + multiplication and spaces. Item 2""" + string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)}) + file_path = test_dir / "hover" / "parameters.f90" + string += hover_req(file_path, 17, 28) + errcode, results = run_request(string, fortls_args=["--sort_keywords"]) + assert errcode == 0 + ref_results = [ + "```fortran90\nINTEGER, PARAMETER :: var_multi2 = 1 * 23 + 2 /1\n```" + ] + validate_hover(results, ref_results) + + def test_hover_parameter_nested(): """Test that hover parameters using other parameter values works""" string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)}) diff --git a/test/test_source/hover/parameters.f90 b/test/test_source/hover/parameters.f90 index 89eff60d..c0189055 100644 --- a/test/test_source/hover/parameters.f90 +++ b/test/test_source/hover/parameters.f90 @@ -15,4 +15,7 @@ program params integer, parameter :: var_ex1 = 1 - 23 integer, parameter :: var_mul1 = 1 * 23 integer, parameter :: var_div1 = 1/1 + INTEGER, PARAMETER :: var_multi2 = 1 * & + 23 + & + 2 /1 ! comment end program params