Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
([#219](https://github.com/fortran-lang/fortls/issues/219))
- Changed hover messages and signature help to use Markdown
([#45](https://github.com/fortran-lang/fortls/issues/45))
- Changed automatic detection of fixed/free-form of files to ignore
preprocessor lines.
([#302](https://github.com/fortran-lang/fortls/pull/302))

### Fixed

Expand Down
23 changes: 23 additions & 0 deletions fortls/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,31 @@ def detect_fixed_format(file_lines: list[str]) -> bool:
Lines wih ampersands are not fixed format
>>> detect_fixed_format(['trailing line & ! comment'])
False

But preprocessor lines will be ignored
>>> detect_fixed_format(
... ['#if defined(A) && !defined(B)', 'C Fixed format', '#endif'])
True

>>> detect_fixed_format(
... ['#if defined(A) && !defined(B)', ' free format', '#endif'])
False

And preprocessor line-continuation is taken into account
>>> detect_fixed_format(
... ['#if defined(A) \\\\ ', ' && !defined(B)', 'C Fixed format', '#endif'])
True

>>> detect_fixed_format(
... ['#if defined(A) \\\\', '&& \\\\', '!defined(B)', ' free format', '#endif'])
False
"""
pp_continue = False
for line in file_lines:
# Ignore preprocessor lines
if line.startswith("#") or pp_continue:
pp_continue = line.rstrip().endswith("\\")
continue
if FRegex.FREE_FORMAT_TEST.match(line):
return False
tmp_match = FRegex.VAR.match(line)
Expand Down