Skip to content

bug: fixes CRITICAL "Unexpected end of scope" #256

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
Jan 13, 2023
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 @@ -26,6 +26,8 @@

### Fixed

- Fixed end of scope for `CRITICAL` keyword blocks
([#255](https://github.com/fortran-lang/fortls/issues/255))
- 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
Expand Down
6 changes: 3 additions & 3 deletions fortls/regex_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class FortranRegularExpressions:
SUBMOD: Pattern = compile(r"[ ]*SUBMODULE[ ]*\(", I)
END_SMOD: Pattern = compile(r"SUBMODULE", I)
END_PRO: Pattern = compile(r"(MODULE)?[ ]*PROCEDURE", I)
BLOCK: Pattern = compile(r"[ ]*([a-z_]\w*[ ]*:[ ]*)?BLOCK(?!\w)", I)
END_BLOCK: Pattern = compile(r"BLOCK", I)
BLOCK: Pattern = compile(r"[ ]*([a-z_]\w*[ ]*:[ ]*)?BLOCK|CRITICAL(?!\w)", I)
END_BLOCK: Pattern = compile(r"BLOCK|CRITICAL", I)
DO: Pattern = compile(r"[ ]*(?:[a-z_]\w*[ ]*:[ ]*)?DO([ ]+[0-9]*|$)", I)
END_DO: Pattern = compile(r"DO", I)
WHERE: Pattern = compile(r"[ ]*WHERE[ ]*\(", I)
Expand All @@ -64,7 +64,7 @@ class FortranRegularExpressions:
INT: Pattern = compile(r"[ ]*(ABSTRACT)?[ ]*INTERFACE[ ]*(\w*)", I)
END_INT: Pattern = compile(r"INTERFACE", I)
END_WORD: Pattern = compile(
r"[ ]*END[ ]*(DO|WHERE|IF|BLOCK|ASSOCIATE|SELECT"
r"[ ]*END[ ]*(DO|WHERE|IF|BLOCK|CRITICAL|ASSOCIATE|SELECT"
r"|TYPE|ENUM|MODULE|SUBMODULE|PROGRAM|INTERFACE"
r"|SUBROUTINE|FUNCTION|PROCEDURE|FORALL)?([ ]+(?!\W)|$)",
I,
Expand Down
12 changes: 12 additions & 0 deletions test/test_server_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,15 @@ def test_attribute_and_variable_name_collision():
errcode, results = run_request(string, ["-n", "1"])
assert errcode == 0
assert results[1]["diagnostics"] == []


def test_critical_scope():
"""Test that critical scopes are correctly parsed."""
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "diag")})
file_path = str(test_dir / "diag" / "tst_critical.f90")
string += write_rpc_notification(
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
)
errcode, results = run_request(string, ["-n", "1"])
assert errcode == 0
assert results[1]["diagnostics"] == []
7 changes: 7 additions & 0 deletions test/test_source/diag/test_critical.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
program test_critical
implicit none
if (.true.) then
critical
end critical
end if
end program test_critical