Skip to content

Commit abd7f39

Browse files
authored
Merge pull request #61 from gnikit/gnikit/issue60
Space separated keywords not being parsed
2 parents 61466da + dbe905a commit abd7f39

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
([#54](https://github.com/gnikit/fortls/issues/54))
99
- Fixed hovering string length size is now matching the string
1010
([#55](https://github.com/gnikit/fortls/issues/55))
11+
- Fixed space separated keywords not being displayed upon hover
12+
([#60](https://github.com/gnikit/fortls/issues/60))
1113

1214
## 2.2.3
1315

fortls/helper_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def map_keywords(keywords: list[str]):
309309
mapped_keywords = []
310310
keyword_info = {}
311311
for keyword in keywords:
312-
keyword_prefix = keyword.split("(")[0].lower()
312+
keyword_prefix = keyword.split("(")[0].lower().strip()
313313
keyword_ind = KEYWORD_ID_DICT.get(keyword_prefix)
314314
# keyword_ind can be 0 which if 0: evaluates to False
315315
if keyword_ind is not None:

fortls/parse_fortran.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ def get_line_context(line: str) -> tuple[str, None] | tuple[str, str]:
144144

145145
def parse_var_keywords(test_str: str) -> tuple[list[str], str]:
146146
"""Parse Fortran variable declaration keywords"""
147+
# Needs to be this way and not simply call finditer because no regex can
148+
# capture nested parenthesis
147149
keyword_match = FRegex.KEYWORD_LIST.match(test_str)
148150
keywords = []
149-
while keyword_match is not None:
151+
while keyword_match:
150152
tmp_str = re.sub(r"^[, ]*", "", keyword_match.group(0))
151153
test_str = test_str[keyword_match.end(0) :]
152154
if tmp_str.lower().startswith("dimension"):

fortls/regex_patterns.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ class FortranRegularExpressions:
7474
KIND_SPEC: Pattern = compile(r"[ ]*([*]?\([ ]*[a-z0-9_*:]|\*[ ]*[0-9:]*)", I)
7575
KEYWORD_LIST: Pattern = compile(
7676
r"[ ]*,[ ]*(PUBLIC|PRIVATE|ALLOCATABLE|"
77-
r"POINTER|TARGET|DIMENSION\(|"
78-
r"OPTIONAL|INTENT\([inout]*\)|DEFERRED|NOPASS|"
79-
r"PASS\([a-z0-9_]*\)|SAVE|PARAMETER|EXTERNAL|"
77+
r"POINTER|TARGET|DIMENSION[ ]*\(|"
78+
r"OPTIONAL|INTENT[ ]*\([ ]*(?:IN|OUT|INOUT)[ ]*\)|DEFERRED|NOPASS|"
79+
r"PASS[ ]*\(\w*\)|SAVE|PARAMETER|EXTERNAL|"
8080
r"CONTIGUOUS)",
8181
I,
8282
)

test/test_server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,9 @@ def check_return(result_array, checks):
594594
string += hover_req(file_path, 46, 11)
595595
string += hover_req(file_path, 51, 11)
596596
string += hover_req(file_path, 55, 11)
597+
file_path = test_dir / "hover" / "spaced_keywords.f90"
598+
string += hover_req(file_path, 1, 45)
599+
string += hover_req(file_path, 2, 99)
597600
file_path = test_dir / "hover" / "recursive.f90"
598601
string += hover_req(file_path, 9, 40)
599602
file_path = test_dir / "subdir" / "test_submod.F90"
@@ -655,6 +658,9 @@ def check_return(result_array, checks):
655658
"""FUNCTION fun7() RESULT(val)
656659
TYPE(c_ptr) :: val""",
657660
"""TYPE(c_ptr) FUNCTION c_loc(x) RESULT(c_loc)""",
661+
"""REAL, DIMENSION(:, :), INTENT(IN)""",
662+
"""REAL, DIMENSION( SIZE(ARG1, 1), MAXVAL([SIZE(ARG1, 2), """
663+
"""SIZE(ARG1, 1)]) ), INTENT(OUT)""",
658664
"""RECURSIVE SUBROUTINE recursive_assign_descending(node, vector, current_loc)
659665
TYPE(tree_inode), POINTER, INTENT(IN) :: node
660666
INTEGER, DIMENSION(:), INTENT(INOUT) :: vector
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
subroutine spaced_keywords(arg1, arg2)
2+
real, dimension (:, :), intent (in) :: arg1
3+
real, dimension ( size(arg1, 1), maxval([size(arg1, 2), size(arg1, 1)]) ), intent (out) :: arg2
4+
end subroutine spaced_keywords

0 commit comments

Comments
 (0)