@@ -586,9 +586,12 @@ def m_text_document__completion(self, textDocument=None, position=None, **_kwarg
586586 return self .completions (textDocument ['uri' ], position )
587587
588588 def _cell_document__definition (self , cellDocument = None , position = None , ** _kwargs ):
589- # First, we create a temp TextDocument that represents the whole notebook
590- # contents. We'll use this to send to the hook.
589+ # First, we create a temp TextDocument to send to the hook that represents the whole notebook
590+ # contents.
591591 workspace = self ._match_uri_to_workspace (cellDocument .notebook_uri )
592+ notebookDocument = workspace .get_maybe_document (cellDocument .notebook_uri )
593+ if notebookDocument is None :
594+ raise ValueError ("Invalid notebook document" )
592595
593596 random_uri = str (uuid .uuid4 ())
594597 # cell_list helps us map the diagnostics back to the correct cell later.
@@ -636,19 +639,26 @@ def _cell_document__definition(self, cellDocument=None, position=None, **_kwargs
636639 # }
637640 print (definitions )
638641 for definition in definitions :
639- if definition ['uri' ] == random_uri :
640- # find what cell the start is in
641- # make sure the end is inside the cell's line_end
642- # subtract that cell's line_start from both definition start and end
643- pass
642+ # TODO: a better test for if a definition is the random_uri
643+ if random_uri in definition ['uri' ]:
644+ # Find the cell the start is in
645+ for cell in cell_list :
646+ # TODO: perhaps it is more correct to check definition['range']['end']['line'] <= cell['line_end'], but
647+ # that would mess up if a definition was split over cells
648+ if cell ['line_start' ] <= definition ['range' ]['start' ]['line' ] <= cell ['line_end' ]:
649+ definition ['uri' ] = cell ['uri' ]
650+ definition ['range' ]['start' ]['line' ] -= cell ['line_start' ]
651+ definition ['range' ]['end' ]['line' ] -= cell ['line_start' ]
644652 return definitions
645653 finally :
646654 workspace .rm_document (random_uri )
647655
648656 def m_text_document__definition (self , textDocument = None , position = None , ** _kwargs ):
649- if isinstance (textDocument , Cell ):
650- # actually, test to see if the document is a cell document
651- return self ._cell_document__definition (textDocument , position , ** _kwargs )
657+ # textDocument here is just a dict with a uri
658+ workspace = self ._match_uri_to_workspace (textDocument ['uri' ])
659+ document = workspace .get_document (textDocument ['uri' ])
660+ if isinstance (document , Cell ):
661+ return self ._cell_document__definition (document , position , ** _kwargs )
652662 return self .definitions (textDocument ['uri' ], position )
653663
654664 def m_text_document__document_highlight (self , textDocument = None , position = None , ** _kwargs ):
0 commit comments