@@ -687,7 +687,36 @@ def m_text_document__code_action(
687
687
def m_text_document__code_lens (self , textDocument = None , ** _kwargs ):
688
688
return self .code_lens (textDocument ["uri" ])
689
689
690
+ def _cell_document__completion (self , cellDocument , position = None , ** _kwargs ):
691
+ workspace = self ._match_uri_to_workspace (cellDocument .notebook_uri )
692
+ notebookDocument = workspace .get_maybe_document (cellDocument .notebook_uri )
693
+ if notebookDocument is None :
694
+ raise ValueError ("Invalid notebook document" )
695
+
696
+ cell_data = notebookDocument .cell_data ()
697
+
698
+ # Concatenate all cells to be a single temporary document
699
+ total_source = "\n " .join (data ["source" ] for data in cell_data .values ())
700
+ with workspace .temp_document (total_source ) as temp_uri :
701
+ # update position to be the position in the temp document
702
+ if position is not None :
703
+ position ["line" ] += cell_data [cellDocument .uri ]["line_start" ]
704
+
705
+ completions = self .completions (temp_uri , position )
706
+
707
+ # Translate temp_uri locations to cell document locations
708
+ for item in completions .get ("items" , []):
709
+ if item .get ("data" , {}).get ("doc_uri" ) == temp_uri :
710
+ item ["data" ]["doc_uri" ] = cellDocument .uri
711
+
712
+ return completions
713
+
690
714
def m_text_document__completion (self , textDocument = None , position = None , ** _kwargs ):
715
+ # textDocument here is just a dict with a uri
716
+ workspace = self ._match_uri_to_workspace (textDocument ["uri" ])
717
+ document = workspace .get_document (textDocument ["uri" ])
718
+ if isinstance (document , Cell ):
719
+ return self ._cell_document__completion (document , position , ** _kwargs )
691
720
return self .completions (textDocument ["uri" ], position )
692
721
693
722
def _cell_document__definition (self , cellDocument , position = None , ** _kwargs ):
0 commit comments