Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 46ab3f1

Browse files
committedJul 28, 2023
wip
1 parent 54a25ba commit 46ab3f1

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed
 

‎pylsp/python_lsp.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,10 @@ def m_text_document__code_lens(self, textDocument=None, **_kwargs):
585585
def m_text_document__completion(self, textDocument=None, position=None, **_kwargs):
586586
return self.completions(textDocument['uri'], position)
587587

588-
def m_notebook_document__definition(self, cellDocument=None, position=None, **_kwargs):
588+
def _cell_document__definition(self, cellDocument=None, position=None, **_kwargs):
589589
# First, we create a temp TextDocument that represents the whole notebook
590590
# contents. We'll use this to send to the hook.
591-
workspace = self._match_uri_to_workspace(notebookDocument['uri'])
591+
workspace = self._match_uri_to_workspace(cellDocument.notebook_uri)
592592

593593
random_uri = str(uuid.uuid4())
594594
# cell_list helps us map the diagnostics back to the correct cell later.
@@ -609,6 +609,9 @@ def m_notebook_document__definition(self, cellDocument=None, position=None, **_k
609609
'source': cell_document.source
610610
}
611611

612+
if position is not None and cell_uri == cellDocument.uri:
613+
position['line'] += offset
614+
612615
cell_list.append(data)
613616
if offset == 0:
614617
total_source = cell_document.source
@@ -619,11 +622,10 @@ def m_notebook_document__definition(self, cellDocument=None, position=None, **_k
619622

620623
# TODO: make a workspace temp document context manager that yields the random uri and cleans up afterwards
621624
workspace.put_document(random_uri, total_source)
622-
625+
log.info(f'Making new document {random_uri}')
623626
try:
624-
# TODO: adjust position to temp document
625-
# position =
626627
definitions = self.definitions(random_uri, position)
628+
log.info(f'Got definitions: {definitions}')
627629

628630
# {
629631
# 'uri': uris.uri_with(document.uri, path=str(d.module_path)),
@@ -632,19 +634,21 @@ def m_notebook_document__definition(self, cellDocument=None, position=None, **_k
632634
# 'end': {'line': d.line - 1, 'character': d.column + len(d.name)},
633635
# }
634636
# }
637+
print(definitions)
635638
for definition in definitions:
636639
if definition['uri'] == random_uri:
637640
# find what cell the start is in
638641
# make sure the end is inside the cell's line_end
639642
# subtract that cell's line_start from both definition start and end
640643
pass
644+
return definitions
641645
finally:
642646
workspace.rm_document(random_uri)
643647

644648
def m_text_document__definition(self, textDocument=None, position=None, **_kwargs):
645649
if isinstance(textDocument, Cell):
646650
# actually, test to see if the document is a cell document
647-
return self.m_notebook_document__definition(textDocument, position, **_kwargs)
651+
return self._cell_document__definition(textDocument, position, **_kwargs)
648652
return self.definitions(textDocument['uri'], position)
649653

650654
def m_text_document__document_highlight(self, textDocument=None, position=None, **_kwargs):

‎test/test_notebook_document.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ def test_notebook_definition(
619619
{
620620
"uri": "cell_1_uri",
621621
"languageId": "python",
622-
"text": "x = 1",
622+
"text": "x=1",
623623
},
624624
{
625625
"uri": "cell_2_uri",
@@ -634,8 +634,6 @@ def test_notebook_definition(
634634
for uri in ["cell_1_uri", "cell_2_uri", "notebook_uri"]:
635635
assert uri in server.workspace.documents
636636

637-
638-
# TODO: send definition request
639637
with patch.object(server._endpoint, "notify") as mock_notify:
640638
client._endpoint.notify(
641639
"textDocument/definition",
@@ -649,7 +647,9 @@ def test_notebook_definition(
649647
}
650648
},
651649
)
652-
wait_for_condition(lambda: mock_notify.call_count >= 2)
650+
raise ValueError(mock_notify.mock_calls)
651+
wait_for_condition(lambda: mock_notify.call_count >= 1)
652+
return
653653

654654

655655
# TODO: definition return

0 commit comments

Comments
 (0)
Please sign in to comment.