{"record":{"id":"39b21939e9d78daa","repo":"BoundaryML/baml","slug":"text-document-uri-does-not-point-to-a-text-document","errorCode":null,"errorMessage":"Text document URI does not point to a text document","messagePattern":"Text document URI does not point to a text document","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_server/src/session/index.rs","lineNumber":45,"sourceCode":"        }\n    }\n\n    pub fn text_document_urls(&self) -> impl Iterator<Item = &DocumentKey> + '_ {\n        self.documents\n            .iter()\n            .filter_map(|(url, doc)| doc.as_text().and(Some(url)))\n    }\n\n    pub fn update_text_document(\n        &mut self,\n        key: &DocumentKey,\n        content_changes: Vec<lsp_types::TextDocumentContentChangeEvent>,\n        new_version: DocumentVersion,\n        encoding: PositionEncoding,\n    ) -> anyhow::Result<()> {\n        let controller = self.document_controller_for_key(key)?;\n        let Some(document) = controller.as_text_mut() else {\n            anyhow::bail!(\"Text document URI does not point to a text document\");\n        };\n\n        if content_changes.is_empty() {\n            document.update_version(new_version);\n            return Ok(());\n        }\n\n        document.apply_changes(content_changes, new_version, encoding);\n\n        Ok(())\n    }\n\n    // pub fn key_from_url(&self, url: Url) -> DocumentKey {\n    //     DocumentKey::Text(url)\n    // }\n\n    pub fn num_documents(&self) -> usize {\n        self.documents.len()","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_server/src/session/index.rs#L27-L63","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: change without confirming kind\nindex.update_text_document(&key, changes, version, encoding)?;\n// after: guard first\nif let Some(doc) = index.document_controller_for_key(&key)?.as_text_mut() { /* apply changes */ }","handlingStrategy":"validation","validationCode":"// only send changes for text documents the server tracks as text\nif (trackedDocKind.get(uri) !== 'text') return;","typeGuard":"function isTextDocument(d: unknown): d is { kind: 'text'; text: string } { return !!d && typeof d === 'object' && (d as any).kind === 'text'; }","tryCatchPattern":"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; }","preventionTips":["Always didOpen before didChange","Track document kinds client-side","Avoid reusing URIs across document kinds","Resync state after server restarts"],"tags":["lsp","document","rust"],"backgroundTag":"invalid-state-transition","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}