Skip to content

LSP: support notebook document synchronization (notebookDocument/didOpen, didChange, didSave, didClose) #2243

Backlog

Description

@lagergren

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: a notebookSelector (notebook type such as jupyter-notebook, and cell languages) and save.
  • 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: notebookDocumentSync with notebookType: 'jupyter-notebook' and Python cells (languageServerBase.ts). I didn't find it in upstream Pyright's languageServerBase.ts.
  • Ruff's server: notebook_document_sync (crates/ruff_server/src/server.rs).
  • python-lsp-server: notebookDocumentSync, and m_notebook_document__did_open (pylsp/python_lsp.py).
  • jedi-language-server: handles NOTEBOOK_DOCUMENT_DID_OPEN, DID_CHANGE and DID_CLOSE (server.py).

What users miss: these servers' diagnostics, completion and hover in Jupyter notebooks.

Today

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.jar and found only *.jupyter integration 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 .ipynb file;
    • each code cell gets a URI, e.g. the notebook URI with a #cell-<n> fragment or the vscode-notebook-cell scheme that servers expect from VS Code (check what basedpyright and Ruff accept);
    • cell text changes become notebookDocument/didChange with cells.textContent and incremental edits;
    • structure changes become cells.structure with a NotebookCellArrayChange;
    • diagnostics, completion and hover on a cell URI map back to the cell's range in the notebook editor.
  • 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.

Activity

  1. added
    enhancement
    on Nov 25, 2026
  2. added this to the Backlog milestone on Nov 30, 2026
  3. cordeirops commented on Nov 30, 2026

    @cordeirops
    Contributor

    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

    • In the initialize request, LSP4IJ sends no notebookDocument capability. basedpyright still answers with notebookDocumentSync (jupyter-notebook, scheme file, Python cells, save: true).
    • IC 2024.2 sandbox with Python Community Edition: the .ipynb opened as raw JSON. The Marketplace metadata of Jupyter 242.20224.300 has <depends>com.intellij.modules.ultimate</depends>.
    • IU 2026.3 (263.7307.200) sandbox, without activating Ultimate: after installing the Jupyter and Notebook Files plugins, the notebook opened in the cell editor.
    • In that sandbox, I temporarily mapped *.ipynb to the server. LSP4IJ sent a textDocument/didOpen with the file: 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)

    Cell URI Result
    vscode-notebook-cell:/…#cell-n Worked: hover in cell 2 sees a variable from cell 1, and an incremental change in cell 1 updates the diagnostics of cell 2
    file:///…#cell-n Partial: pushed diagnostics on open, but no hover and nothing after the change
    custom scheme No diagnostics, no hover

    Pull diagnostics are a problem. When the client declares textDocument.diagnostic with dynamicRegistration (as LSP4IJ does), basedpyright registers pull diagnostics. Pulling a cell URI then returns an empty full report, and nothing is pushed. Adding relatedDocumentSupport or the identifier, 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 if initializationOptions has "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.

    Build Package CellType intellij.notebooks.visualization visibility
    242 org.jetbrains.plugins.notebooks.visualization nested in NotebookCellLines older descriptor format
    243–252 com.intellij.notebooks.visualization nested in NotebookCellLines not checked
    253, 261 com.intellij.notebooks.visualization com.intellij.notebooks.jupyter.core.jupyter internal (source)
    262 com.intellij.notebooks.visualization com.intellij.notebooks.jupyter.core.jupyter public (source)
    263 com.intellij.notebooks.visualization com.intellij.notebooks.jupyter.core.jupyter public (shipped plugin)
    • One directly compiled implementation can't cover this range.
    • The 263 NotebookCellLines class 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.
    • For 253, 261, 262 and 263, the Marketplace listing of the Jupyter plugin shows no Ultimate dependency for the plugin as a whole. I only ran 263.

    Options I see:

    1. A separate module compiled against a newer platform and loaded through an optional dependency, limited to compatible versions.
    2. Reflection.
    3. Splitting the editor text at the #%% markers (#%%, #%% md, #%% raw in 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

    1. Would you accept a PR for this now? As a first step, I'd propose synchronization and diagnostics only.
    2. Which way of reading the cells would you prefer? Is it acceptable for notebook support to require a newer IDE, such as 262 or later?
    3. How should LSP4IJ handle the pull diagnostics case: leave it to initializationOptions, handle it per server in LSP4IJ, or investigate it as a basedpyright issue first?
  4. lagergren commented on Nov 30, 2026

    @lagergren
    CollaboratorAuthor

    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 notebookDocumentSync selects that notebook.

    2. Reading the cells: option 1. I'd make notebook support require 2026.2 or later, where intellij.notebooks.visualization becomes public.

    • Below 2026.2, the model moves between packages from release to release, so reflection would mean guessing per build.
    • The #%% text is how the editor renders the notebook. It can change without notice, and it gives no cell identity.

    Concretely:

    • Packaging: a separate source set or module, compiled against 2026.2 and shipped in the same plugin. Its classes would be reached only when the notebook plugin is present and the IDE is 262 or later: an optional <depends> on the notebook plugin, plus a build check before anything touches the notebook classes.
    • Build: the main build already compiles against 2026.2 with Java 25 (build: LSP4IJ doesn't build against IntelliJ 2026.2: Java 25, the debugger modules and the structure view plugin are taken from 2026.3 on only #2314), so that part is known ground.
    • Cell URIs: NotebookIntervalPointerFactory looks 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 *.ipynb mapped to a server today, LSP4IJ sends the editor's #%% text as the .ipynb document. With notebook synchronization, the .ipynb should 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:

    • If VS Code gets the cells' diagnostics by pulling, the difference between its requests and your script's is the answer.
    • If basedpyright pushes them to VS Code, something on the client side makes it push.
    • If neither, it's a basedpyright issue, with your script as the reproducer.

    Until then, "disablePullDiagnostics": true in 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions