|
12 | 12 | from pathlib import Path
|
13 | 13 |
|
14 | 14 | # Local modules
|
| 15 | +from fortls.constants import FORTRAN_LITERAL |
15 | 16 | from fortls.helper_functions import expand_name
|
16 | 17 | from fortls.intrinsics import (
|
17 | 18 | get_intrinsic_keywords,
|
@@ -809,29 +810,26 @@ def get_definition(self, def_file, def_line, def_char, hover_req=False):
|
809 | 810 |
|
810 | 811 | # If we have a Fortran literal constant e.g. 100, .false., etc.
|
811 | 812 | # Return a dummy object with the correct type & position in the doc
|
812 |
| - if ( |
813 |
| - hover_req |
814 |
| - and curr_scope |
815 |
| - and ( |
816 |
| - NUMBER_REGEX.match(def_name) |
817 |
| - or LOGICAL_REGEX.match(def_name) |
818 |
| - or SQ_STRING_REGEX.match(def_name) |
819 |
| - or DQ_STRING_REGEX.match(def_name) |
820 |
| - ) |
821 |
| - ): |
822 |
| - # The description name chosen is non-ambiguous and cannot naturally |
823 |
| - # occur in Fortran (with/out C preproc) code |
824 |
| - # It is invalid syntax to define a type starting with numerics |
825 |
| - # it cannot also be a comment that requires !, c, d |
826 |
| - # and ^= (xor_eq) operator is invalid in Fortran C++ preproc |
827 |
| - var_obj = fortran_var( |
828 |
| - curr_scope.file_ast, |
829 |
| - def_line + 1, |
830 |
| - def_name, |
831 |
| - "0^=__LITERAL_INTERNAL_DUMMY_VAR_", |
832 |
| - curr_scope.keywords, |
833 |
| - ) |
834 |
| - return var_obj |
| 813 | + if hover_req and curr_scope: |
| 814 | + var_type = None |
| 815 | + if NUMBER_REGEX.match(def_name): |
| 816 | + if any(s in def_name for s in [".", "e", "d"]): |
| 817 | + var_type = f"{FORTRAN_LITERAL}REAL" |
| 818 | + else: |
| 819 | + var_type = f"{FORTRAN_LITERAL}INTEGER" |
| 820 | + elif LOGICAL_REGEX.match(def_name): |
| 821 | + var_type = f"{FORTRAN_LITERAL}LOGICAL" |
| 822 | + elif SQ_STRING_REGEX.match(def_name) or DQ_STRING_REGEX.match(def_name): |
| 823 | + var_type = f"{FORTRAN_LITERAL}STRING" |
| 824 | + if var_type: |
| 825 | + return fortran_var( |
| 826 | + curr_scope.file_ast, |
| 827 | + def_line + 1, |
| 828 | + def_name, |
| 829 | + var_type, |
| 830 | + curr_scope.keywords, |
| 831 | + ) |
| 832 | + |
835 | 833 | else:
|
836 | 834 | return var_obj
|
837 | 835 | return None
|
@@ -1119,9 +1117,20 @@ def create_signature_hover():
|
1119 | 1117 | elif self.variable_hover and (var_type == VAR_TYPE_ID):
|
1120 | 1118 | # Unless we have a Fortran literal include the desc in the hover msg
|
1121 | 1119 | # See get_definition for an explanaiton about this default name
|
1122 |
| - if var_obj.desc != "0^=__LITERAL_INTERNAL_DUMMY_VAR_": |
| 1120 | + if not var_obj.desc.startswith(FORTRAN_LITERAL): |
1123 | 1121 | hover_str, highlight = var_obj.get_hover()
|
1124 | 1122 | hover_array.append(create_hover(hover_str, highlight))
|
| 1123 | + # Hover for Literal variables |
| 1124 | + elif var_obj.desc.endswith("REAL"): |
| 1125 | + hover_array.append(create_hover("REAL", True)) |
| 1126 | + elif var_obj.desc.endswith("INTEGER"): |
| 1127 | + hover_array.append(create_hover("INTEGER", True)) |
| 1128 | + elif var_obj.desc.endswith("LOGICAL"): |
| 1129 | + hover_array.append(create_hover("LOGICAL", True)) |
| 1130 | + elif var_obj.desc.endswith("STRING"): |
| 1131 | + hover_str = f"CHARACTER(LEN={len(var_obj.name)})" |
| 1132 | + hover_array.append(create_hover(hover_str, True)) |
| 1133 | + |
1125 | 1134 | # Include the signature if one is present e.g. if in an argument list
|
1126 | 1135 | if self.hover_signature:
|
1127 | 1136 | hover_str = create_signature_hover()
|
|
0 commit comments