@@ -149,7 +149,7 @@ impl Document {
149 let file = File::open(&path).context(format!("unable to open {:?}", path))?;
149 let file = File::open(&path).context(format!("unable to open {:?}", path))?;
150 let mut doc = Rope::from_reader(BufReader::new(file))?;
150 let mut doc = Rope::from_reader(BufReader::new(file))?;
151 // add missing newline at the end of file
151 // add missing newline at the end of file
152− if doc.byte(doc.len_bytes() - 1) != b'\n' {
152+ if doc.len_bytes() == 0 || doc.byte(doc.len_bytes() - 1) != b'\n' {
153 doc.insert_char(doc.len_chars(), '\n');
153 doc.insert_char(doc.len_chars(), '\n');