@@ -868,9 +868,9 @@ async def complete_LibraryImport( # noqa: N802
868
868
return []
869
869
import_token_index = import_node .tokens .index (import_token )
870
870
871
- async def complete_import () -> Union [List [CompletionItem ], CompletionList , None ]:
871
+ async def complete_import () -> Optional [List [CompletionItem ]]:
872
872
if self .document is None :
873
- return []
873
+ return None
874
874
875
875
if len (import_node .tokens ) > import_token_index + 2 :
876
876
name_token = import_node .tokens [import_token_index + 2 ]
@@ -887,6 +887,9 @@ async def complete_import() -> Union[List[CompletionItem], CompletionList, None]
887
887
888
888
if not position .is_in_range (r ) and r .end != position :
889
889
return None
890
+ else :
891
+ return None
892
+
890
893
else :
891
894
return None
892
895
@@ -954,9 +957,19 @@ async def complete_import() -> Union[List[CompletionItem], CompletionList, None]
954
957
for e in list
955
958
]
956
959
957
- async def complete_arguments () -> Union [List [CompletionItem ], CompletionList , None ]:
960
+ async def complete_arguments () -> Optional [List [CompletionItem ]]:
958
961
if self .document is None :
959
- return []
962
+ return None
963
+
964
+ if (
965
+ import_node .name is None
966
+ or position <= range_from_token (import_node .get_token (RobotToken .NAME )).extend (end_character = 1 ).end
967
+ ):
968
+ return None
969
+
970
+ with_name_token = next ((v for v in import_node .tokens if v .value == "WITH NAME" ), None )
971
+ if with_name_token is not None and position >= range_from_token (with_name_token ).start :
972
+ return None
960
973
961
974
if context is None or context .trigger_kind != CompletionTriggerKind .INVOKED :
962
975
return []
@@ -1063,9 +1076,31 @@ async def complete_arguments() -> Union[List[CompletionItem], CompletionList, No
1063
1076
1064
1077
return None
1065
1078
1066
- result = await complete_import ()
1067
- if not result :
1068
- result = await complete_arguments ()
1079
+ async def complete_with_name () -> Optional [List [CompletionItem ]]:
1080
+ if self .document is None :
1081
+ return None
1082
+
1083
+ if context is None or context .trigger_kind != CompletionTriggerKind .INVOKED :
1084
+ return []
1085
+
1086
+ if import_node .name and not any (v for v in import_node .tokens if v .value == "WITH NAME" ):
1087
+ name_token = import_node .get_token (RobotToken .NAME )
1088
+ if position >= range_from_token (name_token ).extend (end_character = 2 ).end :
1089
+ return [
1090
+ CompletionItem (
1091
+ label = "WITH NAME" ,
1092
+ kind = CompletionItemKind .TEXT ,
1093
+ # detail=e.detail,
1094
+ sort_text = "03_WITH NAME" ,
1095
+ insert_text_format = InsertTextFormat .PLAINTEXT ,
1096
+ )
1097
+ ]
1098
+ return []
1099
+
1100
+ result = await complete_import () or []
1101
+ result .extend (await complete_arguments () or [])
1102
+ result .extend (await complete_with_name () or [])
1103
+
1069
1104
return result
1070
1105
1071
1106
async def complete_ResourceImport ( # noqa: N802
0 commit comments