Skip to content

Commit 0d518d4

Browse files
committed
Adds unittests for hover of literals & parameters
1 parent 6f7d61f commit 0d518d4

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

test/test_server.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,16 @@ def find_in_results(uri, sline):
483483

484484

485485
def test_hover():
486+
def hover_req(file_path: str, ln: int, col: int) -> str:
487+
return write_rpc_request(
488+
1,
489+
"textDocument/hover",
490+
{
491+
"textDocument": {"uri": file_path},
492+
"position": {"line": ln, "character": col},
493+
},
494+
)
495+
486496
def check_return(result_array, checks):
487497
assert len(result_array) == len(checks)
488498
for (i, check) in enumerate(checks):
@@ -491,22 +501,32 @@ def check_return(result_array, checks):
491501
#
492502
string = write_rpc_request(1, "initialize", {"rootPath": test_dir})
493503
file_path = os.path.join(test_dir, "subdir", "test_abstract.f90")
494-
string += write_rpc_request(
495-
2,
496-
"textDocument/hover",
497-
{"textDocument": {"uri": file_path}, "position": {"line": 7, "character": 30}},
498-
)
499-
errcode, results = run_request(string)
504+
string += hover_req(file_path, 7, 30)
505+
file_path = os.path.join(test_dir, "hover", "parameters.f90")
506+
string += hover_req(file_path, 2, 28)
507+
string += hover_req(file_path, 3, 28)
508+
string += hover_req(file_path, 4, 28)
509+
string += hover_req(file_path, 4, 41)
510+
string += hover_req(file_path, 6, 28)
511+
string += hover_req(file_path, 7, 38)
512+
string += hover_req(file_path, 7, 55)
513+
errcode, results = run_request(string, fortls_args=" --variable_hover")
500514
assert errcode == 0
501515
#
502-
check_return(
503-
results[1:],
504-
(
505-
"""SUBROUTINE test(a, b)
516+
ref_results = (
517+
"""SUBROUTINE test(a, b)
506518
INTEGER(4), DIMENSION(3,6), INTENT(IN) :: a
507519
REAL(8), DIMENSION(4), INTENT(OUT) :: b""",
508-
),
520+
"INTEGER, PARAMETER :: var = 1000",
521+
"INTEGER",
522+
"INTEGER, PARAMETER :: var2 = 23",
523+
"INTEGER, PARAMETER :: var3 = var*var2",
524+
"INTEGER, PARAMETER :: var4 = 123",
525+
"DOUBLE PRECISION, PARAMETER :: somevar = 23.12",
526+
"DOUBLE PRECISION, PARAMETER :: some = 1e-19",
509527
)
528+
assert len(ref_results) == len(results) - 1
529+
check_return(results[1:], ref_results)
510530

511531

512532
def test_docs():

test/test_source/.fortls

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"source_dirs": ["subdir"]
3-
}
2+
"source_dirs": [
3+
"**/"
4+
],
5+
"excl_paths": [
6+
"excldir/**"
7+
]
8+
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
program params
2+
implicit none
3+
integer, parameter :: var = &
4+
1000, &
5+
var2 = 23, var3 = &
6+
var*var2, &
7+
var4 = 123
8+
double precision, parameter :: somevar = 23.12, some = 1e-19
9+
end program params

0 commit comments

Comments
 (0)