astral-sh/ruff · error
Text document path does not point to a text document
Error message
Text document path does not point to a text document
What it means
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.
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
Example fix
// before
client.send("textDocument/didChange", { uri: "notebook.ipynb", ... })
// after
client.send("notebookDocument/didChange", { uri: "notebook.ipynb", cells: ... }) Defensive patterns
Strategy: type-guard
Validate before calling
// before sending didChange, confirm the document kind
if (openedDocs.get(uri)?.kind === 'text') {
sendDidChange(uri, changes);
} else {
sendNotebookDidChange(uri, changes);
} Type guard
fn is_text_document(doc: &Document) -> bool {
matches!(doc, Document::Text(_))
} Try / catch
match server.update_text_document(...) {
Err(e) if e.to_string().contains("does not point to a text document") => {
// fall back to the notebook update path
server.update_notebook_document(...)
}
other => other,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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`.
Related errors
AI-assisted analysis of astral-sh/ruff@5bb508f594 (2026-09-05).
Data as JSON: /api/errors/e8b4b46e54164716.
Report an issue: GitHub.
Appendix: source
Thrown at crates/ty_server/src/session.rs:1981
&script_progress,
);
}
pub(crate) fn update_text_document(
&mut self,
session: &mut Session,
client: &Client,
content_changes: Vec<TextDocumentContentChangeEvent>,
new_version: DocumentVersion,
) -> crate::Result<()> {
let position_encoding = session.position_encoding();
{
let mut index = session.index_mut();
let document_mut = index.document_mut(&self.key())?;
let Some(document) = document_mut.as_text_mut() else {
anyhow::bail!("Text document path does not point to a text document");
};
if content_changes.is_empty() {
document.update_version(new_version);
} else {
document.apply_changes(content_changes, new_version, position_encoding);
}
self.set_version(document.version());
}
self.update_in_db(session, client);
Ok(())
}
pub(crate) fn update_notebook_document(
&mut self,View on GitHub (pinned to 5bb508f594)