{"record":{"id":"d0d6c098be43473f","repo":"sinelaw/fresh","slug":"line-indexing-not-available-for-this-document","errorCode":null,"errorMessage":"Line indexing not available for this document","messagePattern":"Line indexing not available for this document","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fresh-editor/src/state.rs","lineNumber":2045,"sourceCode":"                content: line_data.content,\n                has_newline: line_data.has_newline,\n                approximate_line_number: line_data.line_number,\n            })\n            .collect();\n\n        Ok(ViewportContent {\n            start_position: DocumentPosition::ByteOffset(start_offset),\n            lines,\n            has_more,\n        })\n    }\n\n    fn position_to_offset(&self, pos: DocumentPosition) -> Result<usize> {\n        match pos {\n            DocumentPosition::ByteOffset(offset) => Ok(offset),\n            DocumentPosition::LineColumn { line, column } => {\n                if !self.has_line_index() {\n                    anyhow::bail!(\"Line indexing not available for this document\");\n                }\n                // Use piece tree's position conversion\n                let position = crate::model::piece_tree::Position { line, column };\n                Ok(self.buffer.position_to_offset(position))\n            }\n        }\n    }\n\n    fn offset_to_position(&self, offset: usize) -> DocumentPosition {\n        if self.has_line_index() {\n            if let Some(pos) = self.buffer.offset_to_position(offset) {\n                DocumentPosition::LineColumn {\n                    line: pos.line,\n                    column: pos.column,\n                }\n            } else {\n                // Line index exists but metadata unavailable - fall back to byte offset\n                DocumentPosition::ByteOffset(offset)","sourceCodeStart":2027,"sourceCodeEnd":2063,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor/src/state.rs#L2027-L2063","documentation":"position_to_offset was asked to convert a LineColumn DocumentPosition to a byte offset, but the document's buffer has no line index built. state.rs:2045 guards this because piece_tree position conversion requires line indexing; without it, line/column lookups are impossible.","triggerScenarios":"Calling position_to_offset with DocumentPosition::LineColumn on a document where has_line_index() returns false — typically huge files or documents opened in a mode that skips line-index construction.","commonSituations":"Plugins/LSP integrations issuing line/column-based positions on very large files loaded without a line index; remote/session code converting positions after the editor downgraded the buffer to a non-indexed representation.","solutions":["Pass DocumentPosition::ByteOffset instead of LineColumn when the document lacks a line index","Ensure the line index is built for the document before issuing LineColumn positions (check has_line_index())","Convert the position to a byte offset by other means (e.g. scanning content) if line indexing cannot be enabled"],"exampleFix":"// before\nlet off = state.position_to_offset(DocumentPosition::LineColumn { line, column })?;\n// after\nif !state.has_line_index() {\n    let off = state.position_to_offset(DocumentPosition::ByteOffset(compute_byte_offset(...))?);\n} else {\n    let off = state.position_to_offset(DocumentPosition::LineColumn { line, column })?;\n}","handlingStrategy":"type-guard","validationCode":"if !doc.has_line_index() {\n    // fall back to byte offsets or build the line index first\n}","typeGuard":"fn supports_line_column(doc: &DocumentState) -> bool {\n    doc.has_line_index()\n}","tryCatchPattern":"match doc.position_to_offset(pos) {\n    Err(e) if e.to_string().contains(\"Line indexing not available\") => fallback_to_byte_offset(pos),\n    other => other,\n}","preventionTips":["Check has_line_index() before constructing LineColumn positions","Use ByteOffset positions for very large or non-indexed documents","Keep line-index construction enabled for documents you will address by line/column"],"tags":["editor","document-model","positioning","rust"],"backgroundTag":"unsupported-operation","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}