Skip to content

Commit

Permalink
Fix #291 hover multi-line parameter signature
Browse files Browse the repository at this point in the history
Trim trailing whitespaces. Modify one test and add one more
parameter_val test with multiline definition.
  • Loading branch information
folk85 committed Jun 17, 2023
1 parent e7203b8 commit 86d8eb5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fortls/parse_fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion test/test_server_hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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)})
Expand Down
3 changes: 3 additions & 0 deletions test/test_source/hover/parameters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 86d8eb5

Please sign in to comment.