|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +from setup_tests import run_request, test_dir, write_rpc_request |
| 4 | + |
| 5 | + |
| 6 | +def sigh_request(uri: Path, line: int, char: int): |
| 7 | + return write_rpc_request( |
| 8 | + 1, |
| 9 | + "textDocument/signatureHelp", |
| 10 | + { |
| 11 | + "textDocument": {"uri": str(uri)}, |
| 12 | + "position": {"line": line, "character": char}, |
| 13 | + }, |
| 14 | + ) |
| 15 | + |
| 16 | + |
| 17 | +def validate_sigh(results, refs): |
| 18 | + assert results.get("activeParameter", -1) == refs[0] |
| 19 | + signatures = results.get("signatures") |
| 20 | + assert signatures[0].get("label") == refs[2] |
| 21 | + assert len(signatures[0].get("parameters")) == refs[1] |
| 22 | + |
| 23 | + |
| 24 | +def test_subroutine_signature_help(): |
| 25 | + """Test that the signature help is correctly resolved for all arguments and |
| 26 | + that the autocompletion is correct for the subroutine signature. |
| 27 | + """ |
| 28 | + string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)}) |
| 29 | + file_path = test_dir / "test_prog.f08" |
| 30 | + string += sigh_request(file_path, 25, 18) |
| 31 | + string += sigh_request(file_path, 25, 20) |
| 32 | + string += sigh_request(file_path, 25, 22) |
| 33 | + string += sigh_request(file_path, 25, 27) |
| 34 | + string += sigh_request(file_path, 25, 29) |
| 35 | + errcode, results = run_request(string) |
| 36 | + assert errcode == 0 |
| 37 | + |
| 38 | + sub_sig = "test_sig_Sub(arg1, arg2, opt1=opt1, opt2=opt2, opt3=opt3)" |
| 39 | + ref = ( |
| 40 | + [0, 5, sub_sig], |
| 41 | + [1, 5, sub_sig], |
| 42 | + [2, 5, sub_sig], |
| 43 | + [3, 5, sub_sig], |
| 44 | + [4, 5, sub_sig], |
| 45 | + ) |
| 46 | + assert len(ref) == len(results) - 1 |
| 47 | + for i in range(len(ref)): |
| 48 | + validate_sigh(results[i + 1], ref[i]) |
0 commit comments