Skip to content

Commit 20e41f2

Browse files
committed
Adds option to disable Fortran string stipping
1 parent 0d518d4 commit 20e41f2

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

fortls/langserver.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,44 @@ def init_file(filepath, pp_defs, pp_suffixes, include_dirs):
8181
return file_obj, None
8282

8383

84-
def get_line_prefix(pre_lines, curr_line, iChar):
85-
"""Get code line prefix from current line and preceding continuation lines"""
86-
if (curr_line is None) or (iChar > len(curr_line)) or (curr_line.startswith("#")):
84+
def get_line_prefix(pre_lines: list, curr_line: str, col: int, qs: bool = True) -> str:
85+
"""Get code line prefix from current line and preceding continuation lines
86+
87+
Parameters
88+
----------
89+
pre_lines : list
90+
for multiline cases get all the previous, relevant lines
91+
curr_line : str
92+
the current line
93+
col : int
94+
column index of the current line
95+
qs : bool, optional
96+
strip quotes i.e. string literals from `curr_line` and `pre_lines`.
97+
Need this disable when hovering over string literals, by default True
98+
99+
Returns
100+
-------
101+
str
102+
part of the line including any relevant line continuations before `col`
103+
"""
104+
if (curr_line is None) or (col > len(curr_line)) or (curr_line.startswith("#")):
87105
return None
88106
prepend_string = "".join(pre_lines)
89107
curr_line = prepend_string + curr_line
90-
iChar += len(prepend_string)
91-
line_prefix = curr_line[:iChar].lower()
108+
col += len(prepend_string)
109+
line_prefix = curr_line[:col].lower()
92110
# Ignore string literals
93-
if (line_prefix.find("'") > -1) or (line_prefix.find('"') > -1):
94-
sq_count = 0
95-
dq_count = 0
96-
for char in line_prefix:
97-
if (char == "'") and (dq_count % 2 == 0):
98-
sq_count += 1
99-
elif (char == '"') and (sq_count % 2 == 0):
100-
dq_count += 1
101-
if (dq_count % 2 == 1) or (sq_count % 2 == 1):
102-
return None
111+
if qs:
112+
if (line_prefix.find("'") > -1) or (line_prefix.find('"') > -1):
113+
sq_count = 0
114+
dq_count = 0
115+
for char in line_prefix:
116+
if (char == "'") and (dq_count % 2 == 0):
117+
sq_count += 1
118+
elif (char == '"') and (sq_count % 2 == 0):
119+
dq_count += 1
120+
if (dq_count % 2 == 1) or (sq_count % 2 == 1):
121+
return None
103122
return line_prefix
104123

105124

0 commit comments

Comments
 (0)