|
1 |
| -# TODO: make FORTRAN_EXT_REGEX be able to update from user input extensions |
2 | 1 | # TODO: enable jsonc C-style comments
|
3 | 2 | from __future__ import annotations
|
4 | 3 |
|
|
9 | 8 | import traceback
|
10 | 9 | from multiprocessing import Pool
|
11 | 10 | from pathlib import Path
|
| 11 | +from typing import Pattern |
12 | 12 |
|
13 | 13 | # Local modules
|
14 | 14 | from fortls.constants import (
|
|
52 | 52 | LOGICAL_REGEX,
|
53 | 53 | NUMBER_REGEX,
|
54 | 54 | SQ_STRING_REGEX,
|
| 55 | + src_file_exts, |
55 | 56 | )
|
56 | 57 |
|
57 | 58 | log = logging.getLogger(__name__)
|
58 | 59 | # Global regexes
|
59 |
| -FORTRAN_EXT_REGEX = re.compile(r"\.F(77|90|95|03|08|OR|PP)?$", re.I) |
60 | 60 | # TODO: I think this can be replaced by fortls.regex_patterns type & class
|
61 | 61 | TYPE_DEF_REGEX = re.compile(r"[ ]*(TYPE|CLASS)[ ]*\([a-z0-9_ ]*$", re.I)
|
62 | 62 | # TODO: I think this can be replaced by fortls.regex_patterns
|
@@ -94,13 +94,15 @@ def __init__(self, conn, debug_log=False, settings={}):
|
94 | 94 | self.link_version = 0
|
95 | 95 | self.source_dirs = set()
|
96 | 96 | self.excl_paths = set()
|
97 |
| - self.excl_suffixes = [] |
| 97 | + self.incl_suffixes: list[str] = [] |
| 98 | + self.excl_suffixes: list[str] = [] |
98 | 99 | self.post_messages = []
|
99 | 100 | self.pp_suffixes = None
|
100 | 101 | self.pp_defs = {}
|
101 | 102 | self.include_dirs = []
|
102 | 103 | self.streaming = True
|
103 | 104 | self.debug_log = debug_log
|
| 105 | + self.FORTRAN_SRC_EXT_REGEX: Pattern[str] = src_file_exts() |
104 | 106 | # Intrinsic (re-loaded during initialize)
|
105 | 107 | (
|
106 | 108 | self.statements,
|
@@ -1491,6 +1493,9 @@ def __load_config_file_dirs(self, config_dict) -> None:
|
1491 | 1493 | self.source_dirs = {i for i in self.source_dirs if i not in self.excl_paths}
|
1492 | 1494 |
|
1493 | 1495 | def __load_config_file_general(self, config_dict) -> None:
|
| 1496 | + self.incl_suffixes = config_dict.get("incl_suffixes", []) |
| 1497 | + # Update the source file REGEX |
| 1498 | + self.FORTRAN_SRC_EXT_REGEX = src_file_exts(self.incl_suffixes) |
1494 | 1499 | self.excl_suffixes = config_dict.get("excl_suffixes", [])
|
1495 | 1500 | self.lowercase_intrinsics = config_dict.get(
|
1496 | 1501 | "lowercase_intrinsics", self.lowercase_intrinsics
|
@@ -1535,7 +1540,7 @@ def __add_source_dirs(self) -> None:
|
1535 | 1540 | self.source_dirs = set()
|
1536 | 1541 | for root, dirs, files in os.walk(self.root_path):
|
1537 | 1542 | # Match not found
|
1538 |
| - if not list(filter(FORTRAN_EXT_REGEX.search, files)): |
| 1543 | + if not list(filter(self.FORTRAN_SRC_EXT_REGEX.search, files)): |
1539 | 1544 | continue
|
1540 | 1545 | if root not in self.source_dirs and root not in self.excl_paths:
|
1541 | 1546 | self.source_dirs.add(str(Path(root).resolve()))
|
@@ -1563,7 +1568,7 @@ def __get_source_files(self) -> list[str]:
|
1563 | 1568 | if not os.path.isfile(p):
|
1564 | 1569 | continue
|
1565 | 1570 | # File extension must match supported extensions
|
1566 |
| - if not FORTRAN_EXT_REGEX.search(f): |
| 1571 | + if not self.FORTRAN_SRC_EXT_REGEX.search(f): |
1567 | 1572 | continue
|
1568 | 1573 | # File cannot be in excluded paths/files
|
1569 | 1574 | if p in self.excl_paths:
|
|
0 commit comments