Skip to content

Commit ab60590

Browse files
committed
Adds unittest for autocompletion as snippets
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.
1 parent 29a2a82 commit ab60590

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELONG
22

3+
## 2.1.2
4+
5+
### Fixed
6+
7+
- Fixed code autocompletion bug with f-strings
8+
([#39](https://github.com/hansec/fortran-language-server/issues/39))
9+
310
## 2.1.1
411

512
### Added

fortls/interface.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ def commandline_args(name: str = "fortls") -> argparse.ArgumentParser:
152152
group.add_argument(
153153
"--use_signature_help",
154154
action="store_true",
155-
help="Use signature help instead of subroutine/function snippets",
155+
help=(
156+
"Use signature help instead of subroutine/function snippets. This"
157+
" effectively sets --autocomplete_no_snippets"
158+
),
156159
)
157160

158161
# Hover options ------------------------------------------------------------

test/setup_tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def run_request(request, fortls_args: list[str] = None):
2424
sys.executable,
2525
str(root_dir / "fortls.py"),
2626
"--incremental_sync",
27-
"--use_signature_help",
2827
]
2928
if fortls_args:
3029
# Input args might not be sanitised, fix that

test/test_server.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from pathlib import Path
2-
31
# from types import NoneType
42
from setup_tests import (
53
path_to_uri,
@@ -233,6 +231,10 @@ def check_return(result_array, checks):
233231
if checks[0] > 0:
234232
assert result_array[0]["label"] == checks[1]
235233
assert result_array[0]["detail"] == checks[2]
234+
try:
235+
assert result_array[0]["insertText"] == checks[3]
236+
except KeyError:
237+
pass
236238

237239
def comp_request(file_path, line, char):
238240
return write_rpc_request(
@@ -296,15 +298,23 @@ def comp_request(file_path, line, char):
296298
file_path = test_dir / "completion" / "test_vis_mod_completion.f90"
297299
string += comp_request(file_path, 12, 16)
298300
string += comp_request(file_path, 12, 24)
299-
errcode, results = run_request(string)
301+
errcode, results = run_request(string, ["--use_signature_help"])
302+
assert errcode == 0
303+
304+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
305+
file_path = test_dir / "test_prog.f08"
306+
string += comp_request(file_path, 12, 6)
307+
errcode, res = run_request(string)
300308
assert errcode == 0
309+
results.extend(res[1:])
310+
301311
#
302312
exp_results = (
303313
# test_prog.f08
304-
[1, "myfun", "DOUBLE PRECISION FUNCTION myfun(n, xval)"],
305-
[9, "glob_sub", "SUBROUTINE glob_sub(n, xval, yval)"],
306-
[1, "bound_nopass", "SUBROUTINE bound_nopass(a, b)"],
307-
[1, "bound_pass", "SUBROUTINE bound_pass(arg1)"],
314+
[1, "myfun", "DOUBLE PRECISION FUNCTION myfun(n, xval)", "myfun"],
315+
[9, "glob_sub", "SUBROUTINE glob_sub(n, xval, yval)", "glob_sub"],
316+
[1, "bound_nopass", "SUBROUTINE bound_nopass(a, b)", "bound_nopass"],
317+
[1, "bound_pass", "SUBROUTINE bound_pass(arg1)", "bound_pass"],
308318
[1, "stretch_vector", "TYPE(scaled_vector)"],
309319
[6, "scale", "TYPE(scale_type)"],
310320
[2, "n", "INTEGER(4)"],
@@ -337,7 +347,12 @@ def comp_request(file_path, line, char):
337347
[10, "READ", "STATEMENT"],
338348
[11, "READ", "STATEMENT"],
339349
# subdir/test_generic.f90
340-
[4, "my_gen", "SUBROUTINE my_gen(self, a, b)"],
350+
[
351+
4,
352+
"my_gen",
353+
"SUBROUTINE my_gen(self, a, b)",
354+
"my_gen(${1:self}, ${2:a}, ${3:b})",
355+
],
341356
# subdir/test_inherit.f90
342357
[1, "val", "REAL(8)"],
343358
# subdir/test_rename.F90
@@ -352,6 +367,14 @@ def comp_request(file_path, line, char):
352367
# completion/test_vis_mod_completion.f90
353368
[1, "some_var", "INTEGER"],
354369
[3, "length", "INTEGER"],
370+
# test_prog.f08, completion without signature_help
371+
# returns the entire completion as a snippet
372+
[
373+
1,
374+
"myfun",
375+
"DOUBLE PRECISION FUNCTION myfun(n, xval)",
376+
"myfun(${1:n}, ${2:xval})",
377+
],
355378
)
356379
assert len(exp_results) + 1 == len(results)
357380
for i in range(len(exp_results)):

0 commit comments

Comments
 (0)