Skip to content

Commit 01221aa

Browse files
committed
update formatting part to not use internal formatter if RF version >= 5 detected
1 parent 12049bf commit 01221aa

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

robotcode/language_server/robotframework/parts/formatting.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
import os
66
from typing import TYPE_CHECKING, Any, List, Optional, cast
77

8+
from ....utils.async_tools import threaded
89
from ....utils.logging import LoggingDescriptor
910
from ...common.decorators import language_id
10-
from ...common.lsp_types import FormattingOptions, Position, Range, TextEdit
11+
from ...common.lsp_types import (
12+
FormattingOptions,
13+
MessageType,
14+
Position,
15+
Range,
16+
TextEdit,
17+
)
1118
from ...common.text_document import TextDocument
19+
from ..utils.version import get_robot_version
1220

1321
if TYPE_CHECKING:
1422
from ..protocol import RobotLanguageServerProtocol
@@ -33,6 +41,7 @@ def __init__(self, parent: RobotLanguageServerProtocol) -> None:
3341
super().__init__(parent)
3442

3543
parent.formatting.format.add(self.format)
44+
3645
# TODO implement range formatting
3746
# parent.formatting.format_range.add(self.format_range)
3847

@@ -50,14 +59,24 @@ async def get_config(self, document: TextDocument) -> Optional[RoboTidyConfig]:
5059
return await self.parent.workspace.get_configuration(RoboTidyConfig, folder.uri)
5160

5261
@language_id("robotframework")
53-
@_logger.call(entering=True, exiting=True, exception=True)
62+
@threaded()
63+
@_logger.call
5464
async def format(
5565
self, sender: Any, document: TextDocument, options: FormattingOptions, **further_options: Any
5666
) -> Optional[List[TextEdit]]:
5767
config = await self.get_config(document)
58-
if config and config.enabled and robotidy_installed():
68+
69+
if config and (config.enabled or get_robot_version() >= (5, 0)) and robotidy_installed():
5970
return await self.format_robot_tidy(document, options, **further_options)
60-
return await self.format_internal(document, options, **further_options)
71+
72+
if get_robot_version() < (5, 0):
73+
return await self.format_internal(document, options, **further_options)
74+
75+
self.parent.window.show_message(
76+
"RobotFramework formatter is not available, please install 'robotframework-tidy'.", MessageType.ERROR
77+
)
78+
79+
return None
6180

6281
async def format_robot_tidy(
6382
self, document: TextDocument, options: FormattingOptions, **further_options: Any

0 commit comments

Comments
 (0)