Skip to content

Add Jupyter notebook cell support via LSP 3.17 Notebook Document Sync#473

Draft
edvilme wants to merge 9 commits intomainfrom
notebook-support-infra
Draft

Add Jupyter notebook cell support via LSP 3.17 Notebook Document Sync#473
edvilme wants to merge 9 commits intomainfrom
notebook-support-infra

Conversation

@edvilme
Copy link
Contributor

@edvilme edvilme commented Mar 10, 2026

Adds notebook (.ipynb) and Interactive Window support via LSP 3.17 Notebook Document Sync. Follows upstream template PR microsoft/vscode-python-tools-extension-template#265.

Changes: NOTEBOOK_SYNC_OPTIONS, _get_document_path(), 4 notebook handlers (didOpen/Change/Save/Close), non-Python cell filter, _clear_diagnostics on exception, activation events, test infrastructure (test_notebook.py, session helpers, sample.ipynb, mock fixes).

Closes #86
Closes #474

Manual Test Plan (use notebook-support-infra branch + Jupyter extension):

# Scenario Steps Verify Breakpoint
1 Activation Open .ipynb or Interactive Window Extension activates package.json activationEvents
2 Open Cell: x: int = "hello" Type error appears lsp_server.py:226 notebook_did_open — check nb.cells iteration
3 Edit Fix → x: int = 42, break → def f() -> int: return "a" Diagnostics update lsp_server.py:241 notebook_did_change — check text_content loop
4 Save Ctrl+S Diagnostics refresh lsp_server.py:266 notebook_did_save — check all cells re-linted
5 Close Close notebook tab Diagnostics cleared lsp_server.py:281 notebook_did_close — check empty diagnostics published
6 Multi-cell 3 cells with type errors Independent diagnostics lsp_server.py:309 _linting_helper — check publish per cell
7 Markdown Markdown + code cell No diagnostics on markdown lsp_server.py:253 — check language_id != "python" skip
8 Mixed .py + notebook open Independent; closing nb doesn't affect .py lsp_server.py:107 _get_document_path — check URI resolution
9 Interactive Run x: int = "hello" in Interactive Type error appears Same as 2
10 Edge cases Empty nb, valid x = 1, 20+ cells No crash, clean clear lsp_server.py:390 — check _clear_diagnostics in except block

- Add NOTEBOOK_SYNC_OPTIONS and notebook_document_sync to LanguageServer
- Add _get_document_path helper for resolving notebook cell URIs
- Add notebook lifecycle handlers (didOpen, didChange, didSave, didClose)
- Remove notebook-cell skip guard in _linting_helper
- Add onNotebook:jupyter-notebook and onNotebook:interactive activation events

Closes #86

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@edvilme edvilme added feature-request Request for new features or functionality debt Technical debt or repo cleanup labels Mar 10, 2026
@edvilme edvilme marked this pull request as draft March 10, 2026 20:45
edvilme and others added 8 commits March 10, 2026 13:49
Add NOTEBOOK_DOCUMENT_DID_* event constants and notebook-related type
classes (NotebookDocumentSyncOptions, NotebookCellLanguage, etc.) to the
lsprotocol.types mock so lsp_server.py can be imported in unit tests.
Also update _MockLS to use Pygls 2.0 method names.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add test_notebook.py with 5 tests covering notebook lifecycle events
(didOpen, didChange, didSave, didClose, cell kind filter).
Add notify_notebook_did_* helpers to session.py test client.
Add sample.ipynb test data fixture.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The repos use defaults.vscode_initialize_defaults() (a function),
not defaults.VSCODE_DEFAULT_INITIALIZE (a constant).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Drain didOpen diagnostics before registering the close callback
to avoid capturing stale open-diagnostics instead of the
expected empty close-diagnostics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Skip cells with languageId != 'python' in structure.did_open
to avoid running the linter on markdown or other non-Python cells.
Also clear diagnostics on exception in mypy's _linting_helper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

debt Technical debt or repo cleanup feature-request Request for new features or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template Sync: Add Jupyter notebook cell support via LSP 3.17 Notebook Document Sync Enable on Jupyter notebooks

1 participant