Skip to content

fix: completion of USE ONLY interaces #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

### Fixed

- Fixed bug where completion of interfaces in USE ONLY would produce the snippet
([#150](https://github.com/fortran-lang/fortls/issues/150))
- Fixed bug where diagnostic messages were raised for non-existent variables
([#173](https://github.com/fortran-lang/fortls/issues/173))
([#175](https://github.com/fortran-lang/fortls/issues/175))
Expand Down
2 changes: 1 addition & 1 deletion fortls/langserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def build_comp(
continue
#
name_replace = rename_list[i]
if candidate_type == INTERFACE_TYPE_ID:
if candidate_type == INTERFACE_TYPE_ID and not line_context == "mod_mems":
tmp_list = []
if name_replace is None:
name_replace = candidate.name
Expand Down
17 changes: 17 additions & 0 deletions test/test_server_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,20 @@ def test_comp_documentation():
]
assert len(exp_results) == len(results[1])
assert exp_results == results[1]


def test_comp_use_only_interface():
"""Test completion of interfaces when using USE ONLY give the right signature."""
string = write_rpc_request(
1, "initialize", {"rootPath": str(test_dir / "completion")}
)
file_path = test_dir / "completion" / "use_only_interface.f90"
string += comp_request(file_path, 21, 29)
errcode, results = run_request(
string,
)
assert errcode == 0
exp_results = [[1, "some_sub", "INTERFACE"]]
assert len(exp_results) == len(results) - 1
for i, ref in enumerate(exp_results):
validate_comp(results[i + 1], ref)
24 changes: 24 additions & 0 deletions test/test_source/completion/use_only_interface.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module some_mod
implicit none
private
public :: some_sub
interface some_sub
module procedure a_subroutine
module procedure b_subroutine
end interface
contains
subroutine a_subroutine(x)
integer, intent(in) :: x
write(*,*) 'x = ', x
end subroutine a_subroutine
subroutine b_subroutine(x, y)
integer, intent(in) :: x, y
write(*,*) 'x = ', x
write(*,*) 'y = ', y
end subroutine b_subroutine
end module some_mod

program main
use some_mod, only: some_sub
implicit none
end program main