{"record":{"id":"791e9e9af9359b37","repo":"Hmbown/CodeWhale","slug":"lsp-file-exceeds-the-document-limit","errorCode":null,"errorMessage":"LSP file exceeds the document limit","messagePattern":"LSP file exceeds the document limit","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lsp/mod.rs","lineNumber":242,"sourceCode":"            let relative = requested\n                .strip_prefix(&root)\n                .or_else(|_| requested.strip_prefix(&canonical_root))\n                .map_err(|_| {\n                    std::io::Error::new(\n                        std::io::ErrorKind::PermissionDenied,\n                        \"LSP file is outside the workspace\",\n                    )\n                })?;\n            // Match the existing workspace file serving ceiling. Decode only\n            // bounded UTF-8 bytes from the same no-follow workspace opener.\n            const MAX_DOCUMENT_BYTES: u64 = 16 * 1024 * 1024;\n            let file = crate::fleet::files::WorkspaceFile::open(&canonical_root, relative, false)?;\n            let mut bytes = Vec::new();\n            file.open_file()?\n                .take(MAX_DOCUMENT_BYTES + 1)\n                .read_to_end(&mut bytes)?;\n            if bytes.len() as u64 > MAX_DOCUMENT_BYTES {\n                return Err(std::io::Error::new(\n                    std::io::ErrorKind::InvalidData,\n                    \"LSP file exceeds the document limit\",\n                ));\n            }\n            String::from_utf8(bytes)\n                .map_err(|error| std::io::Error::new(std::io::ErrorKind::InvalidData, error))\n        })\n        .await\n        .map_err(std::io::Error::other)?\n    }\n\n    /// Inject a fake transport for a language. Used by tests so we never\n    /// fork a real LSP server in CI.\n    #[cfg(test)]\n    pub async fn install_test_transport(&self, lang: Language, transport: Arc<dyn LspTransport>) {\n        self.test_transports.lock().await.insert(lang, transport);\n    }\n","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lsp/mod.rs#L224-L260","documentation":"read_workspace_text reads at most MAX_DOCUMENT_BYTES+1 bytes and rejects any workspace document larger than MAX_DOCUMENT_BYTES with InvalidData. The cap bounds memory used when serving file contents to LSP features.","triggerScenarios":"Any read_workspace_text call (or its callers diagnostics_for/diagnostics_for_custom/intelligence_at_revision/semantic_locations/diagnostics_for_paths) where the workspace file's byte size exceeds MAX_DOCUMENT_BYTES.","commonSituations":"Opening generated files, lockfiles, minified bundles, large JSON datasets, or vendored blobs that the LSP is asked to diagnose or analyze.","solutions":["Exclude the oversized file from LSP analysis (ignore patterns / don't request diagnostics for it).","Split or shrink the file; for generated artifacts, regenerate them smaller or gitignore them and skip analysis.","If the file is legitimately needed, pre-process it (e.g. pretty-print a minified bundle only partially, or index it instead)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let size = std::fs::metadata(path)?.len();\nif size > MAX_DOCUMENT_BYTES { eprintln!(\"skip LSP for oversized file {path:?}\"); }","typeGuard":null,"tryCatchPattern":"match read_workspace_text(p) {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidData => eprintln!(\"document too large; skipped {p:?}\"),\n    other => other.map(|_| ()),\n}","preventionTips":["Don't request LSP analysis for generated artifacts, lockfiles, minified bundles, or data dumps.","Filter candidate files by size before feeding them to LSP features.","Keep vendored blobs out of the workspace."],"tags":["lsp","file-size","limit"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}