Repository navigation
Backlog
Labels
enhancementNew feature or request
Milestone
Description
What
Notebook document synchronization (3.17) syncs a notebook as a whole. There is one notebook document with its cells, and each code cell is a text document with its own URI. The messages are notebookDocument/didOpen, didChange (cell structure, cell data and cell text), didSave and didClose.
- The client announces it with
notebookDocument.synchronization. - The server announces it with
notebookDocumentSync: anotebookSelector(notebook type such asjupyter-notebook, and cell languages) andsave. - The language features (completion, hover, diagnostics and so on) then work on the cell URIs, as for any text document.
Why
Python servers that support it:
- basedpyright:
notebookDocumentSyncwithnotebookType: 'jupyter-notebook'and Python cells (languageServerBase.ts). I didn't find it in upstream Pyright'slanguageServerBase.ts. - Ruff's server:
notebook_document_sync(crates/ruff_server/src/server.rs). - python-lsp-server:
notebookDocumentSync, andm_notebook_document__did_open(pylsp/python_lsp.py). - jedi-language-server: handles
NOTEBOOK_DOCUMENT_DID_OPEN,DID_CHANGEandDID_CLOSE(server.py).
What users miss: these servers' diagnostics, completion and hover in Jupyter notebooks.
Today
- No
notebookDocumentclient capability is sent (ClientCapabilitiesFactory.create). getNotebookDocumentService()is never called.- The docs say "Notebooks are not supported" (LSPSupport.md#L24).
How it could be done
This depends on what the IDE offers:
- Where notebooks live: IntelliJ IDEA 2026.2 has no notebook module in its own distribution. I checked
modules/module-descriptors.jarand found only*.jupyterintegration modules of the AI features. Notebooks come from the Jupyter plugin, which is bundled in PyCharm and DataSpell and is a Marketplace plugin for IntelliJ IDEA. - Plugin dependency: LSP4IJ would need an optional dependency on that plugin, in a
<depends optional="true" config-file=…>part, and its API for:- the cells of an open notebook: their kind, language and text ranges;
- changes to cells: added, removed, moved, text edited.
- To check: I couldn't check whether that API is public or stable. Ideally, a JetBrains contact says whether a cell model is meant for third-party use.
- Mapping:
- the notebook URI is the
.ipynbfile; - each code cell gets a URI, e.g. the notebook URI with a
#cell-<n>fragment or thevscode-notebook-cellscheme that servers expect from VS Code (check what basedpyright and Ruff accept); - cell text changes become
notebookDocument/didChangewithcells.textContentand incremental edits; - structure changes become
cells.structurewith aNotebookCellArrayChange; - diagnostics, completion and hover on a cell URI map back to the cell's range in the notebook editor.
- the notebook URI is the
- Simpler first step: synchronization and diagnostics only, then the language features.
- Without the Jupyter plugin, nothing changes.
This is the largest item in the list. It may be enough to file it and wait for demand.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
cordeirops commentedon Nov 30, 2026
Hello @lagergren, I looked into what it would take to implement this. I haven't changed any LSP4IJ code yet. Here is what I found, and a few questions before going further.
Environment: Windows 11, basedpyright 1.40.2.
Current behavior
initializerequest, LSP4IJ sends nonotebookDocumentcapability. basedpyright still answers withnotebookDocumentSync(jupyter-notebook, schemefile, Python cells,save: true)..ipynbopened as raw JSON. The Marketplace metadata of Jupyter242.20224.300has<depends>com.intellij.modules.ultimate</depends>.263.7307.200) sandbox, without activating Ultimate: after installing the Jupyter and Notebook Files plugins, the notebook opened in the cell editor.*.ipynbto the server. LSP4IJ sent atextDocument/didOpenwith thefile:URI of the.ipynb, and the editor text instead of the JSON:"#%%\nx: int = \"a\"\n#%%\nx: int = \"b\""Protocol test (standalone script talking to basedpyright, two one-line cells)
vscode-notebook-cell:/…#cell-nfile:///…#cell-nPull diagnostics are a problem. When the client declares
textDocument.diagnosticwithdynamicRegistration(as LSP4IJ does), basedpyright registers pull diagnostics. Pulling a cell URI then returns an empty full report, and nothing is pushed. AddingrelatedDocumentSupportor theidentifier, waiting longer, or pulling the notebook URI didn't help. Without the pull capability, the diagnostics are pushed. They are also pushed with the pull capability ifinitializationOptionshas"disablePullDiagnostics": true. I haven't found the cause.So with this server, notebook synchronization alone would probably show no diagnostics.
IDE cell model (
NotebookCellLines)I checked sample builds of each version, not every build.
CellTypeintellij.notebooks.visualizationvisibilityorg.jetbrains.plugins.notebooks.visualizationNotebookCellLinescom.intellij.notebooks.visualizationNotebookCellLinescom.intellij.notebooks.visualizationcom.intellij.notebooks.jupyter.core.jupyterinternal(source)com.intellij.notebooks.visualizationcom.intellij.notebooks.jupyter.core.jupyterpublic(source)com.intellij.notebooks.visualizationcom.intellij.notebooks.jupyter.core.jupyterpublic(shipped plugin)NotebookCellLinesclass is Java 25 bytecode, so I don't expect the default build (2024.2, Java 21) to compile against it. I haven't tried. CI tests 2024.2, 2025.3 and 2026.3.Options I see:
#%%markers (#%%,#%% md,#%% rawin 263). This needs no notebook classes at compile time, but relies on the editor's text format. I only saw it in 263, with code cells.Cell URIs also need to stay with their cells when cells move, so the cell's position isn't enough. 263 has a
NotebookIntervalPointerFactory, which I haven't examined.Not tested: Ruff, adding, removing or moving cells,
didSave,didClose, Markdown and raw cells, multi-line cells.Questions
initializationOptions, handle it per server in LSP4IJ, or investigate it as a basedpyright issue first?lagergren commentedon Nov 30, 2026
Thanks, that's a thorough look. The protocol test settles the cell URI question better than my guess in the issue did.
1. A PR now: yes, it's welcome, and synchronization plus diagnostics is the right first step. Nothing should change for users without notebooks: the notebook path applies only when a notebook editor is open and the server's
notebookDocumentSyncselects that notebook.2. Reading the cells: option 1. I'd make notebook support require 2026.2 or later, where
intellij.notebooks.visualizationbecomes public.#%%text is how the editor renders the notebook. It can change without notice, and it gives no cell identity.Concretely:
<depends>on the notebook plugin, plus a build check before anything touches the notebook classes.NotebookIntervalPointerFactorylooks like the right place to start for URIs that stay with their cells when cells move. For the scheme,vscode-notebook-cell, since your test shows basedpyright handles it and it's what servers get from VS Code.Your test also exposed something to keep in mind: with
*.ipynbmapped to a server today, LSP4IJ sends the editor's#%%text as the.ipynbdocument. With notebook synchronization, the.ipynbshould go to the server only as a notebook, not also as a text document.3. Pull diagnostics: I'd investigate before deciding, and avoid per-server code in LSP4IJ. VS Code's client also announces pull diagnostics with dynamic registration. So it's worth capturing what VS Code sends to basedpyright for a notebook, with the trace of its basedpyright extension:
Until then,
"disablePullDiagnostics": truein the initialization options is a workaround. Users can set it in the server's configuration without any LSP4IJ code.The issue is on the Backlog milestone. Once there's a PR, it moves to the release that takes it.