17
17
18
18
from ..configuration import RoboCopConfig , RoboTidyConfig
19
19
from .protocol_part import RobotLanguageServerProtocolPart
20
- from .robocop_tidy_mixin import RoboCopTidyMixin
21
20
22
21
if TYPE_CHECKING :
23
22
from ..protocol import RobotLanguageServerProtocol
24
23
25
24
26
- class RobotFormattingProtocolPart (RobotLanguageServerProtocolPart , RoboCopTidyMixin ):
25
+ class RobotFormattingProtocolPart (RobotLanguageServerProtocolPart ):
27
26
_logger = LoggingDescriptor ()
28
27
29
28
def __init__ (self , parent : "RobotLanguageServerProtocol" ) -> None :
30
29
super ().__init__ (parent )
31
30
32
31
parent .formatting .format .add (self .format )
33
32
34
- if self .robotidy_installed or (self .robocop_installed and self .robocop_version >= (6 , 0 )):
33
+ if self .parent .robocop_helper .robotidy_installed or (
34
+ self .parent .robocop_helper .robocop_installed and self .parent .robocop_helper .robocop_version >= (6 , 0 )
35
+ ):
35
36
parent .formatting .format_range .add (self .format_range )
36
37
37
38
self .space_count = 4
@@ -64,8 +65,8 @@ def format(
64
65
options : FormattingOptions ,
65
66
** further_options : Any ,
66
67
) -> Optional [List [TextEdit ]]:
67
- if self .robocop_installed and self .robocop_version >= (6 , 0 ):
68
- if not self .is_robocop_notification_shown and self .robotidy_installed :
68
+ if self .parent . robocop_helper . robocop_installed and self . parent . robocop_helper .robocop_version >= (6 , 0 ):
69
+ if not self .is_robocop_notification_shown and self .parent . robocop_helper . robotidy_installed :
69
70
self .parent .window .show_message (
70
71
"`robotframework-robocop >= 6.0` is installed and will be used for formatting.\n \n "
71
72
"`robotframework-tidy` is also detected in the workspace, but its use is redundant.\n "
@@ -78,7 +79,7 @@ def format(
78
79
return self .format_robocop (document , options , ** further_options )
79
80
80
81
tidy_config = self .get_tidy_config (document )
81
- if (tidy_config .enabled or get_robot_version () >= (5 , 0 )) and self .robotidy_installed :
82
+ if (tidy_config .enabled or get_robot_version () >= (5 , 0 )) and self .parent . robocop_helper . robotidy_installed :
82
83
return self .format_robot_tidy (document , options , config = tidy_config , ** further_options )
83
84
84
85
if get_robot_version () < (5 , 0 ):
@@ -105,18 +106,18 @@ def format_robot_tidy(
105
106
106
107
model = self .parent .documents_cache .get_model (document , False )
107
108
108
- if self .robotidy_version >= (3 , 0 ):
109
+ if self .parent . robocop_helper . robotidy_version >= (3 , 0 ):
109
110
from robotidy .api import get_robotidy
110
111
from robotidy .disablers import RegisterDisablers
111
112
112
- if self .robotidy_version >= (4 , 2 ):
113
+ if self .parent . robocop_helper . robotidy_version >= (4 , 2 ):
113
114
robot_tidy = get_robotidy (
114
115
document .uri .to_path (),
115
116
None ,
116
117
ignore_git_dir = config .ignore_git_dir ,
117
118
config = config .config ,
118
119
)
119
- elif self .robotidy_version >= (4 , 1 ):
120
+ elif self .parent . robocop_helper . robotidy_version >= (4 , 1 ):
120
121
robot_tidy = get_robotidy (
121
122
document .uri .to_path (),
122
123
None ,
@@ -135,14 +136,14 @@ def format_robot_tidy(
135
136
)
136
137
disabler_finder .visit (model )
137
138
138
- if self .robotidy_version >= (4 , 11 ):
139
+ if self .parent . robocop_helper . robotidy_version >= (4 , 11 ):
139
140
if disabler_finder .is_disabled_in_file ():
140
141
return None
141
142
else :
142
143
if disabler_finder .file_disabled :
143
144
return None
144
145
145
- if self .robotidy_version >= (4 , 0 ):
146
+ if self .parent . robocop_helper . robotidy_version >= (4 , 0 ):
146
147
_ , _ , new , _ = robot_tidy .transform_until_stable (model , disabler_finder )
147
148
else :
148
149
_ , _ , new = robot_tidy .transform (model , disabler_finder .disablers )
@@ -156,7 +157,7 @@ def format_robot_tidy(
156
157
robot_tidy .formatting_config .start_line = range .start .line + 1
157
158
robot_tidy .formatting_config .end_line = range .end .line + 1
158
159
159
- if self .robotidy_version >= (2 , 2 ):
160
+ if self .parent . robocop_helper . robotidy_version >= (2 , 2 ):
160
161
from robotidy .disablers import RegisterDisablers
161
162
162
163
disabler_finder = RegisterDisablers (
@@ -197,19 +198,13 @@ def format_robocop(
197
198
range : Optional [Range ] = None ,
198
199
** further_options : Any ,
199
200
) -> Optional [List [TextEdit ]]:
200
- from robocop .config import ConfigManager
201
201
from robocop .formatter .runner import RobocopFormatter
202
202
203
- robocop_config = self .get_robocop_config (document )
204
203
workspace_folder = self .parent .workspace .get_workspace_folder (document .uri )
204
+ if workspace_folder is None :
205
+ return None
205
206
206
- config_manager = ConfigManager (
207
- [document .uri .to_path ()],
208
- root = workspace_folder .uri .to_path () if workspace_folder else None ,
209
- config = robocop_config .config_file ,
210
- ignore_git_dir = robocop_config .ignore_git_dir ,
211
- ignore_file_config = robocop_config .ignore_file_config ,
212
- )
207
+ config_manager = self .parent .robocop_helper .get_config_manager (workspace_folder )
213
208
214
209
config = config_manager .get_config_for_source_file (document .uri .to_path ())
215
210
@@ -284,7 +279,9 @@ def format_range(
284
279
** further_options : Any ,
285
280
) -> Optional [List [TextEdit ]]:
286
281
config = self .get_tidy_config (document )
287
- if (config .enabled and self .robotidy_installed ) or (self .robocop_installed and self .robocop_version >= (6 , 0 )):
282
+ if (config .enabled and self .parent .robocop_helper .robotidy_installed ) or (
283
+ self .parent .robocop_helper .robocop_installed and self .parent .robocop_helper .robocop_version >= (6 , 0 )
284
+ ):
288
285
return self .format_robot_tidy (document , options , range = range , config = config , ** further_options )
289
286
290
287
return None
0 commit comments