1- from __future__ import annotations
2-
3- from asyncio import CancelledError
1+ from concurrent .futures import CancelledError
42from typing import TYPE_CHECKING , Any , Final , List , Optional
53
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
86from robotcode .core .lsp .types import (
97 ErrorCodes ,
108 Position ,
@@ -37,7 +35,7 @@ class CantRenameError(Exception):
3735class RenameProtocolPart (LanguageServerProtocolPart ):
3836 _logger : Final = LoggingDescriptor ()
3937
40- def __init__ (self , parent : LanguageServerProtocol ) -> None :
38+ def __init__ (self , parent : " LanguageServerProtocol" ) -> None :
4139 super ().__init__ (parent )
4240
4341 def extend_capabilities (self , capabilities : ServerCapabilities ) -> None :
@@ -46,21 +44,19 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None:
4644 prepare_provider = len (self .collect_prepare ) > 0 , work_done_progress = True
4745 )
4846
49- @async_tasking_event
50- async def collect (
47+ @event
48+ def collect (
5149 sender , document : TextDocument , position : Position , new_name : str # NOSONAR
5250 ) -> Optional [WorkspaceEdit ]:
5351 ...
5452
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
5955 ...
6056
6157 @rpc_method (name = "textDocument/rename" , param_type = RenameParams )
6258 @threaded
63- async def _text_document_rename (
59+ def _text_document_rename (
6460 self ,
6561 text_document : TextDocumentIdentifier ,
6662 position : Position ,
@@ -74,13 +70,15 @@ async def _text_document_rename(
7470 if document is None :
7571 return None
7672
77- for result in await self .collect (
73+ for result in self .collect (
7874 self ,
7975 document ,
8076 document .position_from_utf16 (position ),
8177 new_name ,
8278 callback_filter = language_id_filter (document ),
8379 ):
80+ check_current_thread_canceled ()
81+
8482 if isinstance (result , BaseException ):
8583 if not isinstance (result , CancelledError ):
8684 self ._logger .exception (result , exc_info = result )
@@ -92,6 +90,8 @@ async def _text_document_rename(
9290 return None
9391
9492 for we in edits :
93+ check_current_thread_canceled ()
94+
9595 if we .changes :
9696 for uri , changes in we .changes .items ():
9797 if changes :
@@ -108,6 +108,8 @@ async def _text_document_rename(
108108
109109 result = WorkspaceEdit ()
110110 for we in edits :
111+ check_current_thread_canceled ()
112+
111113 if we .changes :
112114 if result .changes is None :
113115 result .changes = {}
@@ -127,7 +129,7 @@ async def _text_document_rename(
127129
128130 @rpc_method (name = "textDocument/prepareRename" , param_type = PrepareRenameParams )
129131 @threaded
130- async def _text_document_prepare_rename (
132+ def _text_document_prepare_rename (
131133 self ,
132134 text_document : TextDocumentIdentifier ,
133135 position : Position ,
@@ -140,9 +142,11 @@ async def _text_document_prepare_rename(
140142 if document is None :
141143 return None
142144
143- for result in await self .collect_prepare (
145+ for result in self .collect_prepare (
144146 self , document , document .position_from_utf16 (position ), callback_filter = language_id_filter (document )
145147 ):
148+ check_current_thread_canceled ()
149+
146150 if isinstance (result , BaseException ):
147151 if isinstance (result , CantRenameError ):
148152 raise JsonRPCErrorException (ErrorCodes .INVALID_PARAMS , str (result ))
0 commit comments