Add Jupyter notebook cell support via LSP 3.17 Notebook Document Sync#265
Open
Add Jupyter notebook cell support via LSP 3.17 Notebook Document Sync#265
Conversation
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add Jupyter notebook cell support to Python tools extension
Add Jupyter notebook cell support via LSP 3.17 Notebook Document Sync
Mar 4, 2026
edvilme
reviewed
Mar 4, 2026
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
Contributor
|
This follows the same approach as microsoft/vscode-isort#565 |
rchiodo
reviewed
Mar 4, 2026
rchiodo
reviewed
Mar 4, 2026
rchiodo
reviewed
Mar 4, 2026
Co-authored-by: rchiodo <19672699+rchiodo@users.noreply.github.com>
Co-authored-by: rchiodo <19672699+rchiodo@users.noreply.github.com>
edvilme
requested changes
Mar 4, 2026
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
edvilme
requested changes
Mar 4, 2026
…I set Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
edvilme
approved these changes
Mar 4, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NOTEBOOK_SYNC_OPTIONSconstant and pass toLanguageServerconstructor inlsp_server.py_get_document_pathhelper inlsp_server.pylsp_server.py_run_tool_on_documentto use_get_document_pathand remove the skip guardpackage.jsonsession.pytest_get_cwd.pymock setuptest_notebook.pywith notebook lifecycle testssample.ipynbtest data fileREADME.mdNotebookCellKind.Codeinnotebook_did_changetest_notebook_did_change_new_cell_kind_filtertest_get_document_pathto checkvscode-notebook-cell:explicitly so other schemes fall through safely_collect_diagnosticshelper fromtest_notebook.py_get_document_pathwithurllib.parse.urlparse/urlunparse_replace()with explicit tuple inurlunparsecallnotebook_did_changecell-kind filter from dict to a set of code-cell URIsOriginal prompt
Summary
Add Jupyter notebook cell support to the VS Code Python tools extension template, enabling linting/formatting diagnostics and code actions for Python cells within
.ipynbnotebooks. This follows the same approach as microsoft/vscode-isort#565.Context
The template currently explicitly skips notebook cells in
_run_tool_on_document(line 439-442 ofbundled/tool/lsp_server.py):With pygls supporting LSP 3.17's notebook document sync protocol, the template should provide built-in notebook support as a starting point for extension developers.
Changes Required
1. LSP Server (
bundled/tool/lsp_server.py)1.1 Declare
NotebookDocumentSyncOptionsAdd after
MAX_WORKERSand pass to theLanguageServerconstructor:1.2 Add
_get_document_pathhelperResolves
vscode-notebook-cell:URIs to filesystem paths:1.3 Add four notebook lifecycle handlers
After the existing
did_closehandler, add handlers for:NOTEBOOK_DOCUMENT_DID_OPEN— iterate all code cells, run_linting_helper, publish diagnostics per cellNOTEBOOK_DOCUMENT_DID_CHANGE— re-lint cells with text changes, lint newly added cells (structure.did_open), clear diagnostics for removed cells (structure.did_close)NOTEBOOK_DOCUMENT_DID_SAVE— re-lint all code cellsNOTEBOOK_DOCUMENT_DID_CLOSE— clear diagnostics for all cellsEach handler should:
LSP_SERVER.workspace.get_notebook_document()andget_text_document()lsp.NotebookCellKind.CodeLSP_SERVER.text_document_publish_diagnostics()withlsp.PublishDiagnosticsParamsExample pattern for
notebook_did_open:Follow this same pattern for
did_change,did_save, anddid_close. See vscode-isort PR #565 diff for lsp_server.py for the full implementation of all four handlers.1.4 Remove/update the notebook-cell skip guard in
_run_tool_on_documentReplace the current skip guard (lines 439-442) with a TODO comment that indicates notebook cells are now supported, and update
document.pathreferences in that function to use_get_document_path(document)where the tool needs a filesystem path.2. Extension Manifest (
package.json)Add notebook activation events:
3. Test Infrastructure
3.1 LSP Test Client (
src/test/python_tests/lsp_test_client/session.py)Add four new methods to
LspSession(afternotify_did_close):notify_notebook_did_open(self, params)→ sends"notebookDocument/didOpen"notify_notebook_did_change(self, params)→ sends"notebookDocument/didChange"This pull request was created from Copilot chat.
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.