diff --git a/CHANGELOG.md b/CHANGELOG.md index baf1eee1..b1bf1be8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGELONG +## 2.1.2 + +### Fixed + +- Fixed code autocompletion bug with f-strings + ([#39](https://github.com/hansec/fortran-language-server/issues/39)) + ## 2.1.1 ### Added diff --git a/fortls/interface.py b/fortls/interface.py index 7a914cb4..cb589137 100644 --- a/fortls/interface.py +++ b/fortls/interface.py @@ -152,7 +152,10 @@ def commandline_args(name: str = "fortls") -> argparse.ArgumentParser: group.add_argument( "--use_signature_help", action="store_true", - help="Use signature help instead of subroutine/function snippets", + help=( + "Use signature help instead of subroutine/function snippets. This" + " effectively sets --autocomplete_no_snippets" + ), ) # Hover options ------------------------------------------------------------ diff --git a/test/setup_tests.py b/test/setup_tests.py index 6bab00b2..ca896afb 100644 --- a/test/setup_tests.py +++ b/test/setup_tests.py @@ -24,7 +24,6 @@ def run_request(request, fortls_args: list[str] = None): sys.executable, str(root_dir / "fortls.py"), "--incremental_sync", - "--use_signature_help", ] if fortls_args: # Input args might not be sanitised, fix that diff --git a/test/test_server.py b/test/test_server.py index 55854626..c6ae6e6e 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -1,5 +1,3 @@ -from pathlib import Path - # from types import NoneType from setup_tests import ( path_to_uri, @@ -233,6 +231,10 @@ def check_return(result_array, checks): if checks[0] > 0: assert result_array[0]["label"] == checks[1] assert result_array[0]["detail"] == checks[2] + try: + assert result_array[0]["insertText"] == checks[3] + except KeyError: + pass def comp_request(file_path, line, char): return write_rpc_request( @@ -296,15 +298,23 @@ def comp_request(file_path, line, char): file_path = test_dir / "completion" / "test_vis_mod_completion.f90" string += comp_request(file_path, 12, 16) string += comp_request(file_path, 12, 24) - errcode, results = run_request(string) + errcode, results = run_request(string, ["--use_signature_help"]) + assert errcode == 0 + + string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)}) + file_path = test_dir / "test_prog.f08" + string += comp_request(file_path, 12, 6) + errcode, res = run_request(string) assert errcode == 0 + results.extend(res[1:]) + # exp_results = ( # test_prog.f08 - [1, "myfun", "DOUBLE PRECISION FUNCTION myfun(n, xval)"], - [9, "glob_sub", "SUBROUTINE glob_sub(n, xval, yval)"], - [1, "bound_nopass", "SUBROUTINE bound_nopass(a, b)"], - [1, "bound_pass", "SUBROUTINE bound_pass(arg1)"], + [1, "myfun", "DOUBLE PRECISION FUNCTION myfun(n, xval)", "myfun"], + [9, "glob_sub", "SUBROUTINE glob_sub(n, xval, yval)", "glob_sub"], + [1, "bound_nopass", "SUBROUTINE bound_nopass(a, b)", "bound_nopass"], + [1, "bound_pass", "SUBROUTINE bound_pass(arg1)", "bound_pass"], [1, "stretch_vector", "TYPE(scaled_vector)"], [6, "scale", "TYPE(scale_type)"], [2, "n", "INTEGER(4)"], @@ -337,7 +347,12 @@ def comp_request(file_path, line, char): [10, "READ", "STATEMENT"], [11, "READ", "STATEMENT"], # subdir/test_generic.f90 - [4, "my_gen", "SUBROUTINE my_gen(self, a, b)"], + [ + 4, + "my_gen", + "SUBROUTINE my_gen(self, a, b)", + "my_gen(${1:self}, ${2:a}, ${3:b})", + ], # subdir/test_inherit.f90 [1, "val", "REAL(8)"], # subdir/test_rename.F90 @@ -352,6 +367,14 @@ def comp_request(file_path, line, char): # completion/test_vis_mod_completion.f90 [1, "some_var", "INTEGER"], [3, "length", "INTEGER"], + # test_prog.f08, completion without signature_help + # returns the entire completion as a snippet + [ + 1, + "myfun", + "DOUBLE PRECISION FUNCTION myfun(n, xval)", + "myfun(${1:n}, ${2:xval})", + ], ) assert len(exp_results) + 1 == len(results) for i in range(len(exp_results)):