Skip to content

Commit ac81470

Browse files
committed
Minor changes
1 parent a5b3468 commit ac81470

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

fortls/langserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ def create_signature_hover():
11061106
# Construct hover information
11071107
var_type = var_obj.get_type()
11081108
hover_array = []
1109-
if (var_type == SUBROUTINE_TYPE_ID) or (var_type == FUNCTION_TYPE_ID):
1109+
if var_type in (SUBROUTINE_TYPE_ID, FUNCTION_TYPE_ID):
11101110
hover_str, highlight = var_obj.get_hover(long=True)
11111111
hover_array.append(create_hover(hover_str, highlight))
11121112
elif var_type == INTERFACE_TYPE_ID:

fortls/parse_fortran.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
BLOCK_REGEX,
4949
CALL_REGEX,
5050
CONTAINS_REGEX,
51+
DEFINED_REGEX,
5152
DO_REGEX,
5253
END_ASSOCIATE_REGEX,
5354
END_BLOCK_REGEX,
@@ -1034,7 +1035,7 @@ def preprocess_file(
10341035
# Look for and mark excluded preprocessor paths in file
10351036
# Initial implementation only looks for "if" and "ifndef" statements.
10361037
# For "if" statements all blocks are excluded except the "else" block if present
1037-
# For "ifndef" statements all blocks excluding the first block are exlucded
1038+
# For "ifndef" statements all blocks excluding the first block are excluded
10381039
def eval_pp_if(text, defs={}):
10391040
def replace_ops(expr):
10401041
expr = expr.replace("&&", " and ")
@@ -1045,9 +1046,6 @@ def replace_ops(expr):
10451046
return expr
10461047

10471048
def replace_defined(line):
1048-
DEFINED_REGEX = re.compile(
1049-
r"defined[ ]*\([ ]*([a-z_][a-z0-9_]*)[ ]*\)", re.I
1050-
)
10511049
i0 = 0
10521050
out_line = ""
10531051
for match in DEFINED_REGEX.finditer(line):
@@ -1106,7 +1104,7 @@ def replace_vars(line):
11061104
continue
11071105
# Handle conditional statements
11081106
match = PP_REGEX.match(line)
1109-
if match is not None:
1107+
if match:
11101108
output_file.append(line)
11111109
def_name = None
11121110
if_start = False
@@ -1192,6 +1190,9 @@ def replace_vars(line):
11921190
log.debug(f"{line.strip()} !!! Include statement({i+1})")
11931191
include_filename = match.group(1).replace('"', "")
11941192
include_path = None
1193+
# Intentionally keep this as a list and not a set. There are cases
1194+
# where projects play tricks with the include order of their headers
1195+
# to get their codes to compile. Using a set would not permit that.
11951196
for include_dir in include_dirs:
11961197
include_path_tmp = os.path.join(include_dir, include_filename)
11971198
if os.path.isfile(include_path_tmp):
@@ -1221,7 +1222,7 @@ def replace_vars(line):
12211222
else:
12221223
log.debug(f"{line.strip()} !!! Could not locate include file ({i+1})")
12231224

1224-
#
1225+
# Substitute (if any) read in preprocessor macros
12251226
for def_tmp, value in defs_tmp.items():
12261227
def_regex = def_regexes.get(def_tmp)
12271228
if def_regex is None:

fortls/regex_patterns.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
FREE_OPENMP_MATCH = re.compile(r"[ ]*!\$OMP", re.I)
103103
FREE_FORMAT_TEST = re.compile(r"[ ]{1,4}[a-z]", re.I)
104104
# Preprocessor mathching rules
105+
DEFINED_REGEX = re.compile(r"defined[ ]*\([ ]*([a-z_][a-z0-9_]*)[ ]*\)", re.I)
105106
PP_REGEX = re.compile(r"#(if |ifdef|ifndef|else|elif|endif)")
106107
PP_DEF_REGEX = re.compile(r"#(define|undef)[ ]*([a-z0-9_]+)", re.I)
107108
PP_DEF_TEST_REGEX = re.compile(r"(![ ]*)?defined[ ]*\([ ]*([a-z0-9_]*)[ ]*\)$", re.I)

0 commit comments

Comments
 (0)