diff --git a/CHANGELOG.md b/CHANGELOG.md index fed02d79..0ceb85c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/fortls/parse_fortran.py b/fortls/parse_fortran.py index 2aca1a04..1c7afe3c 100644 --- a/fortls/parse_fortran.py +++ b/fortls/parse_fortran.py @@ -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): @@ -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, diff --git a/test/test_server.py b/test/test_server.py index 6c4ba819..6de7067b 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -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 # @@ -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)): diff --git a/test/test_source/test_import.f90 b/test/test_source/test_import.f90 new file mode 100644 index 00000000..72eeec9d --- /dev/null +++ b/test/test_source/test_import.f90 @@ -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