Skip to content

fix: flip the condition in strip_comment for fixed format #448

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
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Fixed

- Fixed bug with Fixed Format references being incorrectly detected in comments
([#447](https://github.com/fortran-lang/fortls/issues/447))

## 3.1.2

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion fortls/parsers/internal/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ def get_code_line(
def strip_comment(self, line: str) -> str:
"""Strip comment from line"""
if self.fixed:
if FRegex.FIXED_COMMENT.match(line) and FRegex.FIXED_OPENMP.match(line):
if FRegex.FIXED_COMMENT.match(line) and not FRegex.FIXED_OPENMP.match(line):
return ""
else:
if FRegex.FREE_OPENMP.match(line) is None:
Expand Down
9 changes: 9 additions & 0 deletions test/test_server_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ def test_references():
[free_path, 78, 6, 12],
),
)


def test_references_ignore_comments_fixed():
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "fixed")})
file_path = test_dir / "fixed" / "comment_as_reference.f"
string += ref_req(file_path, 3, 22)
errcode, results = run_request(string)
assert errcode == 0
assert len(results[1]) == 2
5 changes: 5 additions & 0 deletions test/test_source/fixed/comment_as_reference.f
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
program comment_as_reference
C Comment with variable name gets picked as a ref: variable_to_reference
real variable_to_reference
variable_to_reference = 1
end program comment_as_reference