|
11 | 11 | AsyncGenerator, |
12 | 12 | Awaitable, |
13 | 13 | Callable, |
| 14 | + Dict, |
14 | 15 | Iterator, |
15 | 16 | List, |
16 | 17 | Optional, |
|
20 | 21 | cast, |
21 | 22 | ) |
22 | 23 |
|
23 | | -from ..utils.version import get_robot_version |
24 | | - |
25 | 24 | from ....utils.async_itertools import async_chain, async_chain_iterator |
26 | 25 | from ....utils.async_tools import threaded |
27 | 26 | from ....utils.logging import LoggingDescriptor |
|
58 | 57 | whitespace_at_begin_of_token, |
59 | 58 | whitespace_from_begin_of_token, |
60 | 59 | ) |
| 60 | +from ..utils.version import get_robot_version |
61 | 61 | from .model_helper import ModelHelperMixin |
62 | 62 |
|
63 | 63 | if TYPE_CHECKING: |
@@ -164,10 +164,28 @@ async def resolve(self, sender: Any, completion_item: CompletionItem) -> Complet |
164 | 164 | TESTCASE_SETTINGS = ["Documentation", "Tags", "Setup", "Teardown", "Template", "Timeout"] |
165 | 165 | KEYWORD_SETTINGS = ["Documentation", "Tags", "Arguments", "Return", "Teardown", "Timeout"] |
166 | 166 |
|
167 | | -SNIPPETS = { |
168 | | - "FOR": [r"FOR \${${1}} ${2|IN,IN ENUMERATE,IN RANGE,IN ZIP|} ${3:arg}", "$0", "END", ""], |
169 | | - "IF": [r"IF \${${1}}", "$0", "END", ""], |
170 | | -} |
| 167 | + |
| 168 | +__snippets: Optional[Dict[str, List[str]]] = None |
| 169 | + |
| 170 | + |
| 171 | +def get_snippets() -> Dict[str, List[str]]: |
| 172 | + global __snippets |
| 173 | + if __snippets is None: |
| 174 | + __snippets = { |
| 175 | + "FOR": [r"FOR \${${1}} ${2|IN,IN ENUMERATE,IN RANGE,IN ZIP|} ${3:arg}", "$0", "END", ""], |
| 176 | + "IF": [r"IF \${${1}}", " $0", "END", ""], |
| 177 | + } |
| 178 | + |
| 179 | + if get_robot_version() >= (5, 0): |
| 180 | + __snippets.update( |
| 181 | + { |
| 182 | + "TRYEX": ["TRY", " $0", r"EXCEPT message", " ", "END", ""], |
| 183 | + "TRYEXAS": ["TRY", " $0", r"EXCEPT message AS \${ex}", " ", "END", ""], |
| 184 | + "WHILE": [r"WHILE $1:expression", " $0", "END", ""], |
| 185 | + } |
| 186 | + ) |
| 187 | + return __snippets |
| 188 | + |
171 | 189 |
|
172 | 190 | __reserved_keywords: Optional[List[str]] = None |
173 | 191 |
|
@@ -413,7 +431,7 @@ async def create_keyword_snippet_completion_items(self, range: Optional[Range]) |
413 | 431 | insert_text_format=InsertTextFormat.SNIPPET, |
414 | 432 | text_edit=TextEdit(range=range, new_text=line_end.join(snippet_value)) if range is not None else None, |
415 | 433 | ) |
416 | | - for snippet_name, snippet_value in SNIPPETS.items() |
| 434 | + for snippet_name, snippet_value in get_snippets().items() |
417 | 435 | ] |
418 | 436 |
|
419 | 437 | async def create_testcase_settings_completion_items(self, range: Optional[Range]) -> List[CompletionItem]: |
|
0 commit comments