@@ -1139,71 +1139,64 @@ async def complete_arguments() -> Optional[List[CompletionItem]]:
1139
1139
if token_at_position .type not in [RobotToken .ARGUMENT , RobotToken .EOL , RobotToken .SEPARATOR ]:
1140
1140
return None
1141
1141
1142
+ if (
1143
+ token_at_position .type == RobotToken .EOL
1144
+ and len (tokens_at_position ) > 1
1145
+ and tokens_at_position [- 2 ].type == RobotToken .KEYWORD
1146
+ ):
1147
+ return None
1148
+
1142
1149
token_at_position_index = kw_node .tokens .index (token_at_position )
1143
1150
1144
1151
argument_token_index = token_at_position_index
1145
1152
while argument_token_index >= 0 and kw_node .tokens [argument_token_index ].type != RobotToken .ARGUMENT :
1146
1153
argument_token_index -= 1
1147
1154
1148
- arguments = kw_node .get_tokens (RobotToken .ARGUMENT )
1149
-
1155
+ argument_token : Optional [RobotToken ] = None
1150
1156
if argument_token_index >= 0 :
1151
1157
argument_token = kw_node .tokens [argument_token_index ]
1152
- if argument_token .type == RobotToken .ARGUMENT :
1153
- argument_index = arguments .index (argument_token )
1154
- else :
1155
- argument_index = 0
1156
- else :
1157
- argument_index = - 1
1158
-
1159
- if whitespace_at_begin_of_token (token_at_position ) > 1 :
1160
- completion_range = range_from_token (token_at_position )
1161
1158
1162
- ws_b = whitespace_from_begin_of_token (token_at_position )
1163
- completion_range .start .character += 2 if ws_b and ws_b [0 ] != "\t " else 1
1164
-
1165
- if position .is_in_range (completion_range ) or completion_range .end == position :
1166
- argument_index += 1
1167
-
1168
- if argument_index < 0 :
1169
- return None
1170
-
1171
- completion_range = range_from_token (token_at_position )
1159
+ completion_range = range_from_token (argument_token or token_at_position )
1160
+ completion_range .end = range_from_token (token_at_position ).end
1172
1161
if (w := whitespace_at_begin_of_token (token_at_position )) > 0 :
1173
- if w > 1 and completion_range .start .character + 1 < position .character :
1162
+ if w > 1 and range_from_token ( token_at_position ) .start .character + 1 < position .character :
1174
1163
completion_range .start = position
1175
- elif completion_range .start == position :
1176
- pass
1177
- else :
1164
+ elif completion_range .start != position :
1178
1165
return None
1179
1166
else :
1180
- if token_at_position .type != RobotToken .ARGUMENT :
1181
- return None
1182
-
1183
- if "=" in token_at_position .value :
1184
- equal_index = token_at_position .value .index ("=" )
1167
+ if "=" in (argument_token or token_at_position ).value :
1168
+ equal_index = (argument_token or token_at_position ).value .index ("=" )
1185
1169
if completion_range .start .character + equal_index < position .character :
1186
1170
return None
1187
1171
else :
1188
1172
completion_range .end .character = completion_range .start .character + equal_index + 1
1173
+ else :
1174
+ completion_range .end = position
1189
1175
1190
- libdocs = [
1191
- entry .library_doc
1192
- for entry in (await self .namespace .get_libraries ()).values ()
1193
- if entry .import_name == import_node .name
1194
- and entry .args == import_node .args
1195
- and entry .alias == import_node .alias
1196
- ]
1176
+ imports_manger = await self .parent .documents_cache .get_imports_manager (self .document )
1177
+
1178
+ try :
1179
+ libdoc = await imports_manger .get_libdoc_for_library_import (
1180
+ import_node .name , (), str (self .document .uri .to_path ().parent )
1181
+ )
1182
+ if not list :
1183
+ return None
1184
+ except (SystemExit , KeyboardInterrupt , asyncio .CancelledError ):
1185
+ raise
1186
+ except BaseException as e :
1187
+ self ._logger .exception (e )
1188
+ return None
1197
1189
1198
- if len ( libdocs ) == 1 :
1199
- init = next ((v for v in libdocs [ 0 ] .inits .values ()), None )
1190
+ if libdoc is not None :
1191
+ init = next ((v for v in libdoc .inits .values ()), None )
1200
1192
1201
1193
if init :
1202
1194
return [
1203
1195
CompletionItem (
1204
1196
label = f"{ e .name } =" ,
1205
1197
kind = CompletionItemKind .VARIABLE ,
1206
- sort_text = f"010{ i } _{ e .name } =" ,
1198
+ sort_text = f"010{ i } _{ e .name } " ,
1199
+ filter_text = e .name ,
1207
1200
insert_text_format = InsertTextFormat .PLAINTEXT ,
1208
1201
text_edit = TextEdit (range = completion_range , new_text = f"{ e .name } =" ),
1209
1202
data = {
@@ -1237,7 +1230,7 @@ async def complete_with_name() -> Optional[List[CompletionItem]]:
1237
1230
return [
1238
1231
CompletionItem (
1239
1232
label = "WITH NAME" ,
1240
- kind = CompletionItemKind .TEXT ,
1233
+ kind = CompletionItemKind .KEYWORD ,
1241
1234
# detail=e.detail,
1242
1235
sort_text = "03_WITH NAME" ,
1243
1236
insert_text_format = InsertTextFormat .PLAINTEXT ,
@@ -1258,6 +1251,7 @@ async def complete_ResourceImport( # noqa: N802
1258
1251
position : Position ,
1259
1252
context : Optional [CompletionContext ],
1260
1253
) -> Union [List [CompletionItem ], CompletionList , None ]:
1254
+
1261
1255
from robot .parsing .lexer .tokens import Token
1262
1256
from robot .parsing .model .statements import ResourceImport
1263
1257
@@ -1285,6 +1279,8 @@ async def complete_ResourceImport( # noqa: N802
1285
1279
1286
1280
if not position .is_in_range (r ) and r .end != position :
1287
1281
return None
1282
+ else :
1283
+ return None
1288
1284
else :
1289
1285
return None
1290
1286
@@ -1368,6 +1364,10 @@ async def _complete_KeywordCall_or_Fixture( # noqa: N802
1368
1364
1369
1365
kw_node = cast (Statement , node )
1370
1366
1367
+ keyword_token = kw_node .get_token (keyword_name_token_type )
1368
+ if keyword_token is None :
1369
+ return None
1370
+
1371
1371
tokens_at_position = get_tokens_at_position (kw_node , position )
1372
1372
1373
1373
if not tokens_at_position :
@@ -1378,59 +1378,41 @@ async def _complete_KeywordCall_or_Fixture( # noqa: N802
1378
1378
if token_at_position .type not in [RobotToken .ARGUMENT , RobotToken .EOL , RobotToken .SEPARATOR ]:
1379
1379
return None
1380
1380
1381
+ if (
1382
+ token_at_position .type == RobotToken .EOL
1383
+ and len (tokens_at_position ) > 1
1384
+ and tokens_at_position [- 2 ].type == RobotToken .KEYWORD
1385
+ ):
1386
+ return None
1387
+
1381
1388
token_at_position_index = kw_node .tokens .index (token_at_position )
1382
1389
1383
1390
argument_token_index = token_at_position_index
1384
1391
while argument_token_index >= 0 and kw_node .tokens [argument_token_index ].type != RobotToken .ARGUMENT :
1385
1392
argument_token_index -= 1
1386
1393
1387
- arguments = kw_node .get_tokens (RobotToken .ARGUMENT )
1388
-
1394
+ argument_token : Optional [RobotToken ] = None
1389
1395
if argument_token_index >= 0 :
1390
1396
argument_token = kw_node .tokens [argument_token_index ]
1391
- if argument_token .type == RobotToken .ARGUMENT :
1392
- argument_index = arguments .index (argument_token )
1393
- else :
1394
- argument_index = 0
1395
- else :
1396
- argument_index = - 1
1397
-
1398
- if whitespace_at_begin_of_token (token_at_position ) > 1 :
1399
- completion_range = range_from_token (token_at_position )
1400
-
1401
- ws_b = whitespace_from_begin_of_token (token_at_position )
1402
- completion_range .start .character += 2 if ws_b and ws_b [0 ] != "\t " else 1
1403
-
1404
- if position .is_in_range (completion_range ) or completion_range .end == position :
1405
- argument_index += 1
1406
-
1407
- if argument_index < 0 :
1408
- return None
1409
1397
1410
1398
result : Optional [Tuple [Optional [KeywordDoc ], Token ]]
1411
1399
1412
- keyword_token = kw_node .get_token (keyword_name_token_type )
1413
- if keyword_token is None :
1414
- return None
1415
-
1416
- completion_range = range_from_token (token_at_position )
1400
+ completion_range = range_from_token (argument_token or token_at_position )
1401
+ completion_range .end = range_from_token (token_at_position ).end
1417
1402
if (w := whitespace_at_begin_of_token (token_at_position )) > 0 :
1418
- if w > 1 and completion_range .start .character + 1 < position .character :
1403
+ if w > 1 and range_from_token ( token_at_position ) .start .character + 1 < position .character :
1419
1404
completion_range .start = position
1420
- elif completion_range .start == position :
1421
- pass
1422
- else :
1405
+ elif completion_range .start != position :
1423
1406
return None
1424
1407
else :
1425
- if token_at_position .type != RobotToken .ARGUMENT :
1426
- return None
1427
-
1428
- if "=" in token_at_position .value :
1429
- equal_index = token_at_position .value .index ("=" )
1408
+ if "=" in (argument_token or token_at_position ).value :
1409
+ equal_index = (argument_token or token_at_position ).value .index ("=" )
1430
1410
if completion_range .start .character + equal_index < position .character :
1431
1411
return None
1432
1412
else :
1433
1413
completion_range .end .character = completion_range .start .character + equal_index + 1
1414
+ else :
1415
+ completion_range .end = position
1434
1416
1435
1417
result = await self .get_keyworddoc_and_token_from_position (
1436
1418
keyword_token .value ,
@@ -1460,15 +1442,11 @@ async def _complete_KeywordCall_or_Fixture( # noqa: N802
1460
1442
CompletionItem (
1461
1443
label = f"{ e .name } =" ,
1462
1444
kind = CompletionItemKind .VARIABLE ,
1463
- # detail=e.detail,
1445
+ detail = "Argument" ,
1446
+ filter_text = e .name ,
1464
1447
sort_text = f"02{ i } _{ e .name } =" ,
1465
1448
insert_text_format = InsertTextFormat .PLAINTEXT ,
1466
1449
text_edit = TextEdit (range = completion_range , new_text = f"{ e .name } =" ),
1467
- data = {
1468
- "document_uri" : str (self .document .uri ),
1469
- "type" : "Argument" ,
1470
- "name" : e ,
1471
- },
1472
1450
)
1473
1451
for i , e in enumerate (result [0 ].args )
1474
1452
if e .kind
0 commit comments