1- from __future__ import annotations
2-
31import ast
4- import asyncio
5- from typing import TYPE_CHECKING , Any , Awaitable , Callable , List , Optional , Type , cast
2+ from typing import TYPE_CHECKING , Any , Callable , List , Optional , Type , cast
63
74from robot .parsing .lexer .tokens import Token
5+ from robotcode .core .concurrent import check_current_thread_canceled
86from robotcode .core .lsp .types import InlayHint , InlayHintKind , Range
97from robotcode .core .utils .logging import LoggingDescriptor
108from robotcode .robot .diagnostics .library_doc import KeywordArgumentKind , KeywordDoc , LibraryDoc
2220from .protocol_part import RobotLanguageServerProtocolPart
2321
2422_HandlerMethod = Callable [
25- [TextDocument , Range , ast .AST , ast .AST , Namespace , InlayHintsConfig ], Awaitable [ Optional [List [InlayHint ] ]]
23+ [TextDocument , Range , ast .AST , ast .AST , Namespace , InlayHintsConfig ], Optional [List [InlayHint ]]
2624]
2725
2826
2927class RobotInlayHintProtocolPart (RobotLanguageServerProtocolPart , ModelHelperMixin ):
3028 _logger = LoggingDescriptor ()
3129
32- def __init__ (self , parent : RobotLanguageServerProtocol ) -> None :
30+ def __init__ (self , parent : " RobotLanguageServerProtocol" ) -> None :
3331 super ().__init__ (parent )
3432
3533 parent .inlay_hint .collect .add (self .collect )
3634
37- async def get_config (self , document : TextDocument ) -> Optional [InlayHintsConfig ]:
35+ def get_config (self , document : TextDocument ) -> Optional [InlayHintsConfig ]:
3836 folder = self .parent .workspace .get_workspace_folder (document .uri )
3937 if folder is None :
4038 return None
4139
42- return await self .parent .workspace .get_configuration_async (InlayHintsConfig , folder .uri )
40+ return self .parent .workspace .get_configuration (InlayHintsConfig , folder .uri )
4341
4442 def _find_method (self , cls : Type [Any ]) -> Optional [_HandlerMethod ]:
4543 if cls is ast .AST :
@@ -58,8 +56,8 @@ def _find_method(self, cls: Type[Any]) -> Optional[_HandlerMethod]:
5856
5957 @language_id ("robotframework" )
6058 @_logger .call
61- async def collect (self , sender : Any , document : TextDocument , range : Range ) -> Optional [List [InlayHint ]]:
62- config = await self .get_config (document )
59+ def collect (self , sender : Any , document : TextDocument , range : Range ) -> Optional [List [InlayHint ]]:
60+ config = self .get_config (document )
6361 if config is None or not config .parameter_names and not config .namespaces :
6462 return None
6563
@@ -69,6 +67,8 @@ async def collect(self, sender: Any, document: TextDocument, range: Range) -> Op
6967 result : List [InlayHint ] = []
7068
7169 for node in iter_nodes (model ):
70+ check_current_thread_canceled ()
71+
7272 node_range = range_from_node (node )
7373 if node_range .end < range .start :
7474 continue
@@ -78,13 +78,13 @@ async def collect(self, sender: Any, document: TextDocument, range: Range) -> Op
7878
7979 method = self ._find_method (type (node ))
8080 if method is not None :
81- r = await method (document , range , node , model , namespace , config )
81+ r = method (document , range , node , model , namespace , config )
8282 if r is not None :
8383 result .extend (r )
8484
8585 return result
8686
87- async def _handle_keywordcall_fixture_template (
87+ def _handle_keywordcall_fixture_template (
8888 self ,
8989 keyword_token : Token ,
9090 arguments : List [Token ],
@@ -107,9 +107,9 @@ async def _handle_keywordcall_fixture_template(
107107 if kw_doc is None :
108108 return None
109109
110- return await self ._get_inlay_hint (keyword_token , kw_doc , arguments , namespace , config )
110+ return self ._get_inlay_hint (keyword_token , kw_doc , arguments , namespace , config )
111111
112- async def _get_inlay_hint (
112+ def _get_inlay_hint (
113113 self ,
114114 keyword_token : Optional [Token ],
115115 kw_doc : KeywordDoc ,
@@ -197,7 +197,7 @@ async def _get_inlay_hint(
197197
198198 return result
199199
200- async def handle_KeywordCall ( # noqa: N802
200+ def handle_KeywordCall ( # noqa: N802
201201 self ,
202202 document : TextDocument ,
203203 range : Range ,
@@ -215,9 +215,9 @@ async def handle_KeywordCall( # noqa: N802
215215 return None
216216
217217 arguments = keyword_call .get_tokens (RobotToken .ARGUMENT )
218- return await self ._handle_keywordcall_fixture_template (keyword_token , arguments , namespace , config )
218+ return self ._handle_keywordcall_fixture_template (keyword_token , arguments , namespace , config )
219219
220- async def handle_Fixture ( # noqa: N802
220+ def handle_Fixture ( # noqa: N802
221221 self ,
222222 document : TextDocument ,
223223 range : Range ,
@@ -235,9 +235,9 @@ async def handle_Fixture( # noqa: N802
235235 return None
236236
237237 arguments = fixture .get_tokens (RobotToken .ARGUMENT )
238- return await self ._handle_keywordcall_fixture_template (keyword_token , arguments , namespace , config )
238+ return self ._handle_keywordcall_fixture_template (keyword_token , arguments , namespace , config )
239239
240- async def handle_TestTemplate ( # noqa: N802
240+ def handle_TestTemplate ( # noqa: N802
241241 self ,
242242 document : TextDocument ,
243243 range : Range ,
@@ -254,9 +254,9 @@ async def handle_TestTemplate( # noqa: N802
254254 if keyword_token is None or not keyword_token .value :
255255 return None
256256
257- return await self ._handle_keywordcall_fixture_template (keyword_token , [], namespace , config )
257+ return self ._handle_keywordcall_fixture_template (keyword_token , [], namespace , config )
258258
259- async def handle_Template ( # noqa: N802
259+ def handle_Template ( # noqa: N802
260260 self ,
261261 document : TextDocument ,
262262 range : Range ,
@@ -273,9 +273,9 @@ async def handle_Template( # noqa: N802
273273 if keyword_token is None or not keyword_token .value :
274274 return None
275275
276- return await self ._handle_keywordcall_fixture_template (keyword_token , [], namespace , config )
276+ return self ._handle_keywordcall_fixture_template (keyword_token , [], namespace , config )
277277
278- async def handle_LibraryImport ( # noqa: N802
278+ def handle_LibraryImport ( # noqa: N802
279279 self ,
280280 document : TextDocument ,
281281 range : Range ,
@@ -306,19 +306,20 @@ async def handle_LibraryImport( # noqa: N802
306306 variables = namespace .get_resolvable_variables (),
307307 )
308308
309- except (asyncio . CancelledError , SystemExit , KeyboardInterrupt ):
309+ except (SystemExit , KeyboardInterrupt ):
310310 raise
311- except BaseException :
311+ except BaseException as e :
312+ self ._logger .exception (e )
312313 return None
313314
314315 arguments = library_node .get_tokens (RobotToken .ARGUMENT )
315316
316317 for kw_doc in lib_doc .inits :
317- return await self ._get_inlay_hint (None , kw_doc , arguments , namespace , config )
318+ return self ._get_inlay_hint (None , kw_doc , arguments , namespace , config )
318319
319320 return None
320321
321- async def handle_VariablesImport ( # noqa: N802
322+ def handle_VariablesImport ( # noqa: N802
322323 self ,
323324 document : TextDocument ,
324325 range : Range ,
@@ -352,14 +353,15 @@ async def handle_VariablesImport( # noqa: N802
352353 variables = namespace .get_resolvable_variables (),
353354 )
354355
355- except (asyncio . CancelledError , SystemExit , KeyboardInterrupt ):
356+ except (SystemExit , KeyboardInterrupt ):
356357 raise
357- except BaseException :
358+ except BaseException as e :
359+ self ._logger .exception (e )
358360 return None
359361
360362 arguments = library_node .get_tokens (RobotToken .ARGUMENT )
361363
362364 for kw_doc in lib_doc .inits :
363- return await self ._get_inlay_hint (None , kw_doc , arguments , namespace , config )
365+ return self ._get_inlay_hint (None , kw_doc , arguments , namespace , config )
364366
365367 return None
0 commit comments