Skip to content

Commit 909ee85

Browse files
edvilmeCopilot
andauthored
Add notebook document sync infrastructure for Jupyter support (#664)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c47b64a commit 909ee85

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

bundled/tool/lsp_server.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,28 @@ def update_environ_path() -> None:
7777
RUNNER = pathlib.Path(__file__).parent / "lsp_runner.py"
7878

7979
MAX_WORKERS = 5
80+
NOTEBOOK_SYNC_OPTIONS = lsp.NotebookDocumentSyncOptions(
81+
notebook_selector=[
82+
lsp.NotebookDocumentFilterWithNotebook(
83+
notebook="jupyter-notebook",
84+
cells=[
85+
lsp.NotebookCellLanguage(language="python"),
86+
],
87+
),
88+
lsp.NotebookDocumentFilterWithNotebook(
89+
notebook="interactive",
90+
cells=[
91+
lsp.NotebookCellLanguage(language="python"),
92+
],
93+
),
94+
],
95+
save=True,
96+
)
8097
LSP_SERVER = LanguageServer(
81-
name="black-server", version="v0.1.0", max_workers=MAX_WORKERS
98+
name="black-server",
99+
version="v0.1.0",
100+
max_workers=MAX_WORKERS,
101+
notebook_document_sync=NOTEBOOK_SYNC_OPTIONS,
82102
)
83103

84104

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
"onLanguage:python",
4949
"workspaceContains:pyproject.toml",
5050
"workspaceContains:.black",
51-
"workspaceContains:*.py"
51+
"workspaceContains:*.py",
52+
"onNotebook:jupyter-notebook",
53+
"onNotebook:interactive"
5254
],
5355
"main": "./dist/extension.js",
5456
"l10n": "./l10n",

src/test/python_tests/test_get_cwd.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def feature(self, *args, **kwargs):
2323
def command(self, *args, **kwargs):
2424
return lambda f: f
2525

26-
def show_message_log(self, *args, **kwargs):
26+
def window_log_message(self, *args, **kwargs):
2727
pass
2828

29-
def show_message(self, *args, **kwargs):
29+
def window_show_message(self, *args, **kwargs):
3030
pass
3131

3232
mock_lsp_server = types.ModuleType("pygls.lsp.server")
@@ -48,6 +48,10 @@ def show_message(self, *args, **kwargs):
4848
"INITIALIZE",
4949
"EXIT",
5050
"SHUTDOWN",
51+
"NOTEBOOK_DOCUMENT_DID_OPEN",
52+
"NOTEBOOK_DOCUMENT_DID_CHANGE",
53+
"NOTEBOOK_DOCUMENT_DID_SAVE",
54+
"NOTEBOOK_DOCUMENT_DID_CLOSE",
5155
]:
5256
setattr(mock_lsp, _name, _name)
5357
for _name in [
@@ -56,13 +60,21 @@ def show_message(self, *args, **kwargs):
5660
"DidCloseTextDocumentParams",
5761
"DidOpenTextDocumentParams",
5862
"DidSaveTextDocumentParams",
63+
"DidChangeNotebookDocumentParams",
64+
"DidCloseNotebookDocumentParams",
65+
"DidOpenNotebookDocumentParams",
66+
"DidSaveNotebookDocumentParams",
5967
"DocumentFormattingParams",
6068
"InitializeParams",
69+
"NotebookCellKind",
70+
"NotebookCellLanguage",
71+
"NotebookDocumentFilterWithNotebook",
72+
"NotebookDocumentSyncOptions",
6173
"Position",
6274
"Range",
6375
"TextEdit",
6476
]:
65-
setattr(mock_lsp, _name, type(_name, (), {}))
77+
setattr(mock_lsp, _name, type(_name, (), {"__init__": lambda self, **kw: None}))
6678
mock_lsp.MessageType = type(
6779
"MessageType", (), {"Log": 4, "Error": 1, "Warning": 2, "Info": 3}
6880
)

0 commit comments

Comments
 (0)