Skip to content

Commit f649cdc

Browse files
committed
add some RF 5.0 Snippets to completion
1 parent 2809f9b commit f649cdc

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

robotcode/language_server/robotframework/parts/completion.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
AsyncGenerator,
1212
Awaitable,
1313
Callable,
14+
Dict,
1415
Iterator,
1516
List,
1617
Optional,
@@ -20,8 +21,6 @@
2021
cast,
2122
)
2223

23-
from ..utils.version import get_robot_version
24-
2524
from ....utils.async_itertools import async_chain, async_chain_iterator
2625
from ....utils.async_tools import threaded
2726
from ....utils.logging import LoggingDescriptor
@@ -58,6 +57,7 @@
5857
whitespace_at_begin_of_token,
5958
whitespace_from_begin_of_token,
6059
)
60+
from ..utils.version import get_robot_version
6161
from .model_helper import ModelHelperMixin
6262

6363
if TYPE_CHECKING:
@@ -164,10 +164,28 @@ async def resolve(self, sender: Any, completion_item: CompletionItem) -> Complet
164164
TESTCASE_SETTINGS = ["Documentation", "Tags", "Setup", "Teardown", "Template", "Timeout"]
165165
KEYWORD_SETTINGS = ["Documentation", "Tags", "Arguments", "Return", "Teardown", "Timeout"]
166166

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+
171189

172190
__reserved_keywords: Optional[List[str]] = None
173191

@@ -413,7 +431,7 @@ async def create_keyword_snippet_completion_items(self, range: Optional[Range])
413431
insert_text_format=InsertTextFormat.SNIPPET,
414432
text_edit=TextEdit(range=range, new_text=line_end.join(snippet_value)) if range is not None else None,
415433
)
416-
for snippet_name, snippet_value in SNIPPETS.items()
434+
for snippet_name, snippet_value in get_snippets().items()
417435
]
418436

419437
async def create_testcase_settings_completion_items(self, range: Optional[Range]) -> List[CompletionItem]:

0 commit comments

Comments
 (0)