Skip to content

Commit d658fb4

Browse files
authored
Merge pull request #239 from fortran-lang/gnikit/issue150
fix: completion of USE ONLY interaces
2 parents f98d79c + ef05393 commit d658fb4

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
### Fixed
2626

27+
- Fixed bug where completion of interfaces in USE ONLY would produce the snippet
28+
([#150](https://github.com/fortran-lang/fortls/issues/150))
2729
- Fixed bug where diagnostic messages were raised for non-existent variables
2830
([#173](https://github.com/fortran-lang/fortls/issues/173))
2931
([#175](https://github.com/fortran-lang/fortls/issues/175))

fortls/langserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def build_comp(
660660
continue
661661
#
662662
name_replace = rename_list[i]
663-
if candidate_type == INTERFACE_TYPE_ID:
663+
if candidate_type == INTERFACE_TYPE_ID and not line_context == "mod_mems":
664664
tmp_list = []
665665
if name_replace is None:
666666
name_replace = candidate.name

test/test_server_completion.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,20 @@ def test_comp_documentation():
377377
]
378378
assert len(exp_results) == len(results[1])
379379
assert exp_results == results[1]
380+
381+
382+
def test_comp_use_only_interface():
383+
"""Test completion of interfaces when using USE ONLY give the right signature."""
384+
string = write_rpc_request(
385+
1, "initialize", {"rootPath": str(test_dir / "completion")}
386+
)
387+
file_path = test_dir / "completion" / "use_only_interface.f90"
388+
string += comp_request(file_path, 21, 29)
389+
errcode, results = run_request(
390+
string,
391+
)
392+
assert errcode == 0
393+
exp_results = [[1, "some_sub", "INTERFACE"]]
394+
assert len(exp_results) == len(results) - 1
395+
for i, ref in enumerate(exp_results):
396+
validate_comp(results[i + 1], ref)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module some_mod
2+
implicit none
3+
private
4+
public :: some_sub
5+
interface some_sub
6+
module procedure a_subroutine
7+
module procedure b_subroutine
8+
end interface
9+
contains
10+
subroutine a_subroutine(x)
11+
integer, intent(in) :: x
12+
write(*,*) 'x = ', x
13+
end subroutine a_subroutine
14+
subroutine b_subroutine(x, y)
15+
integer, intent(in) :: x, y
16+
write(*,*) 'x = ', x
17+
write(*,*) 'y = ', y
18+
end subroutine b_subroutine
19+
end module some_mod
20+
21+
program main
22+
use some_mod, only: some_sub
23+
implicit none
24+
end program main

0 commit comments

Comments
 (0)