Skip to content

Commit

Permalink
fix(parser): support free-form line continuation in lexical tokens
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gnikit committed May 20, 2024
1 parent c8df48b commit 780830f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
([#398](https://github.com/fortran-lang/fortls/issues/398))
- Fixed bug with string quotes not being escaped when looking for parenthesis
([#250](https://github.com/fortran-lang/fortls/issues/250))
- Fixed bug with line continuations in lexical tokens
([#235](https://github.com/fortran-lang/fortls/issues/235))

## 3.0.0

Expand Down
5 changes: 1 addition & 4 deletions fortls/parsers/internal/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,10 +1121,7 @@ def get_code_line(
continue
opt_cont_match = FRegex.FREE_CONT.match(next_line)
if opt_cont_match:
next_line = (
" " * opt_cont_match.end(0)
+ next_line[opt_cont_match.end(0) :]
)
next_line = next_line[opt_cont_match.end(0) :]
post_lines.append(next_line)
line_stripped = strip_strings(next_line, maintain_len=True)
iAmper = line_stripped.find("&")
Expand Down
14 changes: 14 additions & 0 deletions test/test_server_hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,17 @@ def test_complicated_kind_spec():
'```fortran90\nREAL(int(sin(0.5))+8+len("ab))c")-3) :: z\n```',
]
validate_hover(results, ref_results)


def test_multiline_lexical_token():
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "hover")})
file_path = test_dir / "hover" / "multiline_lexical_tokens.f90"
string += hover_req(file_path, 4, 8)
string += hover_req(file_path, 8, 16)
errcode, results = run_request(string, fortls_args=["-n", "1"])
assert errcode == 0
ref_results = [
"```fortran90\nINTEGER :: i\n```",
'```fortran90\nREAL(int(sin(0.5))+8+len("ab))c")-3) :: Z\n```',
]
validate_hover(results, ref_results)
10 changes: 10 additions & 0 deletions test/test_source/hover/multiline_lexical_tokens.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
program multiline_lexical_token
implicit none
inte&
&ger &
:: i
RE&
&AL(int(sin(0.5))&
&+8+len("ab)&
&)c")-3) :: Z
end program

0 comments on commit 780830f

Please sign in to comment.