Skip to content

Copy LAST_JEDI_COMPLETIONS to cell document so that completionItem/resolve will work #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pylsp/python_lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,12 @@ def _cell_document__completion(self, cellDocument, position=None, **_kwargs):
if item.get("data", {}).get("doc_uri") == temp_uri:
item["data"]["doc_uri"] = cellDocument.uri

# Copy LAST_JEDI_COMPLETIONS to cell document so that completionItem/resolve will work
tempDocument = workspace.get_document(temp_uri)
cellDocument.shared_data["LAST_JEDI_COMPLETIONS"] = (
tempDocument.shared_data.get("LAST_JEDI_COMPLETIONS", None)
)

return completions

def m_text_document__completion(self, textDocument=None, position=None, **_kwargs):
Expand Down
68 changes: 68 additions & 0 deletions test/test_notebook_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,71 @@ def test_notebook_completion(client_server_pair) -> None:
},
],
}


@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows")
def test_notebook_completion_resolve(client_server_pair) -> None:
"""
Tests that completion item resolve works correctly
"""
client, server = client_server_pair
send_initialize_request(client)

# Open notebook
with patch.object(server._endpoint, "notify") as mock_notify:
send_notebook_did_open(
client,
[
"def answer():\n\t'''Returns an important number.'''\n\treturn 42",
"ans",
],
)
# wait for expected diagnostics messages
wait_for_condition(lambda: mock_notify.call_count >= 2)
assert len(server.workspace.documents) == 3
for uri in ["cell_1_uri", "cell_2_uri", "notebook_uri"]:
assert uri in server.workspace.documents

future = client._endpoint.request(
"textDocument/completion",
{
"textDocument": {
"uri": "cell_2_uri",
},
"position": {"line": 0, "character": 3},
},
)
result = future.result(CALL_TIMEOUT_IN_SECONDS)
assert result == {
"isIncomplete": False,
"items": [
{
"data": {"doc_uri": "cell_2_uri"},
"insertText": "answer",
"kind": 3,
"label": "answer()",
"sortText": "aanswer",
},
],
}

future = client._endpoint.request(
"completionItem/resolve",
{
"data": {"doc_uri": "cell_2_uri"},
"label": "answer()",
},
)
result = future.result(CALL_TIMEOUT_IN_SECONDS)
del result["detail"] # The value of this is unpredictable.
assert result == {
"data": {"doc_uri": "cell_2_uri"},
"insertText": "answer",
"kind": 3,
"label": "answer()",
"sortText": "aanswer",
"documentation": {
"kind": "markdown",
"value": "```python\nanswer()\n```\n\n\nReturns an important number.",
},
}
Loading