You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,6 +71,47 @@ References, to other extension created by our team using the template:
71
71
- Implementation showing how to handle Formatting. [Black Formatter](https://github.com/microsoft/vscode-black-formatter/tree/main/bundled/tool)
72
72
- Implementation showing how to handle Code Actions. [isort](https://github.com/microsoft/vscode-isort/blob/main/bundled/tool)
73
73
74
+
## Jupyter Notebook Support
75
+
76
+
This template includes built-in support for linting and formatting Python cells inside Jupyter notebooks (`.ipynb` files) and the VS Code Interactive Window, following the [LSP 3.17 Notebook Document Sync specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notebookDocument_synchronization).
77
+
78
+
### How it works
79
+
80
+
The server declares `NotebookDocumentSyncOptions` (in `lsp_server.py`) that tell the client which notebook types and cell languages to synchronize:
-`notebookDocument/didOpen` — diagnostics are published for every Python code cell when a notebook is opened.
101
+
-`notebookDocument/didChange` — diagnostics are updated for cells whose text changed, new cells are linted, and removed cells have their diagnostics cleared.
102
+
-`notebookDocument/didSave` — all Python code cells are re-linted on save.
103
+
-`notebookDocument/didClose` — diagnostics are cleared for all cells when the notebook is closed.
104
+
105
+
The `_get_document_path` helper resolves `vscode-notebook-cell:` URIs back to the parent notebook's filesystem path, so your tool receives a valid path even when processing a cell document.
106
+
107
+
### Customizing notebook support
108
+
109
+
- To disable notebook support entirely, remove the `notebook_document_sync=NOTEBOOK_SYNC_OPTIONS` argument from the `LanguageServer` constructor and delete the four `notebook_did_*` handlers.
110
+
- To restrict which cell languages are supported, update the `cells` list in `NOTEBOOK_SYNC_OPTIONS`.
111
+
- To change the linting/formatting behavior per cell, update the individual handlers.
112
+
113
+
See [microsoft/vscode-isort#565](https://github.com/microsoft/vscode-isort/pull/565) for a reference implementation of notebook support in a production extension.
114
+
74
115
## Building and Run the extension
75
116
76
117
Run the `Debug Extension and Python` configuration form VS Code. That should build and debug the extension in host window.
0 commit comments