@@ -88,32 +88,54 @@ async def format_robot_tidy(
88
88
89
89
from difflib import SequenceMatcher
90
90
91
- from robotidy .api import RobotidyAPI
92
91
from robotidy .version import __version__
93
92
94
93
try :
94
+ robotidy_version = create_version_from_str (__version__ )
95
+
95
96
model = await self .parent .documents_cache .get_model (document , False )
96
97
if model is None :
97
98
return None
98
99
99
- robot_tidy = RobotidyAPI (document .uri .to_path (), None )
100
+ if robotidy_version >= (3 , 0 ):
101
+ from robotidy .api import get_robotidy
102
+ from robotidy .disablers import RegisterDisablers
100
103
101
- if range is not None :
102
- robot_tidy .formatting_config .start_line = range .start .line
103
- robot_tidy .formatting_config .end_line = range .end .line + 1
104
+ robot_tidy = get_robotidy (document .uri .to_path (), None )
104
105
105
- if create_version_from_str (__version__ ) >= (2 , 2 ):
106
- from robotidy .disablers import RegisterDisablers
106
+ if range is not None :
107
+ robot_tidy .config .formatting .start_line = range .start .line
108
+ robot_tidy .config .formatting .end_line = range .end .line + 1
107
109
108
110
disabler_finder = RegisterDisablers (
109
- robot_tidy .formatting_config . start_line , robot_tidy .formatting_config .end_line
111
+ robot_tidy .config . formatting . start_line , robot_tidy .config . formatting .end_line
110
112
)
111
113
disabler_finder .visit (model )
112
114
if disabler_finder .file_disabled :
113
115
return None
114
116
changed , _ , new = robot_tidy .transform (model , disabler_finder .disablers )
117
+
115
118
else :
116
- changed , _ , new = robot_tidy .transform (model )
119
+ from robotidy .api import RobotidyAPI
120
+
121
+ robot_tidy = RobotidyAPI (document .uri .to_path (), None )
122
+
123
+ if range is not None :
124
+ robot_tidy .formatting_config .start_line = range .start .line
125
+ robot_tidy .formatting_config .end_line = range .end .line + 1
126
+
127
+ if robotidy_version >= (2 , 2 ):
128
+ from robotidy .disablers import RegisterDisablers
129
+
130
+ disabler_finder = RegisterDisablers (
131
+ robot_tidy .formatting_config .start_line , robot_tidy .formatting_config .end_line
132
+ )
133
+ disabler_finder .visit (model )
134
+ if disabler_finder .file_disabled :
135
+ return None
136
+ changed , _ , new = robot_tidy .transform (model , disabler_finder .disablers )
137
+ else :
138
+ changed , _ , new = robot_tidy .transform (model )
117
139
118
140
if not changed :
119
141
return None
0 commit comments