{"record":{"id":"e8b4b46e54164716","repo":"astral-sh/ruff","slug":"text-document-path-does-not-point-to-a-text-docume","errorCode":null,"errorMessage":"Text document path does not point to a text document","messagePattern":"Text document path does not point to a text document","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ty_server/src/session.rs","lineNumber":1981,"sourceCode":"            &script_progress,\n        );\n    }\n\n    pub(crate) fn update_text_document(\n        &mut self,\n        session: &mut Session,\n        client: &Client,\n        content_changes: Vec<TextDocumentContentChangeEvent>,\n        new_version: DocumentVersion,\n    ) -> crate::Result<()> {\n        let position_encoding = session.position_encoding();\n        {\n            let mut index = session.index_mut();\n\n            let document_mut = index.document_mut(&self.key())?;\n\n            let Some(document) = document_mut.as_text_mut() else {\n                anyhow::bail!(\"Text document path does not point to a text document\");\n            };\n\n            if content_changes.is_empty() {\n                document.update_version(new_version);\n            } else {\n                document.apply_changes(content_changes, new_version, position_encoding);\n            }\n\n            self.set_version(document.version());\n        }\n\n        self.update_in_db(session, client);\n\n        Ok(())\n    }\n\n    pub(crate) fn update_notebook_document(\n        &mut self,","sourceCodeStart":1963,"sourceCodeEnd":1999,"githubUrl":"https://github.com/astral-sh/ruff/blob/5bb508f59481c1a02d5c7ff8568b9ffd8a763eef/crates/ty_server/src/session.rs#L1963-L1999","documentation":"In `ty_server`, `update_text_document` fetches the open document indexed under the current document key and requires it to be a text (script) document. If the key maps to a notebook or other non-text document kind, the `as_text_mut` narrowing fails and the server returns this error, preventing text-content changes from being applied to the wrong document type.","triggerScenarios":"An LSP `textDocument/didChange` is routed to a document key that was opened as a notebook (or other non-text) document — e.g. an editor/client sending incremental text changes for a `.ipynb` URI, or the server's document index classifying the URI differently than the client does.","commonSituations":"Jupyter/VS Code clients mixing notebook and text-document sync for the same file URI; a server-side classification mismatch after a client upgrade; custom clients sending didChange for notebook cells instead of `update_notebook_document`.","solutions":["Update the client so notebook changes go through notebook sync (cells/metadata), not `textDocument/didChange`","Verify the URI sent in didChange matches a text document the client opened via didOpen, not a `.ipynb`","Restart the language server session so the document index reclassifies the document correctly","If developing a client, call `update_notebook_document` paths for notebook documents"],"exampleFix":"// before\nclient.send(\"textDocument/didChange\", { uri: \"notebook.ipynb\", ... })\n// after\nclient.send(\"notebookDocument/didChange\", { uri: \"notebook.ipynb\", cells: ... })","handlingStrategy":"type-guard","validationCode":"// before sending didChange, confirm the document kind\nif (openedDocs.get(uri)?.kind === 'text') {\n  sendDidChange(uri, changes);\n} else {\n  sendNotebookDidChange(uri, changes);\n}","typeGuard":"fn is_text_document(doc: &Document) -> bool {\n    matches!(doc, Document::Text(_))\n}","tryCatchPattern":"match server.update_text_document(...) {\n    Err(e) if e.to_string().contains(\"does not point to a text document\") => {\n        // fall back to the notebook update path\n        server.update_notebook_document(...)\n    }\n    other => other,\n}","preventionTips":["Route didChange only for documents opened as text documents via didOpen","Send notebook edits through notebookDocument/didChange, not textDocument/didChange","Keep client document-kind tracking in sync with the server's index after restarts"],"tags":["lsp","document-sync","notebook","server"],"backgroundTag":"document-type-mismatch","analyzedSha":"5bb508f59481c1a02d5c7ff8568b9ffd8a763eef","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}