Skip to content

fix: find reference in USE after comment #474

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 1 commit into from
Mar 16, 2025
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: 1 addition & 1 deletion fortls/parsers/internal/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def read_use_stmt(line: str) -> tuple[Literal["use"], Use] | None:
if use_match is None:
return None

trailing_line = line[use_match.end(0) :].lower()
trailing_line = line[use_match.end(0) :].lower().split("!")[0]
use_mod = use_match.group(2)
only_list: set[str] = set()
rename_map: dict[str, str] = {}
Expand Down
15 changes: 15 additions & 0 deletions test/test_server_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,18 @@ def test_references_ignore_comments_fixed():
errcode, results = run_request(string)
assert errcode == 0
assert len(results[1]) == 2


def test_references_ignore_comments_on_use_import():
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "use")})
file_path = test_dir / "use" / "comment_after_use.f90"
string += ref_req(file_path, 6, 31)
errcode, results = run_request(string, ["-n", "1"])
assert errcode == 0
validate_refs(
results[1],
(
[str(file_path), 1, 15, 27],
[str(file_path), 5, 23, 35],
),
)
7 changes: 7 additions & 0 deletions test/test_source/use/comment_after_use.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module dep_mod
integer :: dep_variable
end module dep_mod

module user_mod
use dep_mod, only: dep_variable ! disabling comment
end module user_mod