Skip to content

Commit c8df48b

Browse files
authored
Merge pull request #400 from fortran-lang/fix/complicated-kind-args
fix: properly locates closing parenthesis in the presence of quotes
2 parents f29b02d + c71e8a8 commit c8df48b

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
- Fixed bug where parser would crash when trying to retrieve an invalid line no.
88
([#398](https://github.com/fortran-lang/fortls/issues/398))
9+
- Fixed bug with string quotes not being escaped when looking for parenthesis
10+
([#250](https://github.com/fortran-lang/fortls/issues/250))
911

1012
## 3.0.0
1113

fortls/helper_functions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,21 @@ def find_paren_match(string: str) -> int:
260260
261261
>>> find_paren_match('a, (b, (c, d)')
262262
-1
263+
264+
>>> find_paren_match('nt(sin(0.5))+8+len("ab((c")-3) :: y')
265+
29
266+
267+
>>> find_paren_match("nt(sin(0.5))+8+len('ab))c')-3) :: y")
268+
29
263269
"""
264270
paren_count = 1
271+
quote_state = {"'": False, '"': False}
265272
for i, char in enumerate(string):
273+
if char in quote_state:
274+
quote_state[char] = not quote_state[char]
275+
if any(quote_state.values()):
276+
continue
277+
266278
if char == "(":
267279
paren_count += 1
268280
elif char == ")":

test/test_server_hover.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,3 +666,17 @@ def test_types():
666666
"```fortran90\nTYPE, EXTENDS(extends_t) :: a_t\n```",
667667
]
668668
validate_hover(results, ref_results)
669+
670+
671+
def test_complicated_kind_spec():
672+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "hover")})
673+
file_path = test_dir / "hover" / "complicated_kind_spec.f90"
674+
string += hover_req(file_path, 1, 40)
675+
string += hover_req(file_path, 2, 40)
676+
errcode, results = run_request(string, fortls_args=["-n", "1"])
677+
assert errcode == 0
678+
ref_results = [
679+
'```fortran90\nREAL(int(sin(0.5))+8+len("ab((c")-3) :: y\n```',
680+
'```fortran90\nREAL(int(sin(0.5))+8+len("ab))c")-3) :: z\n```',
681+
]
682+
validate_hover(results, ref_results)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
program complicated_kind_spec
2+
real(int(sin(0.5))+8+len("ab((c")-3) :: y
3+
real(int(sin(0.5))+8+len("ab))c")-3) :: z
4+
end program

0 commit comments

Comments
 (0)