Skip to content

Commit 6f7d61f

Browse files
committed
Adds hover support for parameter values
Fixes Show constant parameter value in hover #116 Fixes Show constant parameter value in hover #1
1 parent c3752ed commit 6f7d61f

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELONG
22

3+
## 1.16.0
4+
5+
### Adds
6+
7+
- Adds value for `PARAMETER` variables on hover
8+
([#116](https://github.com/hansec/fortran-language-server/issues/116))
9+
([gnikit/fortls#1](https://github.com/gnikit/fortls/issues/1))
10+
311
## 1.15.2
412

513
### Fixes

fortls/objects.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,7 @@ def base_setup(
15811581
self.link_obj = None
15821582
self.type_obj = None
15831583
self.is_const = False
1584+
self.param_val: str = None
15841585
if link_obj is not None:
15851586
self.link_name = link_obj.lower()
15861587
else:
@@ -1664,6 +1665,9 @@ def get_hover(self, long=False, include_doc=True, drop_arg=-1):
16641665
hover_str = ", ".join(
16651666
[self.desc] + get_keywords(self.keywords, self.keyword_info)
16661667
)
1668+
# Add parameter value in the output
1669+
if self.is_parameter() and self.param_val:
1670+
hover_str += f" :: {self.name} = {self.param_val}"
16671671
if include_doc and (doc_str is not None):
16681672
hover_str += "\n {0}".format("\n ".join(doc_str.splitlines()))
16691673
return hover_str, True
@@ -1680,6 +1684,9 @@ def is_callable(self):
16801684
def is_parameter(self):
16811685
return self.is_const
16821686

1687+
def set_parameter_val(self, val: str):
1688+
self.param_val = val
1689+
16831690
def check_definition(self, obj_tree, known_types={}, interface=False):
16841691
# Check for type definition in scope
16851692
type_match = DEF_KIND_REGEX.match(self.desc)

fortls/parse_fortran.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
MOD_REGEX,
9494
NAT_VAR_REGEX,
9595
NON_DEF_REGEX,
96+
PARAMETER_VAL_REGEX,
9697
PP_DEF_REGEX,
9798
PP_INCLUDE_REGEX,
9899
PP_REGEX,
@@ -1554,6 +1555,14 @@ def parser_debug_msg(msg: str, line: str, ln: int):
15541555
keyword_info=keyword_info,
15551556
link_obj=link_name,
15561557
)
1558+
# If the object is fortran_var and a parameter include
1559+
# the value in hover
1560+
if new_var.is_parameter():
1561+
_, col = find_word_in_line(line, name_stripped)
1562+
match = PARAMETER_VAL_REGEX.match(line[col:])
1563+
if match:
1564+
var = match.group(1).strip()
1565+
new_var.set_parameter_val(var)
15571566
file_ast.add_variable(new_var)
15581567
parser_debug_msg("VARIABLE", line, line_number)
15591568

fortls/regex_patterns.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
r"CONTIGUOUS)",
7373
re.I,
7474
)
75+
PARAMETER_VAL_REGEX = re.compile(r"[\w]*[\s\&]*=[\s\&]*([\w\.\*\-\+\\]*)", re.I)
7576
TATTR_LIST_REGEX = re.compile(
7677
r"[ ]*,[ ]*(PUBLIC|PRIVATE|ABSTRACT|EXTENDS\([a-z0-9_]*\))", re.I
7778
)

0 commit comments

Comments
 (0)