@@ -423,9 +423,7 @@ async def create_keyword_settings_completion_items(self, range: Optional[Range])
423
423
]
424
424
425
425
async def create_keyword_completion_items (
426
- self ,
427
- token : Optional [Token ],
428
- position : Position ,
426
+ self , token : Optional [Token ], position : Position , add_reserverd : bool = True
429
427
) -> List [CompletionItem ]:
430
428
result : List [CompletionItem ] = []
431
429
if self .document is None :
@@ -561,15 +559,16 @@ def enumerate_indexes(s: str, c: str) -> Iterator[int]:
561
559
)
562
560
result .append (c )
563
561
564
- for k in RESERVERD_KEYWORDS :
565
- c = CompletionItem (
566
- label = k ,
567
- kind = CompletionItemKind .KEYWORD ,
568
- sort_text = f"040_{ k } " ,
569
- insert_text_format = InsertTextFormat .PLAINTEXT ,
570
- text_edit = TextEdit (range = r , new_text = k ) if r is not None else None ,
571
- )
572
- result .append (c )
562
+ if add_reserverd :
563
+ for k in RESERVERD_KEYWORDS :
564
+ c = CompletionItem (
565
+ label = k ,
566
+ kind = CompletionItemKind .KEYWORD ,
567
+ sort_text = f"999_{ k } " ,
568
+ insert_text_format = InsertTextFormat .PLAINTEXT ,
569
+ text_edit = TextEdit (range = r , new_text = k ) if r is not None else None ,
570
+ )
571
+ result .append (c )
573
572
574
573
return result
575
574
@@ -701,6 +700,14 @@ async def _complete_TestCase_or_Keyword( # noqa: N802
701
700
from robot .parsing .lexer .tokens import Token as RobotToken
702
701
from robot .parsing .model .statements import KeywordName , Statement , TestCaseName
703
702
703
+ # TODO should this be configurable?
704
+ if (
705
+ context is not None
706
+ and context .trigger_kind == CompletionTriggerKind .TRIGGERCHARACTER
707
+ and context .trigger_character in [" " , "\t " ]
708
+ ):
709
+ return None
710
+
704
711
index = 0
705
712
in_assign = False
706
713
@@ -854,6 +861,14 @@ async def _complete_SuiteSetup_or_SuiteTeardown_or_TestTemplate( # noqa: N802
854
861
) -> Union [List [CompletionItem ], CompletionList , None ]:
855
862
from robot .parsing .model .statements import Statement
856
863
864
+ # TODO should this be configurable?
865
+ if (
866
+ context is not None
867
+ and context .trigger_kind == CompletionTriggerKind .TRIGGERCHARACTER
868
+ and context .trigger_character in [" " , "\t " ]
869
+ ):
870
+ return None
871
+
857
872
statement_node = cast (Statement , node )
858
873
if len (statement_node .tokens ) > 1 :
859
874
token = cast (Token , statement_node .tokens [1 ])
@@ -867,14 +882,16 @@ async def _complete_SuiteSetup_or_SuiteTeardown_or_TestTemplate( # noqa: N802
867
882
868
883
if position .is_in_range (r ) or r .end == position :
869
884
return await self .create_keyword_completion_items (
870
- statement_node .tokens [2 ] if r .end == position and len (statement_node .tokens ) > 2 else None , position
885
+ statement_node .tokens [2 ] if r .end == position and len (statement_node .tokens ) > 2 else None ,
886
+ position ,
887
+ add_reserverd = False ,
871
888
)
872
889
873
890
if len (statement_node .tokens ) > 2 :
874
891
token = cast (Token , statement_node .tokens [2 ])
875
892
r = range_from_token (token )
876
893
if position .is_in_range (r ) or r .end == position :
877
- return await self .create_keyword_completion_items (token , position )
894
+ return await self .create_keyword_completion_items (token , position , add_reserverd = False )
878
895
879
896
return None
880
897
@@ -947,6 +964,14 @@ async def complete_Setup_or_Teardown_or_Template( # noqa: N802
947
964
) -> Union [List [CompletionItem ], CompletionList , None ]:
948
965
from robot .parsing .model .statements import Statement
949
966
967
+ # TODO should this be configurable?
968
+ if (
969
+ context is not None
970
+ and context .trigger_kind == CompletionTriggerKind .TRIGGERCHARACTER
971
+ and context .trigger_character in [" " , "\t " ]
972
+ ):
973
+ return None
974
+
950
975
statement_node = cast (Statement , node )
951
976
if len (statement_node .tokens ) > 2 :
952
977
token = cast (Token , statement_node .tokens [2 ])
@@ -960,14 +985,16 @@ async def complete_Setup_or_Teardown_or_Template( # noqa: N802
960
985
961
986
if position .is_in_range (r ) or r .end == position :
962
987
return await self .create_keyword_completion_items (
963
- statement_node .tokens [3 ] if r .end == position and len (statement_node .tokens ) > 3 else None , position
988
+ statement_node .tokens [3 ] if r .end == position and len (statement_node .tokens ) > 3 else None ,
989
+ position ,
990
+ add_reserverd = False ,
964
991
)
965
992
966
993
if len (statement_node .tokens ) > 3 :
967
994
token = cast (Token , statement_node .tokens [3 ])
968
995
r = range_from_token (token )
969
996
if position .is_in_range (r ) or r .end == position :
970
- return await self .create_keyword_completion_items (token , position )
997
+ return await self .create_keyword_completion_items (token , position , add_reserverd = False )
971
998
972
999
return None
973
1000
0 commit comments