diff --git a/CHANGELOG.md b/CHANGELOG.md index e5b65d70..e08dfc80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ ### Fixed +- Fixed bug where type fields or methods were not detected if spaces were + used around `%` + ([#286](https://github.com/fortran-lang/fortls/issues/286)) - Fixed bug where Go To Implementation would not work for submodules ([#74](https://github.com/fortran-lang/fortls/issues/74)) - Fixed bug where `associate` blocks for variables pointing to function results diff --git a/fortls/helper_functions.py b/fortls/helper_functions.py index 469aa0dc..0d589377 100644 --- a/fortls/helper_functions.py +++ b/fortls/helper_functions.py @@ -553,6 +553,9 @@ def get_var_stack(line: str) -> list[str]: >>> get_var_stack('myarray(i)%foo%bar') ['myarray', 'foo', 'bar'] + >>> get_var_stack('myarray( i ) % foo % bar') + ['myarray', 'foo', 'bar'] + In this case it will operate at the end of the string i.e. ``'this%foo'`` >>> get_var_stack('CALL self%method(this%foo') @@ -569,13 +572,14 @@ def get_var_stack(line: str) -> list[str]: # Continuation of variable after paren requires '%' character iLast = 0 for i, section in enumerate(sections): - if not line[section.start : section.end].startswith("%"): + if not line[section.start : section.end].strip().startswith("%"): iLast = i final_var = "" for section in sections[iLast:]: final_var += line[section.start : section.end] if final_var is not None: + final_var = "%".join([i.strip() for i in final_var.split("%")]) final_op_split: list[str] = FRegex.OBJBREAK.split(final_var) return final_op_split[-1].split("%") else: diff --git a/test/test_server_completion.py b/test/test_server_completion.py index 6ef55fee..2ef97825 100644 --- a/test/test_server_completion.py +++ b/test/test_server_completion.py @@ -225,6 +225,29 @@ def test_comp10(): validate_comp(results[i + 1], ref) +def test_comp11(): + """Indicate the derived types arguments separated with spaces and types""" + string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)}) + file_path = test_dir / "test_prog.f08" + string += comp_request(file_path, 23, 26) + string += comp_request(file_path, 27, 28) + string += comp_request(file_path, 28, 30) + string += comp_request(file_path, 29, 30) + errcode, results = run_request(string, ["--use_signature_help", "-n1"]) + assert errcode == 0 + + exp_results = ( + # test_prog.f08 + [1, "val", "REAL(8)"], + [1, "val", "REAL(8)"], + [1, "val", "REAL(8)"], + [1, "val", "REAL(8)"], + ) + assert len(exp_results) == len(results) - 1 + for i, ref in enumerate(exp_results): + validate_comp(results[i + 1], ref) + + def test_comp_import_host_association(): string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)}) file_path = test_dir / "test_import.f90" diff --git a/test/test_source/test_prog.f08 b/test/test_source/test_prog.f08 index 98b38f22..ab754457 100644 --- a/test/test_source/test_prog.f08 +++ b/test/test_source/test_prog.f08 @@ -8,7 +8,7 @@ PROGRAM test_program REAL(8) :: x,y COMPLEX(8) :: xc,yc TYPE(vector) :: loc_vector -TYPE(scaled_vector) :: stretch_vector +TYPE(scaled_vector) :: stretch_vector, vector1d(1) ! y = myfun(n,x) CALL glob_sub(n,xc,yc) @@ -25,4 +25,7 @@ PROGRAM test_program ! CALL test_sig_Sub(a,b,opt2=c,opt3=d) PRINT*, module_variable +y = stretch_vector%scale % val +y = stretch_vector % scale % val +y = vector1d( 1 ) % scale % val END PROGRAM test_program