88
99from robotcode .core .logging import LoggingDescriptor
1010from robotcode .language_server .common .decorators import language_id
11- from robotcode .language_server .common .lsp_types import FormattingOptions , MessageType , Position , Range , TextEdit
11+ from robotcode .language_server .common .lsp_types import (
12+ FormattingOptions ,
13+ MessageType ,
14+ Position ,
15+ Range ,
16+ TextEdit ,
17+ )
1218from robotcode .language_server .common .text_document import TextDocument
1319from robotcode .language_server .robotframework .utils .version import get_robot_version
1420
1521if TYPE_CHECKING :
16- from robotcode .language_server .robotframework .protocol import RobotLanguageServerProtocol
22+ from robotcode .language_server .robotframework .protocol import (
23+ RobotLanguageServerProtocol ,
24+ )
1725
1826from robotcode .core .utils .version import create_version_from_str
1927from robotcode .language_server .robotframework .configuration import RoboTidyConfig
@@ -57,7 +65,11 @@ async def get_config(self, document: TextDocument) -> Optional[RoboTidyConfig]:
5765 @language_id ("robotframework" )
5866 @_logger .call
5967 async def format (
60- self , sender : Any , document : TextDocument , options : FormattingOptions , ** further_options : Any
68+ self ,
69+ sender : Any ,
70+ document : TextDocument ,
71+ options : FormattingOptions ,
72+ ** further_options : Any ,
6173 ) -> Optional [List [TextEdit ]]:
6274 config = await self .get_config (document )
6375
@@ -68,15 +80,20 @@ async def format(
6880 return await self .format_internal (document , options , ** further_options )
6981
7082 self .parent .window .show_message (
71- "RobotFramework formatter is not available, please install 'robotframework-tidy'." , MessageType .ERROR
83+ "RobotFramework formatter is not available, please install 'robotframework-tidy'." ,
84+ MessageType .ERROR ,
7285 )
7386
7487 return None
7588
7689 RE_LINEBREAKS = re .compile (r"\r\n|\r|\n" )
7790
7891 async def format_robot_tidy (
79- self , document : TextDocument , options : FormattingOptions , range : Optional [Range ] = None , ** further_options : Any
92+ self ,
93+ document : TextDocument ,
94+ options : FormattingOptions ,
95+ range : Optional [Range ] = None ,
96+ ** further_options : Any ,
8097 ) -> Optional [List [TextEdit ]]:
8198 from difflib import SequenceMatcher
8299
@@ -98,7 +115,8 @@ async def format_robot_tidy(
98115 robot_tidy .config .formatting .end_line = range .end .line + 1
99116
100117 disabler_finder = RegisterDisablers (
101- robot_tidy .config .formatting .start_line , robot_tidy .config .formatting .end_line
118+ robot_tidy .config .formatting .start_line ,
119+ robot_tidy .config .formatting .end_line ,
102120 )
103121 disabler_finder .visit (model )
104122 if disabler_finder .file_disabled :
@@ -118,7 +136,8 @@ async def format_robot_tidy(
118136 from robotidy .disablers import RegisterDisablers
119137
120138 disabler_finder = RegisterDisablers (
121- robot_tidy .formatting_config .start_line , robot_tidy .formatting_config .end_line
139+ robot_tidy .formatting_config .start_line ,
140+ robot_tidy .formatting_config .end_line ,
122141 )
123142 disabler_finder .visit (model )
124143 if disabler_finder .file_disabled :
@@ -170,7 +189,7 @@ async def format_internal(
170189 self , document : TextDocument , options : FormattingOptions , ** further_options : Any
171190 ) -> Optional [List [TextEdit ]]:
172191 from robot .parsing .model .blocks import File
173- from robot .tidypkg import (
192+ from robot .tidypkg import ( # pyright: ignore [reportMissingImports]
174193 Aligner ,
175194 Cleaner ,
176195 NewlineNormalizer ,
@@ -182,7 +201,11 @@ async def format_internal(
182201 Cleaner ().visit (model )
183202 NewlineNormalizer (self .line_separator , self .short_test_name_length ).visit (model )
184203 SeparatorNormalizer (self .use_pipes , self .space_count ).visit (model )
185- Aligner (self .short_test_name_length , self .setting_and_variable_name_length , self .use_pipes ).visit (model )
204+ Aligner (
205+ self .short_test_name_length ,
206+ self .setting_and_variable_name_length ,
207+ self .use_pipes ,
208+ ).visit (model )
186209
187210 with io .StringIO () as s :
188211 model .save (s )
@@ -191,15 +214,23 @@ async def format_internal(
191214 TextEdit (
192215 range = Range (
193216 start = Position (line = 0 , character = 0 ),
194- end = Position (line = len (document .get_lines ()), character = len ((document .get_lines ())[- 1 ])),
217+ end = Position (
218+ line = len (document .get_lines ()),
219+ character = len ((document .get_lines ())[- 1 ]),
220+ ),
195221 ),
196222 new_text = s .getvalue (),
197223 )
198224 ]
199225
200226 @language_id ("robotframework" )
201227 async def format_range (
202- self , sender : Any , document : TextDocument , range : Range , options : FormattingOptions , ** further_options : Any
228+ self ,
229+ sender : Any ,
230+ document : TextDocument ,
231+ range : Range ,
232+ options : FormattingOptions ,
233+ ** further_options : Any ,
203234 ) -> Optional [List [TextEdit ]]:
204235 config = await self .get_config (document )
205236 if config and config .enabled and robotidy_installed ():
0 commit comments