sinelaw/fresh · error
Line indexing not available for this document
Error message
Line indexing not available for this document
What it means
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.
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
Example fix
// before
let off = state.position_to_offset(DocumentPosition::LineColumn { line, column })?;
// after
if !state.has_line_index() {
let off = state.position_to_offset(DocumentPosition::ByteOffset(compute_byte_offset(...))?);
} else {
let off = state.position_to_offset(DocumentPosition::LineColumn { line, column })?;
} Defensive patterns
Strategy: type-guard
Validate before calling
if !doc.has_line_index() {
// fall back to byte offsets or build the line index first
} Type guard
fn supports_line_column(doc: &DocumentState) -> bool {
doc.has_line_index()
} Try / catch
match doc.position_to_offset(pos) {
Err(e) if e.to_string().contains("Line indexing not available") => fallback_to_byte_offset(pos),
other => other,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Invalid range: start offset
- Buffer range out of bounds: requested
- Buffer has unsaved changes
- no split layout
- Buffer has no file path
AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13).
Data as JSON: /api/errors/d0d6c098be43473f.
Report an issue: GitHub.
Appendix: source
Thrown at crates/fresh-editor/src/state.rs:2045
content: line_data.content,
has_newline: line_data.has_newline,
approximate_line_number: line_data.line_number,
})
.collect();
Ok(ViewportContent {
start_position: DocumentPosition::ByteOffset(start_offset),
lines,
has_more,
})
}
fn position_to_offset(&self, pos: DocumentPosition) -> Result<usize> {
match pos {
DocumentPosition::ByteOffset(offset) => Ok(offset),
DocumentPosition::LineColumn { line, column } => {
if !self.has_line_index() {
anyhow::bail!("Line indexing not available for this document");
}
// Use piece tree's position conversion
let position = crate::model::piece_tree::Position { line, column };
Ok(self.buffer.position_to_offset(position))
}
}
}
fn offset_to_position(&self, offset: usize) -> DocumentPosition {
if self.has_line_index() {
if let Some(pos) = self.buffer.offset_to_position(offset) {
DocumentPosition::LineColumn {
line: pos.line,
column: pos.column,
}
} else {
// Line index exists but metadata unavailable - fall back to byte offset
DocumentPosition::ByteOffset(offset)View on GitHub (pinned to 67894ca546)