|
27 | 27 | ) |
28 | 28 | from robotcode.core.text_document import TextDocument |
29 | 29 | from robotcode.core.utils.logging import TRACE, LoggingDescriptor |
| 30 | +from robotcode.robot.diagnostics.entities import VariableDefinitionType |
30 | 31 | from robotcode.robot.diagnostics.model_helper import ModelHelper |
31 | 32 | from robotcode.robot.utils.ast import ( |
32 | 33 | get_nodes_at_position, |
@@ -117,29 +118,43 @@ def _hover_default(self, nodes: List[ast.AST], document: TextDocument, position: |
117 | 118 | if found_range is not None: |
118 | 119 | highlight_range = found_range |
119 | 120 | if variable.has_value or variable.resolvable: |
120 | | - try: |
121 | | - value = reprlib.repr( |
122 | | - namespace.imports_manager.resolve_variable( |
123 | | - variable.name, |
124 | | - str(document.uri.to_path().parent), |
125 | | - namespace.get_resolvable_variables(nodes, position), |
126 | | - ) |
127 | | - ) |
128 | | - except ( |
129 | | - asyncio.CancelledError, |
130 | | - SystemExit, |
131 | | - KeyboardInterrupt, |
| 121 | + if ( |
| 122 | + variable.type == VariableDefinitionType.BUILTIN_VARIABLE |
| 123 | + and variable.matcher.normalized_name == "empty" |
132 | 124 | ): |
133 | | - raise |
134 | | - except BaseException: |
135 | | - self._logger.exception("Error resolving variable: {e}", level=TRACE) |
136 | | - value = "" |
| 125 | + line = document.get_lines()[found_range.start.line] |
| 126 | + prefix = line[found_range.start.character - 2 : found_range.start.character - 1] |
| 127 | + if prefix == "$": |
| 128 | + value = "''" |
| 129 | + elif prefix == "&": |
| 130 | + value = "{}" |
| 131 | + elif prefix == "@": |
| 132 | + value = "[]" |
| 133 | + else: |
| 134 | + try: |
| 135 | + value = reprlib.repr( |
| 136 | + namespace.imports_manager.resolve_variable( |
| 137 | + variable.name, |
| 138 | + str(document.uri.to_path().parent), |
| 139 | + namespace.get_resolvable_variables(nodes, position), |
| 140 | + ) |
| 141 | + ) |
| 142 | + except ( |
| 143 | + asyncio.CancelledError, |
| 144 | + SystemExit, |
| 145 | + KeyboardInterrupt, |
| 146 | + ): |
| 147 | + raise |
| 148 | + except BaseException: |
| 149 | + self._logger.exception("Error resolving variable: {e}", level=TRACE) |
| 150 | + value = "" |
137 | 151 | else: |
138 | 152 | value = "" |
139 | 153 | if text is None: |
140 | 154 | text = "" |
141 | 155 | if text: |
142 | 156 | text += "\n" |
| 157 | + |
143 | 158 | text += f"| ({variable.type.value}) | {variable.name} | {f' `{value}`' if value else ''} |" |
144 | 159 |
|
145 | 160 | if text: |
|
0 commit comments