From bf1a0bce63d1aef619d083da11567b01c35c993b Mon Sep 17 00:00:00 2001 From: gnikit Date: Fri, 10 May 2024 15:16:20 +0100 Subject: [PATCH 1/2] fix(debug): config file handling This commit fixes the handling of the config file in the `debug_parser` function. It now correctly checks if the config file exists before attempting to parse it. Additionally, it prints the config details for debugging purposes. --- fortls/debug.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fortls/debug.py b/fortls/debug.py index b23a57e1..59803806 100644 --- a/fortls/debug.py +++ b/fortls/debug.py @@ -439,7 +439,8 @@ def read_config(root: str | None): # Check for config files config_path = locate_config(root) - if not os.path.isfile(config_path): + print(f" Config file = {config_path}") + if config_path is None or not os.path.isfile(config_path): return pp_suffixes, pp_defs, include_dirs try: From dece46a265e2090af057010c22758abd6036cb1a Mon Sep 17 00:00:00 2001 From: gnikit Date: Fri, 10 May 2024 16:19:06 +0100 Subject: [PATCH 2/2] fix(parser): trailing semicolons triggering end of scope diagnostics Fixes #265 --- CHANGELOG.md | 2 ++ fortls/parsers/internal/parser.py | 1 + test/test_parser.py | 9 +++++++++ test/test_source/parse/trailing_semicolon.f90 | 6 ++++++ 4 files changed, 18 insertions(+) create mode 100644 test/test_source/parse/trailing_semicolon.f90 diff --git a/CHANGELOG.md b/CHANGELOG.md index cf515b3c..e0748ef4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,8 @@ ### Fixed +- Fixed end of scope errors raised by trailing semicolon in native parser + ([#265](https://github.com/fortran-lang/fortls/issues/265)) - Fixed bug where parent scope for includes in AST could be `None` ([#329](https://github.com/fortran-lang/fortls/issues/329)) - Fixed preprocessor bug with `if` and `elif` conditionals diff --git a/fortls/parsers/internal/parser.py b/fortls/parsers/internal/parser.py index da08ca1e..1cab8d11 100644 --- a/fortls/parsers/internal/parser.py +++ b/fortls/parsers/internal/parser.py @@ -1350,6 +1350,7 @@ def parse( multi_lines.extendleft(line_stripped.split(";")) line = multi_lines.pop() line_stripped = line + line_no_comment = line # Test for scope end if file_ast.end_scope_regex is not None: match = FRegex.END_WORD.match(line_no_comment) diff --git a/test/test_parser.py b/test/test_parser.py index 9b48dcaf..2478638b 100644 --- a/test/test_parser.py +++ b/test/test_parser.py @@ -39,3 +39,12 @@ def test_private_visibility_interfaces(): err_str, _ = file.load_from_disk() file.parse() assert err_str is None + + +def test_end_scopes_semicolon(): + file_path = test_dir / "parse" / "trailing_semicolon.f90" + file = FortranFile(str(file_path)) + err_str, _ = file.load_from_disk() + ast = file.parse() + assert err_str is None + assert not ast.end_errors diff --git a/test/test_source/parse/trailing_semicolon.f90 b/test/test_source/parse/trailing_semicolon.f90 new file mode 100644 index 00000000..424013c0 --- /dev/null +++ b/test/test_source/parse/trailing_semicolon.f90 @@ -0,0 +1,6 @@ +program trailing_semicolon_in_end_scope + integer :: i + do i=1, 3 + print *, "Hello World!" + end do; +end program trailing_semicolon_in_end_scope