|
19 | 19 | from ...common.language import language_id
|
20 | 20 | from ...common.lsp_types import Hover, MarkupContent, MarkupKind, Position
|
21 | 21 | from ...common.text_document import TextDocument
|
| 22 | +from ..diagnostics.library_doc import KeywordMatcher |
22 | 23 | from ..utils.ast import (
|
23 | 24 | HasTokens,
|
24 | 25 | Token,
|
@@ -74,17 +75,13 @@ async def run() -> Optional[Hover]:
|
74 | 75 | if not result_nodes:
|
75 | 76 | return None
|
76 | 77 |
|
77 |
| - while result_nodes: |
78 |
| - result_node = result_nodes[-1] |
79 |
| - |
| 78 | + for result_node in reversed(result_nodes): |
80 | 79 | method = self._find_method(type(result_node))
|
81 | 80 | if method is not None:
|
82 | 81 | result = await method(result_node, document, position)
|
83 | 82 | if result is not None:
|
84 | 83 | return result
|
85 | 84 |
|
86 |
| - result_nodes = result_nodes[:-1] |
87 |
| - |
88 | 85 | return await self._hover_default(result_nodes, document, position)
|
89 | 86 |
|
90 | 87 | return await run_coroutine_in_thread(run)
|
@@ -127,31 +124,6 @@ async def _hover_default(self, nodes: List[ast.AST], document: TextDocument, pos
|
127 | 124 | pass
|
128 | 125 | return None
|
129 | 126 |
|
130 |
| - async def hover_KeywordName( # noqa: N802 |
131 |
| - self, node: ast.AST, document: TextDocument, position: Position |
132 |
| - ) -> Optional[Hover]: |
133 |
| - from robot.parsing.lexer.tokens import Token as RobotToken |
134 |
| - from robot.parsing.model.statements import KeywordName |
135 |
| - |
136 |
| - namespace = await self.parent.documents_cache.get_namespace(document) |
137 |
| - if namespace is None: |
138 |
| - return None |
139 |
| - |
140 |
| - kw_node = cast(KeywordName, node) |
141 |
| - name_token = kw_node.get_token(RobotToken.KEYWORD_NAME) |
142 |
| - if not name_token: |
143 |
| - return None |
144 |
| - |
145 |
| - result = await namespace.find_keyword(name_token.value) |
146 |
| - |
147 |
| - if result is not None and not result.is_error_handler: |
148 |
| - return Hover( |
149 |
| - contents=MarkupContent(kind=MarkupKind.MARKDOWN, value=result.to_markdown()), |
150 |
| - range=range_from_token_or_node(node, name_token), |
151 |
| - ) |
152 |
| - |
153 |
| - return None |
154 |
| - |
155 | 127 | async def hover_KeywordCall( # noqa: N802
|
156 | 128 | self, node: ast.AST, document: TextDocument, position: Position
|
157 | 129 | ) -> Optional[Hover]:
|
@@ -312,6 +284,31 @@ async def hover_ResourceImport( # noqa: N802
|
312 | 284 | pass
|
313 | 285 | return None
|
314 | 286 |
|
| 287 | + async def hover_KeywordName( # noqa: N802 |
| 288 | + self, node: ast.AST, document: TextDocument, position: Position |
| 289 | + ) -> Optional[Hover]: |
| 290 | + from robot.parsing.lexer.tokens import Token as RobotToken |
| 291 | + from robot.parsing.model.statements import KeywordName |
| 292 | + |
| 293 | + namespace = await self.parent.documents_cache.get_namespace(document) |
| 294 | + if namespace is None: |
| 295 | + return None |
| 296 | + |
| 297 | + kw_node = cast(KeywordName, node) |
| 298 | + name_token = kw_node.get_token(RobotToken.KEYWORD_NAME) |
| 299 | + if not name_token: |
| 300 | + return None |
| 301 | + |
| 302 | + result = (await namespace.get_library_doc()).keywords.get(KeywordMatcher(name_token.value), None) |
| 303 | + |
| 304 | + if result is not None and not result.is_error_handler: |
| 305 | + return Hover( |
| 306 | + contents=MarkupContent(kind=MarkupKind.MARKDOWN, value=result.to_markdown()), |
| 307 | + range=range_from_token_or_node(node, name_token), |
| 308 | + ) |
| 309 | + |
| 310 | + return None |
| 311 | + |
315 | 312 | async def hover_TestCase( # noqa: N802
|
316 | 313 | self, node: ast.AST, document: TextDocument, position: Position
|
317 | 314 | ) -> Optional[Hover]:
|
|
0 commit comments