Skip to content

Commit

Permalink
Adds unittest for autocompletion as snippets
Browse files Browse the repository at this point in the history
Usually language servers do not treat autocomplete like this, they are
configured to register only the name of the function and then provide
signature help when completing (manually) the argument list.

I suspect that editors with limited UI support would not be able to have
that so instead a more traditional `Tab` completion is available.
  • Loading branch information
gnikit committed Jan 31, 2022
1 parent 29a2a82 commit ab60590
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion fortls/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion test/setup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 31 additions & 8 deletions test/test_server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from pathlib import Path

# from types import NoneType
from setup_tests import (
path_to_uri,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)"],
Expand Down Expand Up @@ -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
Expand All @@ -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)):
Expand Down

0 comments on commit ab60590

Please sign in to comment.