astral-sh/ruff · error

Notebook document URI does not point to a notebook document

Error message

Notebook document URI does not point to a notebook document

What it means

After handling cell-structure events, `update_notebook_document` fetches the document controller and expects it to hold a notebook. If the controller's document is a plain text document instead, the notebook update cannot be applied and the server bails. It mirrors error 81 for the notebook direction.

Solutions

  1. Send `textDocument/didChange` for plain text documents instead of notebookDocument/didChange
  2. Close the document with the correct (text) lifecycle, then reopen it as a notebook via notebookDocument/didOpen
  3. Restart the Ruff server to clear the mismatched document index
Defensive patterns

Strategy: validation

Validate before calling

// only route notebookDocument/didChange to URIs opened as notebooks
if (!openedAsNotebook.has(uri)) {
  sendTextDocumentDidChange(doc);
} else {
  sendNotebookDidChange(doc);
}

Type guard

fn is_notebook_document(controller: &DocumentController) -> bool { matches!(controller.as_notebook(), Some(_)) }

Try / catch

if let Err(e) = session.update_notebook_document(&key, cells, meta, ver, enc) { if e.to_string().contains("not point to a notebook document") { /* fall back to textDocument path */ } }

Prevention

When it happens

Trigger: Calling `session.update_notebook_document(key, cells, metadata, new_version, encoding)` where the key resolves to a controller holding a text document, so `as_notebook_mut()` returns None.

Common situations: A client sends `notebookDocument/didChange` for a URI that was opened as a regular text file via `textDocument/didOpen`; conflicting open events for the same URI across editors/plugins.

Related errors


AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05). Data as JSON: /api/errors/1dc11b799f729310. Report an issue: GitHub.

Appendix: source

Thrown at crates/ruff_server/src/session/index.rs:168

        if let Some(lsp_types::NotebookDocumentCellChangeStructure {
            did_open: Some(did_open),
            ..
        }) = cells.as_ref().and_then(|cells| cells.structure.as_ref())
        {
            let Some(path) = self.uri_for_key(key).cloned() else {
                anyhow::bail!("Tried to open unavailable document `{key}`");
            };

            for opened_cell in did_open {
                self.notebook_cells
                    .insert(opened_cell.uri.clone(), path.clone());
            }
            // deleted notebook cells are closed via textDocument/didClose - we don't close them here.
        }

        let controller = self.document_controller_for_key(key)?;
        let Some(notebook) = controller.as_notebook_mut() else {
            anyhow::bail!("Notebook document URI does not point to a notebook document");
        };

        notebook.update(cells, metadata, new_version, encoding)?;
        Ok(())
    }

    pub(super) fn open_workspace_folder(
        &mut self,
        uri: Uri,
        global: &GlobalClientSettings,
        client: &Client,
    ) -> crate::Result<()> {
        // TODO(jane): Find a way for workspace client settings to be added or changed dynamically.
        self.settings
            .register_workspace(&Workspace::new(uri), global, client)
    }

    pub(super) fn close_workspace_folder(&mut self, workspace_uri: &Uri) -> crate::Result<()> {

View on GitHub (pinned to 26f38c119c)