BoundaryML/baml · error
Text document URI does not point to a text document
Error message
Text document URI does not point to a text document
What it means
Raised in Index::update_text_document when the document at the given key exists in the index but its controller is not a text document (e.g. it is another document kind). The LSP didOpen/didChange targets a URI whose stored controller cannot accept text content changes.
Solutions
- Verify the document was opened via textDocument/didOpen as a TextDocument before sending changes
- Check the URI scheme matches what the server registered (baml vs other schemes)
- Restart the language server to resync document state
- Ensure you don't reuse a DocumentKey across differently-typed documents
Example fix
// before: change without confirming kind
index.update_text_document(&key, changes, version, encoding)?;
// after: guard first
if let Some(doc) = index.document_controller_for_key(&key)?.as_text_mut() { /* apply changes */ } Defensive patterns
Strategy: validation
Validate before calling
// only send changes for text documents the server tracks as text if (trackedDocKind.get(uri) !== 'text') return;
Type guard
function isTextDocument(d: unknown): d is { kind: 'text'; text: string } { return !!d && typeof d === 'object' && (d as any).kind === 'text'; } Try / catch
try { await sendDidChange(uri, changes); } catch (e) { if (String(e).includes('does not point to a text document')) await reopenDocument(uri, text); else throw e; } Prevention
- Always didOpen before didChange
- Track document kinds client-side
- Avoid reusing URIs across document kinds
- Resync state after server restarts
When it happens
Trigger: Calling update_text_document with a DocumentKey whose entry is not a Text variant; a didChange notification for a URI that was opened as a non-text document.
Common situations: Editors sending didChange for untitled or virtual URIs registered under a non-text scheme; client/server disagreeing about document kinds after a reopening; stale client state pointing at a document replaced by another kind.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Document controller not available at
- tried to close document that didn't exist at
- {0}
- -32803
- all ingress capacities and the response reservation must be…
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/39b21939e9d78daa.
Report an issue: GitHub.
Appendix: source
Thrown at engine/language_server/src/session/index.rs:45
}
}
pub fn text_document_urls(&self) -> impl Iterator<Item = &DocumentKey> + '_ {
self.documents
.iter()
.filter_map(|(url, doc)| doc.as_text().and(Some(url)))
}
pub fn update_text_document(
&mut self,
key: &DocumentKey,
content_changes: Vec<lsp_types::TextDocumentContentChangeEvent>,
new_version: DocumentVersion,
encoding: PositionEncoding,
) -> anyhow::Result<()> {
let controller = self.document_controller_for_key(key)?;
let Some(document) = controller.as_text_mut() else {
anyhow::bail!("Text document URI does not point to a text document");
};
if content_changes.is_empty() {
document.update_version(new_version);
return Ok(());
}
document.apply_changes(content_changes, new_version, encoding);
Ok(())
}
// pub fn key_from_url(&self, url: Url) -> DocumentKey {
// DocumentKey::Text(url)
// }
pub fn num_documents(&self) -> usize {
self.documents.len()View on GitHub (pinned to bd85ce9dee)