@@ -127,7 +127,7 @@ class RobotCompletionProtocolPart(RobotLanguageServerProtocolPart):
127
127
128
128
def __init__ (self , parent : "RobotLanguageServerProtocol" ) -> None :
129
129
super ().__init__ (parent )
130
-
130
+ self . doc_cache : Dict [ str , str ] = {}
131
131
parent .completion .collect .add (self .collect )
132
132
parent .completion .resolve .add (self .resolve )
133
133
@@ -171,9 +171,9 @@ def collect(
171
171
model = self .parent .documents_cache .get_model (document , False )
172
172
173
173
config = self .get_config (document )
174
-
174
+ self . doc_cache = {}
175
175
return CompletionCollector (
176
- self . parent ,
176
+ self ,
177
177
document ,
178
178
model ,
179
179
namespace ,
@@ -195,7 +195,7 @@ def resolve(self, sender: Any, completion_item: CompletionItem) -> CompletionIte
195
195
config = self .get_config (document )
196
196
197
197
return CompletionCollector (
198
- self . parent ,
198
+ self ,
199
199
document ,
200
200
model ,
201
201
namespace ,
@@ -331,7 +331,7 @@ class CompletionCollector(ModelHelper):
331
331
332
332
def __init__ (
333
333
self ,
334
- parent : "RobotLanguageServerProtocol " ,
334
+ parent : "RobotCompletionProtocolPart " ,
335
335
document : TextDocument ,
336
336
model : ast .AST ,
337
337
namespace : Namespace ,
@@ -407,7 +407,7 @@ def resolve(self, completion_item: CompletionItem) -> CompletionItem:
407
407
if data is not None :
408
408
document_uri = data .get ("document_uri" , None )
409
409
if document_uri is not None :
410
- document = self .parent .documents .get (document_uri )
410
+ document = self .parent .parent . documents .get (document_uri )
411
411
if document is not None and (comp_type := data .get ("type" , None )) is not None :
412
412
if comp_type in [
413
413
CompleteResultKind .MODULE .name ,
@@ -532,11 +532,15 @@ def resolve(self, completion_item: CompletionItem) -> CompletionItem:
532
532
raise
533
533
except BaseException :
534
534
pass
535
+ elif comp_type == CompleteResultKind .DOC_CACHE .name :
536
+ if (name := data .get ("name" , None )) is not None :
537
+ if (doc := self .parent .doc_cache .get (name , None )) is not None :
538
+ completion_item .documentation = MarkupContent (kind = MarkupKind .MARKDOWN , value = doc )
535
539
536
540
return completion_item
537
541
538
542
def create_headers_completion_items (self , range : Optional [Range ]) -> List [CompletionItem ]:
539
- doc_type = self .parent .documents_cache .get_document_type (self .document )
543
+ doc_type = self .parent .parent . documents_cache .get_document_type (self .document )
540
544
541
545
if self .namespace .languages is None :
542
546
if doc_type in [DocumentType .RESOURCE , DocumentType .INIT ]:
@@ -624,7 +628,7 @@ def create_variables_completion_items(
624
628
]
625
629
626
630
def create_settings_completion_items (self , range : Optional [Range ]) -> List [CompletionItem ]:
627
- doc_type = self .parent .documents_cache .get_document_type (self .document )
631
+ doc_type = self .parent .parent . documents_cache .get_document_type (self .document )
628
632
629
633
settings_class : Type [Settings ] = SuiteFileSettings
630
634
if doc_type == DocumentType .RESOURCE :
@@ -2283,21 +2287,24 @@ def _complete_keyword_arguments_at_position(
2283
2287
2284
2288
for i , b_snippet in enumerate (bool_snippets ):
2285
2289
if b_snippet [0 ]:
2290
+ cache_name = f"BOOL{ id (type_info )} _{ i } "
2291
+ self .parent .doc_cache [cache_name ] = type_info .to_markdown ()
2286
2292
result .append (
2287
2293
CompletionItem (
2288
2294
label = b_snippet [0 ],
2289
2295
kind = CompletionItemKind .CONSTANT ,
2290
2296
detail = f"{ type_info .name } ({ b_snippet [1 ]} )" ,
2291
- documentation = MarkupContent (
2292
- MarkupKind .MARKDOWN ,
2293
- type_info .to_markdown (),
2294
- ),
2295
2297
sort_text = f"01_000_{ int (not b_snippet [1 ])} _{ b_snippet [0 ]} " ,
2296
2298
insert_text_format = InsertTextFormat .PLAIN_TEXT ,
2297
2299
text_edit = TextEdit (
2298
2300
range = completion_range ,
2299
2301
new_text = b_snippet [0 ],
2300
2302
),
2303
+ data = CompletionItemData (
2304
+ document_uri = str (self .document .uri ),
2305
+ type = CompleteResultKind .DOC_CACHE .name ,
2306
+ name = cache_name ,
2307
+ ),
2301
2308
)
2302
2309
)
2303
2310
elif type_info .name == "None" :
@@ -2325,18 +2332,29 @@ def _complete_keyword_arguments_at_position(
2325
2332
)
2326
2333
if type_info .members :
2327
2334
for member_index , member in enumerate (type_info .members ):
2335
+ cache_name = f"TYPE_MEMBER{ id (type_info )} _{ member_index } "
2336
+ self .parent .doc_cache [cache_name ] = (
2337
+ f"```python\n { member .name } = { member .value } \n ```"
2338
+ "\n \n ---"
2339
+ f"\n { type_info .to_markdown (only_doc = True )} "
2340
+ )
2328
2341
result .append (
2329
2342
CompletionItem (
2330
2343
label = member .name ,
2331
2344
kind = CompletionItemKind .ENUM_MEMBER ,
2332
- detail = type_info .name ,
2345
+ detail = f" { type_info .name } ( { type_info . type } )" ,
2333
2346
documentation = MarkupContent (
2334
2347
MarkupKind .MARKDOWN ,
2335
- f"```python\n { member .name } = { member .value } \n ```\n \n { type_info . to_markdown () } " ,
2348
+ f"```python\n { member .name } = { member .value } \n ```" ,
2336
2349
),
2337
- sort_text = f"09_{ i :03 } _{ member_index :03 } _{ member .name } " ,
2350
+ sort_text = f"09_{ i :9 } _{ member_index :09 } _{ member .name } " ,
2338
2351
insert_text_format = InsertTextFormat .PLAIN_TEXT ,
2339
2352
text_edit = TextEdit (range = completion_range , new_text = member .name ),
2353
+ data = CompletionItemData (
2354
+ document_uri = str (self .document .uri ),
2355
+ type = CompleteResultKind .DOC_CACHE .name ,
2356
+ name = cache_name ,
2357
+ ),
2340
2358
)
2341
2359
)
2342
2360
if type_info .items :
@@ -2357,19 +2375,22 @@ def _complete_keyword_arguments_at_position(
2357
2375
+ "}" ,
2358
2376
]
2359
2377
for i , snippet in enumerate (snippets ):
2378
+ cache_name = f"TYPE_ITEMS{ id (type_info )} _{ i } "
2379
+ self .parent .doc_cache [cache_name ] = type_info .to_markdown ()
2360
2380
if snippet :
2361
2381
result .append (
2362
2382
CompletionItem (
2363
2383
label = snippet ,
2364
2384
kind = CompletionItemKind .STRUCT ,
2365
- detail = type_info .name ,
2366
- documentation = MarkupContent (
2367
- MarkupKind .MARKDOWN ,
2368
- type_info .to_markdown (),
2369
- ),
2370
- sort_text = f"08_{ i :03} _{ snippet } " ,
2385
+ detail = f"{ type_info .name } ({ type_info .type } )" ,
2386
+ sort_text = f"08_{ i :09} _{ snippet } " ,
2371
2387
insert_text_format = InsertTextFormat .SNIPPET ,
2372
2388
text_edit = TextEdit (range = completion_range , new_text = snippet ),
2389
+ data = CompletionItemData (
2390
+ document_uri = str (self .document .uri ),
2391
+ type = CompleteResultKind .DOC_CACHE .name ,
2392
+ name = cache_name ,
2393
+ ),
2373
2394
)
2374
2395
)
2375
2396
0 commit comments