Skip to content

Commit 3f86786

Browse files
committed
Fixes import host-association abort
There is still work that needs to be done about suggested autocomplete actions within a scope. Right now we provide objects that are both private and public i.e. import does not impact what appears in autocomplete
1 parent 5bbe881 commit 3f86786

File tree

4 files changed

+56
-18
lines changed

4 files changed

+56
-18
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELONG
22

3+
## 1.14.4
4+
5+
### Fixes
6+
7+
* Fixes import host association includes (autocomplete work not complete)
8+
([#187](https://github.com/hansec/fortran-language-server/issues/187))
9+
310
## 1.14.3
411

512
### Fixes

fortls/parse_fortran.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -726,27 +726,33 @@ def read_int_def(line):
726726

727727
def read_use_stmt(line):
728728
"""Attempt to read USE statement"""
729-
import_match = IMPORT_REGEX.match(line)
730-
if import_match is not None:
731-
trailing_line = line[import_match.end(0) - 1 :].lower()
732-
import_list = [import_obj.strip() for import_obj in trailing_line.split(",")]
733-
return "import", import_list
734729
use_match = USE_REGEX.match(line)
735730
if use_match is None:
736731
return None
737-
else:
738-
trailing_line = line[use_match.end(0) :].lower()
739-
use_mod = use_match.group(2)
740-
only_list = []
741-
rename_map = {}
742-
if use_match.group(3) is not None:
743-
for only_stmt in trailing_line.split(","):
744-
only_split = only_stmt.split("=>")
745-
only_name = only_split[0].strip()
746-
only_list.append(only_name)
747-
if len(only_split) == 2:
748-
rename_map[only_name] = only_split[1].strip()
749-
return "use", USE_info(use_mod, only_list, rename_map)
732+
733+
trailing_line = line[use_match.end(0) :].lower()
734+
use_mod = use_match.group(2)
735+
only_list = []
736+
rename_map = {}
737+
if use_match.group(3):
738+
for only_stmt in trailing_line.split(","):
739+
only_split = only_stmt.split("=>")
740+
only_name = only_split[0].strip()
741+
only_list.append(only_name)
742+
if len(only_split) == 2:
743+
rename_map[only_name] = only_split[1].strip()
744+
return "use", USE_info(use_mod, only_list, rename_map)
745+
746+
747+
def read_imp_stmt(line):
748+
"""Attempt to read IMPORT statement"""
749+
import_match = IMPORT_REGEX.match(line)
750+
if import_match is None:
751+
return None
752+
753+
trailing_line = line[import_match.end(0) - 1 :].lower()
754+
import_list = [import_obj.strip() for import_obj in trailing_line.split(",")]
755+
return "import", import_list
750756

751757

752758
def read_inc_stmt(line):
@@ -783,6 +789,7 @@ def read_vis_stmnt(line):
783789
read_type_def,
784790
read_enum_def,
785791
read_use_stmt,
792+
read_imp_stmt,
786793
read_int_def,
787794
read_generic_def,
788795
read_mod_def,

test/test_server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ def comp_request(file_path, line, char):
315315
string += comp_request(file_path, 14, 5)
316316
file_path = os.path.join(test_dir, "subdir", "test_vis.f90")
317317
string += comp_request(file_path, 8, 10)
318+
file_path = os.path.join(test_dir, "test_import.f90")
319+
string += comp_request(file_path, 15, 20)
318320
errcode, results = run_request(string)
319321
assert errcode == 0
320322
#
@@ -364,6 +366,9 @@ def comp_request(file_path, line, char):
364366
[1, "renamed_var2", "REAL(8)"],
365367
# subdir/test_vis.f90
366368
[3, "some_type", "TYPE"],
369+
# test_import.f90
370+
# TODO: this should be 1, mytype2 should not appear in autocomplete
371+
[2, "mytype", "TYPE"],
367372
)
368373
assert len(exp_results) + 1 == len(results)
369374
for i in range(len(exp_results)):

test/test_source/test_import.f90

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module mymod
2+
implicit none
3+
private
4+
public mytype, mytype2
5+
integer, public :: int1, int2, int3, int4, int5
6+
type :: mytype
7+
integer :: comp
8+
end type mytype
9+
type :: mytype2
10+
integer :: comp
11+
end type mytype2
12+
interface
13+
subroutine sub()
14+
import int1
15+
import mytype, int2
16+
type(mytype) :: some
17+
end subroutine sub
18+
end interface
19+
end module mymod

0 commit comments

Comments
 (0)