From 4369e7a3094f8d95b7616ffb6f45ee66e55610a3 Mon Sep 17 00:00:00 2001 From: ImajinDevon Date: Sat, 16 Jul 2022 21:50:17 -0400 Subject: [PATCH 1/2] Utilize the `fs` module --- lapce-proxy/src/buffer.rs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lapce-proxy/src/buffer.rs b/lapce-proxy/src/buffer.rs index 96de5645..8912d02b 100644 --- a/lapce-proxy/src/buffer.rs +++ b/lapce-proxy/src/buffer.rs @@ -3,7 +3,6 @@ use std::ffi::OsString; use std::fs; use std::fs::File; -use std::io::Read; use std::io::Write; use std::path::PathBuf; use std::{borrow::Cow, path::Path, time::SystemTime}; @@ -81,15 +80,13 @@ pub fn update( self.rev += 1; let content_change = get_document_content_changes(delta, self); self.rope = delta.apply(&self.rope); - let content_change = match content_change { - Some(content_change) => content_change, - None => TextDocumentContentChangeEvent { + Some(content_change.unwrap_or_else(|| { + TextDocumentContentChangeEvent { range: None, range_length: None, text: self.get_document(), - }, - }; - Some(content_change) + } + })) } pub fn get_document(&self) -> String { @@ -131,17 +128,11 @@ pub fn is_empty(&self) -> bool { } pub fn load_file(path: &Path) -> Result { - let mut f = File::open(path)?; - let mut bytes = Vec::new(); - f.read_to_end(&mut bytes)?; - Ok(std::str::from_utf8(&bytes)?.to_string()) + Ok(fs::read_to_string(path)?) } fn load_rope(path: &Path) -> Result { - let mut f = File::open(path)?; - let mut bytes = Vec::new(); - f.read_to_end(&mut bytes)?; - Ok(Rope::from(std::str::from_utf8(&bytes)?)) + Ok(Rope::from(fs::read_to_string(path)?)) } fn language_id_from_path(path: &Path) -> Option<&str> { From 70071f3d174669fa1656e587711117b2f28342de Mon Sep 17 00:00:00 2001 From: ImajinDevon Date: Mon, 18 Jul 2022 14:22:38 -0400 Subject: [PATCH 2/2] Utilize the `fs` module --- lapce-proxy/src/buffer.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lapce-proxy/src/buffer.rs b/lapce-proxy/src/buffer.rs index 8912d02b..8d5c52cd 100644 --- a/lapce-proxy/src/buffer.rs +++ b/lapce-proxy/src/buffer.rs @@ -1,13 +1,12 @@ use anyhow::{anyhow, Result}; use lapce_rpc::buffer::BufferId; +use lsp_types::*; use std::ffi::OsString; use std::fs; use std::fs::File; use std::io::Write; use std::path::PathBuf; use std::{borrow::Cow, path::Path, time::SystemTime}; - -use lsp_types::*; use xi_rope::{interval::IntervalBounds, rope::Rope, RopeDelta}; #[derive(Clone)] @@ -80,13 +79,13 @@ pub fn update( self.rev += 1; let content_change = get_document_content_changes(delta, self); self.rope = delta.apply(&self.rope); - Some(content_change.unwrap_or_else(|| { - TextDocumentContentChangeEvent { + Some( + content_change.unwrap_or_else(|| TextDocumentContentChangeEvent { range: None, range_length: None, text: self.get_document(), - } - })) + }), + ) } pub fn get_document(&self) -> String {