1
- from __future__ import annotations
2
-
3
- from asyncio import CancelledError
1
+ from concurrent .futures import CancelledError
4
2
from typing import TYPE_CHECKING , Any , Final , List , Optional
5
3
6
- from robotcode .core .async_tools import async_tasking_event
7
- from robotcode .core .concurrent import threaded
4
+ from robotcode .core .concurrent import check_current_thread_canceled , threaded
5
+ from robotcode .core .event import event
8
6
from robotcode .core .lsp .types import (
9
7
ErrorCodes ,
10
8
Position ,
@@ -37,7 +35,7 @@ class CantRenameError(Exception):
37
35
class RenameProtocolPart (LanguageServerProtocolPart ):
38
36
_logger : Final = LoggingDescriptor ()
39
37
40
- def __init__ (self , parent : LanguageServerProtocol ) -> None :
38
+ def __init__ (self , parent : " LanguageServerProtocol" ) -> None :
41
39
super ().__init__ (parent )
42
40
43
41
def extend_capabilities (self , capabilities : ServerCapabilities ) -> None :
@@ -46,21 +44,19 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None:
46
44
prepare_provider = len (self .collect_prepare ) > 0 , work_done_progress = True
47
45
)
48
46
49
- @async_tasking_event
50
- async def collect (
47
+ @event
48
+ def collect (
51
49
sender , document : TextDocument , position : Position , new_name : str # NOSONAR
52
50
) -> Optional [WorkspaceEdit ]:
53
51
...
54
52
55
- @async_tasking_event
56
- async def collect_prepare (
57
- sender , document : TextDocument , position : Position # NOSONAR
58
- ) -> Optional [PrepareRenameResult ]:
53
+ @event
54
+ def collect_prepare (sender , document : TextDocument , position : Position ) -> Optional [PrepareRenameResult ]: # NOSONAR
59
55
...
60
56
61
57
@rpc_method (name = "textDocument/rename" , param_type = RenameParams )
62
58
@threaded
63
- async def _text_document_rename (
59
+ def _text_document_rename (
64
60
self ,
65
61
text_document : TextDocumentIdentifier ,
66
62
position : Position ,
@@ -74,13 +70,15 @@ async def _text_document_rename(
74
70
if document is None :
75
71
return None
76
72
77
- for result in await self .collect (
73
+ for result in self .collect (
78
74
self ,
79
75
document ,
80
76
document .position_from_utf16 (position ),
81
77
new_name ,
82
78
callback_filter = language_id_filter (document ),
83
79
):
80
+ check_current_thread_canceled ()
81
+
84
82
if isinstance (result , BaseException ):
85
83
if not isinstance (result , CancelledError ):
86
84
self ._logger .exception (result , exc_info = result )
@@ -92,6 +90,8 @@ async def _text_document_rename(
92
90
return None
93
91
94
92
for we in edits :
93
+ check_current_thread_canceled ()
94
+
95
95
if we .changes :
96
96
for uri , changes in we .changes .items ():
97
97
if changes :
@@ -108,6 +108,8 @@ async def _text_document_rename(
108
108
109
109
result = WorkspaceEdit ()
110
110
for we in edits :
111
+ check_current_thread_canceled ()
112
+
111
113
if we .changes :
112
114
if result .changes is None :
113
115
result .changes = {}
@@ -127,7 +129,7 @@ async def _text_document_rename(
127
129
128
130
@rpc_method (name = "textDocument/prepareRename" , param_type = PrepareRenameParams )
129
131
@threaded
130
- async def _text_document_prepare_rename (
132
+ def _text_document_prepare_rename (
131
133
self ,
132
134
text_document : TextDocumentIdentifier ,
133
135
position : Position ,
@@ -140,9 +142,11 @@ async def _text_document_prepare_rename(
140
142
if document is None :
141
143
return None
142
144
143
- for result in await self .collect_prepare (
145
+ for result in self .collect_prepare (
144
146
self , document , document .position_from_utf16 (position ), callback_filter = language_id_filter (document )
145
147
):
148
+ check_current_thread_canceled ()
149
+
146
150
if isinstance (result , BaseException ):
147
151
if isinstance (result , CantRenameError ):
148
152
raise JsonRPCErrorException (ErrorCodes .INVALID_PARAMS , str (result ))
0 commit comments