Skip to content

Commit 780830f

Browse files
committed
fix(parser): support free-form line continuation in lexical tokens
The support is more permissive than the standard dictates and obviously does not comform with all the LSP responses e.g. completions under certain conditions. Fixes #235
1 parent c8df48b commit 780830f

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
([#398](https://github.com/fortran-lang/fortls/issues/398))
99
- Fixed bug with string quotes not being escaped when looking for parenthesis
1010
([#250](https://github.com/fortran-lang/fortls/issues/250))
11+
- Fixed bug with line continuations in lexical tokens
12+
([#235](https://github.com/fortran-lang/fortls/issues/235))
1113

1214
## 3.0.0
1315

fortls/parsers/internal/parser.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,10 +1121,7 @@ def get_code_line(
11211121
continue
11221122
opt_cont_match = FRegex.FREE_CONT.match(next_line)
11231123
if opt_cont_match:
1124-
next_line = (
1125-
" " * opt_cont_match.end(0)
1126-
+ next_line[opt_cont_match.end(0) :]
1127-
)
1124+
next_line = next_line[opt_cont_match.end(0) :]
11281125
post_lines.append(next_line)
11291126
line_stripped = strip_strings(next_line, maintain_len=True)
11301127
iAmper = line_stripped.find("&")

test/test_server_hover.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,17 @@ def test_complicated_kind_spec():
680680
'```fortran90\nREAL(int(sin(0.5))+8+len("ab))c")-3) :: z\n```',
681681
]
682682
validate_hover(results, ref_results)
683+
684+
685+
def test_multiline_lexical_token():
686+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "hover")})
687+
file_path = test_dir / "hover" / "multiline_lexical_tokens.f90"
688+
string += hover_req(file_path, 4, 8)
689+
string += hover_req(file_path, 8, 16)
690+
errcode, results = run_request(string, fortls_args=["-n", "1"])
691+
assert errcode == 0
692+
ref_results = [
693+
"```fortran90\nINTEGER :: i\n```",
694+
'```fortran90\nREAL(int(sin(0.5))+8+len("ab))c")-3) :: Z\n```',
695+
]
696+
validate_hover(results, ref_results)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
program multiline_lexical_token
2+
implicit none
3+
inte&
4+
&ger &
5+
:: i
6+
RE&
7+
&AL(int(sin(0.5))&
8+
&+8+len("ab)&
9+
&)c")-3) :: Z
10+
end program

0 commit comments

Comments
 (0)