FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make workspace/didChangeConfig work with notebook documents by tkrabel-db · Pull Request #462 · python-lsp/python-lsp-server · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 5 additions & 1 deletion pylsp/workspace.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ def update_document(self, doc_uri, change, version=None):
def update_config(self, settings):
self._config.update((settings or {}).get("pylsp", {}))
for doc_uri in self.documents:
self.get_document(doc_uri).update_config(settings)
if isinstance(document := self.get_document(doc_uri), Notebook):
# Notebook documents don't have a config. The config is
# handled at the cell level.
return
document.update_config(settings)

def apply_edit(self, edit):
return self._endpoint.request(self.M_APPLY_EDIT, {"edit": edit})
Expand Down
57 changes: 55 additions & 2 deletions test/test_notebook_document.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import os
import time
from unittest.mock import patch, call

from unittest.mock import patch, call
from test.fixtures import CALL_TIMEOUT_IN_SECONDS

import pytest
from pylsp.workspace import Notebook

from pylsp import IS_WIN
from pylsp.lsp import NotebookCellKind
Expand Down Expand Up @@ -37,6 +37,59 @@ def test_initialize(client_server_pair):
assert isinstance(selector, list)


@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows")
def test_workspace_did_change_configuration(client_server_pair):
"""Test that we can update a workspace config w/o error when a notebook is open."""
client, server = client_server_pair
client._endpoint.request(
"initialize",
{
"processId": 1234,
"rootPath": os.path.dirname(__file__),
},
).result(timeout=CALL_TIMEOUT_IN_SECONDS)
assert server.workspace is not None

with patch.object(server._endpoint, "notify") as mock_notify:
client._endpoint.notify(
"notebookDocument/didOpen",
{
"notebookDocument": {
"uri": "notebook_uri",
"notebookType": "jupyter-notebook",
"cells": [
{
"kind": NotebookCellKind.Code,
"document": "cell_1_uri",
},
],
},
"cellTextDocuments": [
{
"uri": "cell_1_uri",
"languageId": "python",
"text": "",
},
],
},
)
wait_for_condition(lambda: mock_notify.call_count >= 1)
assert isinstance(server.workspace.get_document("notebook_uri"), Notebook)
assert len(server.workspace.documents) == 2

server.workspace.update_config(
{"pylsp": {"plugins": {"flake8": {"enabled": True}}}}
)

assert server.config.plugin_settings("flake8").get("enabled") is True
assert (
server.workspace.get_document("cell_1_uri")
._config.plugin_settings("flake8")
.get("enabled")
is True
)


@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows")
def test_notebook_document__did_open(
client_server_pair,
Expand Down

Back | FazBrowse Home | New Git URL