1
- from __future__ import annotations
2
-
3
1
import 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
6
3
7
4
from robot .parsing .lexer .tokens import Token
5
+ from robotcode .core .concurrent import check_current_thread_canceled
8
6
from robotcode .core .lsp .types import InlayHint , InlayHintKind , Range
9
7
from robotcode .core .utils .logging import LoggingDescriptor
10
8
from robotcode .robot .diagnostics .library_doc import KeywordArgumentKind , KeywordDoc , LibraryDoc
22
20
from .protocol_part import RobotLanguageServerProtocolPart
23
21
24
22
_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 ]]
26
24
]
27
25
28
26
29
27
class RobotInlayHintProtocolPart (RobotLanguageServerProtocolPart , ModelHelperMixin ):
30
28
_logger = LoggingDescriptor ()
31
29
32
- def __init__ (self , parent : RobotLanguageServerProtocol ) -> None :
30
+ def __init__ (self , parent : " RobotLanguageServerProtocol" ) -> None :
33
31
super ().__init__ (parent )
34
32
35
33
parent .inlay_hint .collect .add (self .collect )
36
34
37
- async def get_config (self , document : TextDocument ) -> Optional [InlayHintsConfig ]:
35
+ def get_config (self , document : TextDocument ) -> Optional [InlayHintsConfig ]:
38
36
folder = self .parent .workspace .get_workspace_folder (document .uri )
39
37
if folder is None :
40
38
return None
41
39
42
- return await self .parent .workspace .get_configuration_async (InlayHintsConfig , folder .uri )
40
+ return self .parent .workspace .get_configuration (InlayHintsConfig , folder .uri )
43
41
44
42
def _find_method (self , cls : Type [Any ]) -> Optional [_HandlerMethod ]:
45
43
if cls is ast .AST :
@@ -58,8 +56,8 @@ def _find_method(self, cls: Type[Any]) -> Optional[_HandlerMethod]:
58
56
59
57
@language_id ("robotframework" )
60
58
@_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 )
63
61
if config is None or not config .parameter_names and not config .namespaces :
64
62
return None
65
63
@@ -69,6 +67,8 @@ async def collect(self, sender: Any, document: TextDocument, range: Range) -> Op
69
67
result : List [InlayHint ] = []
70
68
71
69
for node in iter_nodes (model ):
70
+ check_current_thread_canceled ()
71
+
72
72
node_range = range_from_node (node )
73
73
if node_range .end < range .start :
74
74
continue
@@ -78,13 +78,13 @@ async def collect(self, sender: Any, document: TextDocument, range: Range) -> Op
78
78
79
79
method = self ._find_method (type (node ))
80
80
if method is not None :
81
- r = await method (document , range , node , model , namespace , config )
81
+ r = method (document , range , node , model , namespace , config )
82
82
if r is not None :
83
83
result .extend (r )
84
84
85
85
return result
86
86
87
- async def _handle_keywordcall_fixture_template (
87
+ def _handle_keywordcall_fixture_template (
88
88
self ,
89
89
keyword_token : Token ,
90
90
arguments : List [Token ],
@@ -107,9 +107,9 @@ async def _handle_keywordcall_fixture_template(
107
107
if kw_doc is None :
108
108
return None
109
109
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 )
111
111
112
- async def _get_inlay_hint (
112
+ def _get_inlay_hint (
113
113
self ,
114
114
keyword_token : Optional [Token ],
115
115
kw_doc : KeywordDoc ,
@@ -197,7 +197,7 @@ async def _get_inlay_hint(
197
197
198
198
return result
199
199
200
- async def handle_KeywordCall ( # noqa: N802
200
+ def handle_KeywordCall ( # noqa: N802
201
201
self ,
202
202
document : TextDocument ,
203
203
range : Range ,
@@ -215,9 +215,9 @@ async def handle_KeywordCall( # noqa: N802
215
215
return None
216
216
217
217
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 )
219
219
220
- async def handle_Fixture ( # noqa: N802
220
+ def handle_Fixture ( # noqa: N802
221
221
self ,
222
222
document : TextDocument ,
223
223
range : Range ,
@@ -235,9 +235,9 @@ async def handle_Fixture( # noqa: N802
235
235
return None
236
236
237
237
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 )
239
239
240
- async def handle_TestTemplate ( # noqa: N802
240
+ def handle_TestTemplate ( # noqa: N802
241
241
self ,
242
242
document : TextDocument ,
243
243
range : Range ,
@@ -254,9 +254,9 @@ async def handle_TestTemplate( # noqa: N802
254
254
if keyword_token is None or not keyword_token .value :
255
255
return None
256
256
257
- return await self ._handle_keywordcall_fixture_template (keyword_token , [], namespace , config )
257
+ return self ._handle_keywordcall_fixture_template (keyword_token , [], namespace , config )
258
258
259
- async def handle_Template ( # noqa: N802
259
+ def handle_Template ( # noqa: N802
260
260
self ,
261
261
document : TextDocument ,
262
262
range : Range ,
@@ -273,9 +273,9 @@ async def handle_Template( # noqa: N802
273
273
if keyword_token is None or not keyword_token .value :
274
274
return None
275
275
276
- return await self ._handle_keywordcall_fixture_template (keyword_token , [], namespace , config )
276
+ return self ._handle_keywordcall_fixture_template (keyword_token , [], namespace , config )
277
277
278
- async def handle_LibraryImport ( # noqa: N802
278
+ def handle_LibraryImport ( # noqa: N802
279
279
self ,
280
280
document : TextDocument ,
281
281
range : Range ,
@@ -306,19 +306,20 @@ async def handle_LibraryImport( # noqa: N802
306
306
variables = namespace .get_resolvable_variables (),
307
307
)
308
308
309
- except (asyncio . CancelledError , SystemExit , KeyboardInterrupt ):
309
+ except (SystemExit , KeyboardInterrupt ):
310
310
raise
311
- except BaseException :
311
+ except BaseException as e :
312
+ self ._logger .exception (e )
312
313
return None
313
314
314
315
arguments = library_node .get_tokens (RobotToken .ARGUMENT )
315
316
316
317
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 )
318
319
319
320
return None
320
321
321
- async def handle_VariablesImport ( # noqa: N802
322
+ def handle_VariablesImport ( # noqa: N802
322
323
self ,
323
324
document : TextDocument ,
324
325
range : Range ,
@@ -352,14 +353,15 @@ async def handle_VariablesImport( # noqa: N802
352
353
variables = namespace .get_resolvable_variables (),
353
354
)
354
355
355
- except (asyncio . CancelledError , SystemExit , KeyboardInterrupt ):
356
+ except (SystemExit , KeyboardInterrupt ):
356
357
raise
357
- except BaseException :
358
+ except BaseException as e :
359
+ self ._logger .exception (e )
358
360
return None
359
361
360
362
arguments = library_node .get_tokens (RobotToken .ARGUMENT )
361
363
362
364
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 )
364
366
365
367
return None
0 commit comments