Skip to content

Commit e616843

Browse files
committed
Fix INCLUDE files not in scope #13
1 parent f8b4508 commit e616843

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
multiline but the function body can.
2525
- Fixes objects marked `EXTERNAL` across multiple lines
2626
([#169](https://github.com/hansec/fortran-language-server/issues/169))
27+
- Fixes include with external files
28+
([gnikit/fortls#13](https://github.com/gnikit/fortls/issues/13))
2729

2830
## 1.16.0
2931

fortls/objects.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ def check_scope(
188188
strip_str = strip_str.replace("'", "")
189189
for inc in scope.file_ast.include_statements:
190190
if strip_str == inc.path:
191+
if inc.file is None:
192+
return None
191193
return fortran_include(inc.file.ast, inc.line_number, inc.path)
192194

193195
# Setup USE search

test/test_server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
# from types import NoneType
23
from setup_tests import (
34
run_request,
45
write_rpc_request,
@@ -375,6 +376,10 @@ def sig_request(file_path, line, char):
375376

376377
def test_def():
377378
def check_return(result_array, checks):
379+
# If no definition is given result is None
380+
if result_array is None:
381+
assert not checks[0]
382+
return None
378383
assert result_array["uri"] == path_to_uri(checks[2])
379384
assert result_array["range"]["start"]["line"] == checks[0]
380385
assert result_array["range"]["start"]["line"] == checks[1]
@@ -404,6 +409,7 @@ def def_request(file_path, line, char):
404409
file_path = os.path.join(test_dir, "test_inc.f90")
405410
string += def_request(file_path, 2, 15)
406411
string += def_request(file_path, 10, 2)
412+
string += def_request(file_path, 12, 13)
407413
file_path = os.path.join(test_dir, "subdir", "test_inc2.f90")
408414
string += def_request(file_path, 3, 2)
409415
file_path = os.path.join(test_dir, "subdir", "test_rename.F90")
@@ -428,6 +434,7 @@ def def_request(file_path, line, char):
428434
# test_inc.f90
429435
[2, 2, os.path.join(test_dir, "subdir", "test_inc2.f90")],
430436
[0, 0, os.path.join(test_dir, "subdir", "test_inc2.f90")],
437+
[None],
431438
# subdir/test_inc2.f90
432439
[4, 4, os.path.join(test_dir, "test_inc.f90")],
433440
# subdir/test_rename.F90

test/test_source/test_inc.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ SUBROUTINE test_sub
1010

1111
val2
1212
END SUBROUTINE test_sub
13+
include 'mpi.f'
1314

1415
END MODULE test_mod

0 commit comments

Comments
 (0)