1
- from __future__ import annotations
2
-
3
- import asyncio
4
1
import io
5
2
import os
6
3
import re
4
+ from concurrent .futures import CancelledError
7
5
from typing import TYPE_CHECKING , Any , List , Optional , cast
8
6
9
7
from robotcode .core .lsp .types import (
24
22
from .protocol_part import RobotLanguageServerProtocolPart
25
23
26
24
if TYPE_CHECKING :
27
- from robotcode .language_server .robotframework .protocol import (
28
- RobotLanguageServerProtocol ,
29
- )
25
+ from robotcode .language_server .robotframework .protocol import RobotLanguageServerProtocol
30
26
31
27
32
28
def robotidy_installed () -> bool :
@@ -40,7 +36,7 @@ def robotidy_installed() -> bool:
40
36
class RobotFormattingProtocolPart (RobotLanguageServerProtocolPart , ModelHelperMixin ):
41
37
_logger = LoggingDescriptor ()
42
38
43
- def __init__ (self , parent : RobotLanguageServerProtocol ) -> None :
39
+ def __init__ (self , parent : " RobotLanguageServerProtocol" ) -> None :
44
40
super ().__init__ (parent )
45
41
46
42
parent .formatting .format .add (self .format )
@@ -54,29 +50,29 @@ def __init__(self, parent: RobotLanguageServerProtocol) -> None:
54
50
self .short_test_name_length = 18
55
51
self .setting_and_variable_name_length = 14
56
52
57
- async def get_config (self , document : TextDocument ) -> RoboTidyConfig :
53
+ def get_config (self , document : TextDocument ) -> RoboTidyConfig :
58
54
folder = self .parent .workspace .get_workspace_folder (document .uri )
59
55
if folder is None :
60
56
return RoboTidyConfig ()
61
57
62
- return await self .parent .workspace .get_configuration_async (RoboTidyConfig , folder .uri )
58
+ return self .parent .workspace .get_configuration (RoboTidyConfig , folder .uri )
63
59
64
60
@language_id ("robotframework" )
65
61
@_logger .call
66
- async def format (
62
+ def format (
67
63
self ,
68
64
sender : Any ,
69
65
document : TextDocument ,
70
66
options : FormattingOptions ,
71
67
** further_options : Any ,
72
68
) -> Optional [List [TextEdit ]]:
73
- config = await self .get_config (document )
69
+ config = self .get_config (document )
74
70
75
71
if (config .enabled or get_robot_version () >= (5 , 0 )) and robotidy_installed ():
76
- return await self .format_robot_tidy (document , options , config = config , ** further_options )
72
+ return self .format_robot_tidy (document , options , config = config , ** further_options )
77
73
78
74
if get_robot_version () < (5 , 0 ):
79
- return await self .format_internal (document , options , ** further_options )
75
+ return self .format_internal (document , options , ** further_options )
80
76
81
77
self .parent .window .show_message (
82
78
"RobotFramework formatter is not available, please install 'robotframework-tidy'." ,
@@ -87,7 +83,7 @@ async def format(
87
83
88
84
RE_LINEBREAKS = re .compile (r"\r\n|\r|\n" )
89
85
90
- async def format_robot_tidy (
86
+ def format_robot_tidy (
91
87
self ,
92
88
document : TextDocument ,
93
89
options : FormattingOptions ,
@@ -99,7 +95,7 @@ async def format_robot_tidy(
99
95
100
96
try :
101
97
if config is None :
102
- config = await self .get_config (document )
98
+ config = self .get_config (document )
103
99
104
100
robotidy_version = create_version_from_str (__version__ )
105
101
@@ -181,14 +177,14 @@ async def format_robot_tidy(
181
177
)
182
178
]
183
179
184
- except (SystemExit , KeyboardInterrupt , asyncio . CancelledError ):
180
+ except (SystemExit , KeyboardInterrupt , CancelledError ):
185
181
raise
186
182
except BaseException as e :
187
183
self ._logger .exception (e )
188
184
self .parent .window .show_message (f"Executing `robotidy` failed: { e } " , MessageType .ERROR )
189
185
return None
190
186
191
- async def format_internal (
187
+ def format_internal (
192
188
self , document : TextDocument , options : FormattingOptions , ** further_options : Any
193
189
) -> Optional [List [TextEdit ]]:
194
190
from robot .parsing .model .blocks import File
@@ -227,16 +223,16 @@ async def format_internal(
227
223
]
228
224
229
225
@language_id ("robotframework" )
230
- async def format_range (
226
+ def format_range (
231
227
self ,
232
228
sender : Any ,
233
229
document : TextDocument ,
234
230
range : Range ,
235
231
options : FormattingOptions ,
236
232
** further_options : Any ,
237
233
) -> Optional [List [TextEdit ]]:
238
- config = await self .get_config (document )
234
+ config = self .get_config (document )
239
235
if config .enabled and robotidy_installed ():
240
- return await self .format_robot_tidy (document , options , range = range , config = config , ** further_options )
236
+ return self .format_robot_tidy (document , options , range = range , config = config , ** further_options )
241
237
242
238
return None
0 commit comments