Skip to content

Commit

Permalink
Fixes import host-association abort
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gnikit committed Dec 22, 2021
1 parent 5bbe881 commit 3f86786
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELONG

## 1.14.4

### Fixes

* Fixes import host association includes (autocomplete work not complete)
([#187](https://github.com/hansec/fortran-language-server/issues/187))

## 1.14.3

### Fixes
Expand Down
43 changes: 25 additions & 18 deletions fortls/parse_fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,27 +726,33 @@ def read_int_def(line):

def read_use_stmt(line):
"""Attempt to read USE statement"""
import_match = IMPORT_REGEX.match(line)
if import_match is not None:
trailing_line = line[import_match.end(0) - 1 :].lower()
import_list = [import_obj.strip() for import_obj in trailing_line.split(",")]
return "import", import_list
use_match = USE_REGEX.match(line)
if use_match is None:
return None
else:
trailing_line = line[use_match.end(0) :].lower()
use_mod = use_match.group(2)
only_list = []
rename_map = {}
if use_match.group(3) is not None:
for only_stmt in trailing_line.split(","):
only_split = only_stmt.split("=>")
only_name = only_split[0].strip()
only_list.append(only_name)
if len(only_split) == 2:
rename_map[only_name] = only_split[1].strip()
return "use", USE_info(use_mod, only_list, rename_map)

trailing_line = line[use_match.end(0) :].lower()
use_mod = use_match.group(2)
only_list = []
rename_map = {}
if use_match.group(3):
for only_stmt in trailing_line.split(","):
only_split = only_stmt.split("=>")
only_name = only_split[0].strip()
only_list.append(only_name)
if len(only_split) == 2:
rename_map[only_name] = only_split[1].strip()
return "use", USE_info(use_mod, only_list, rename_map)


def read_imp_stmt(line):
"""Attempt to read IMPORT statement"""
import_match = IMPORT_REGEX.match(line)
if import_match is None:
return None

trailing_line = line[import_match.end(0) - 1 :].lower()
import_list = [import_obj.strip() for import_obj in trailing_line.split(",")]
return "import", import_list


def read_inc_stmt(line):
Expand Down Expand Up @@ -783,6 +789,7 @@ def read_vis_stmnt(line):
read_type_def,
read_enum_def,
read_use_stmt,
read_imp_stmt,
read_int_def,
read_generic_def,
read_mod_def,
Expand Down
5 changes: 5 additions & 0 deletions test/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ def comp_request(file_path, line, char):
string += comp_request(file_path, 14, 5)
file_path = os.path.join(test_dir, "subdir", "test_vis.f90")
string += comp_request(file_path, 8, 10)
file_path = os.path.join(test_dir, "test_import.f90")
string += comp_request(file_path, 15, 20)
errcode, results = run_request(string)
assert errcode == 0
#
Expand Down Expand Up @@ -364,6 +366,9 @@ def comp_request(file_path, line, char):
[1, "renamed_var2", "REAL(8)"],
# subdir/test_vis.f90
[3, "some_type", "TYPE"],
# test_import.f90
# TODO: this should be 1, mytype2 should not appear in autocomplete
[2, "mytype", "TYPE"],
)
assert len(exp_results) + 1 == len(results)
for i in range(len(exp_results)):
Expand Down
19 changes: 19 additions & 0 deletions test/test_source/test_import.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module mymod
implicit none
private
public mytype, mytype2
integer, public :: int1, int2, int3, int4, int5
type :: mytype
integer :: comp
end type mytype
type :: mytype2
integer :: comp
end type mytype2
interface
subroutine sub()
import int1
import mytype, int2
type(mytype) :: some
end subroutine sub
end interface
end module mymod

0 comments on commit 3f86786

Please sign in to comment.