Skip to content

Commit 9d3f42c

Browse files
committed
Fixes end of scope caused by end named vars
Fixes END variable closes scope prematurely #9 The solution is to perform a negative lookahead for non-word characters
1 parent 43a8d06 commit 9d3f42c

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# CHANGELONG
22

3+
## 1.15.1
4+
5+
### Fixes
6+
7+
- Fixes premature end of scope with variables named `end`
8+
([gnikit/fortls#9](https://github.com/gnikit/fortls/issues/9))
9+
10+
## 1.15.0
11+
12+
### Adds
13+
14+
- Adds `--config` option which allows arbitrary named configuration files
15+
316
## 1.14.4
417

518
### Fixes

fortls/regex_patterns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
END_WORD_REGEX = re.compile(
4646
r"[ ]*END[ ]*(DO|WHERE|IF|BLOCK|ASSOCIATE|SELECT"
4747
r"|TYPE|ENUM|MODULE|SUBMODULE|PROGRAM|INTERFACE"
48-
r"|SUBROUTINE|FUNCTION|PROCEDURE)?([ ]+|$)",
48+
r"|SUBROUTINE|FUNCTION|PROCEDURE)?([ ]+(?!\W)|$)",
4949
re.I,
5050
)
5151
TYPE_DEF_REGEX = re.compile(r"[ ]*(TYPE)[, :]+", re.I)

test/test_server.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -580,23 +580,11 @@ def test_diagnostics():
580580
string += write_rpc_notification(
581581
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
582582
)
583-
# Example of a diagnostics message
584-
# string += write_rpc_notification(
585-
# "textDocument/publishDiagnostics",
586-
# {
587-
# "uri": file_path,
588-
# "diagnostics": [
589-
# {
590-
# "range": {
591-
# "start": {"line": 0, "character": 0},
592-
# "end": {"line": 0, "character": 0},
593-
# },
594-
# "message": "",
595-
# "severity": 0,
596-
# }
597-
# ],
598-
# },
599-
# )
583+
# Tests that variables named end do not close the scope prematurely
584+
file_path = os.path.join(test_dir, "diag", "test_scope_end_name_var.f90")
585+
string += write_rpc_notification(
586+
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
587+
)
600588
errcode, results = run_request(string)
601589
assert errcode == 0
602590
# check that the diagnostics list is empty
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
program scope_end_named_var
2+
implicit none
3+
integer :: end, endif
4+
if (.true.) then
5+
end = 10
6+
end if
7+
end program scope_end_named_var

0 commit comments

Comments
 (0)