@@ -530,3 +530,71 @@ def test_notebook_completion(client_server_pair) -> None:
530
530
},
531
531
],
532
532
}
533
+
534
+
535
+ @pytest .mark .skipif (IS_WIN , reason = "Flaky on Windows" )
536
+ def test_notebook_completion_resolve (client_server_pair ) -> None :
537
+ """
538
+ Tests that completion item resolve works correctly
539
+ """
540
+ client , server = client_server_pair
541
+ send_initialize_request (client )
542
+
543
+ # Open notebook
544
+ with patch .object (server ._endpoint , "notify" ) as mock_notify :
545
+ send_notebook_did_open (
546
+ client ,
547
+ [
548
+ "def answer():\n \t '''Returns an important number.'''\n \t return 42" ,
549
+ "ans" ,
550
+ ],
551
+ )
552
+ # wait for expected diagnostics messages
553
+ wait_for_condition (lambda : mock_notify .call_count >= 2 )
554
+ assert len (server .workspace .documents ) == 3
555
+ for uri in ["cell_1_uri" , "cell_2_uri" , "notebook_uri" ]:
556
+ assert uri in server .workspace .documents
557
+
558
+ future = client ._endpoint .request (
559
+ "textDocument/completion" ,
560
+ {
561
+ "textDocument" : {
562
+ "uri" : "cell_2_uri" ,
563
+ },
564
+ "position" : {"line" : 0 , "character" : 3 },
565
+ },
566
+ )
567
+ result = future .result (CALL_TIMEOUT_IN_SECONDS )
568
+ assert result == {
569
+ "isIncomplete" : False ,
570
+ "items" : [
571
+ {
572
+ "data" : {"doc_uri" : "cell_2_uri" },
573
+ "insertText" : "answer" ,
574
+ "kind" : 3 ,
575
+ "label" : "answer()" ,
576
+ "sortText" : "aanswer" ,
577
+ },
578
+ ],
579
+ }
580
+
581
+ future = client ._endpoint .request (
582
+ "completionItem/resolve" ,
583
+ {
584
+ "data" : {"doc_uri" : "cell_2_uri" },
585
+ "label" : "answer()" ,
586
+ },
587
+ )
588
+ result = future .result (CALL_TIMEOUT_IN_SECONDS )
589
+ del result ["detail" ] # The value of this is unpredictable.
590
+ assert result == {
591
+ "data" : {"doc_uri" : "cell_2_uri" },
592
+ "insertText" : "answer" ,
593
+ "kind" : 3 ,
594
+ "label" : "answer()" ,
595
+ "sortText" : "aanswer" ,
596
+ "documentation" : {
597
+ "kind" : "markdown" ,
598
+ "value" : "```python\n answer()\n ```\n \n \n Returns an important number." ,
599
+ },
600
+ }
0 commit comments