Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
panekj committed May 20, 2024
1 parent 6c05d62 commit 6f97ac3
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions lapce-proxy/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,43 +110,44 @@ impl Buffer {
.truncate(true)
.open(&path)?;

match self.encoding.as_str() {
"UTF-8" => {
for chunk in self.rope.iter_chunks(..self.rope.len()) {
f.write_all(chunk.as_bytes())?;
}
match self.encoding.as_str() {
"UTF-8" => {
for chunk in self.rope.iter_chunks(..self.rope.len()) {
f.write_all(chunk.as_bytes())?;
}
v => {
use encoding_rs::CoderResult;

let Some(enc) = Encoding::for_label(v.as_bytes()) else {
bail!("Failed to obtain valid encoding to use for saving file");
};
let mut encoder = enc.new_encoder();

let mut buf = vec![];
let mut last = false;
let mut i = 0;
for chunk in self.rope.iter_chunks(..self.rope.len()) {
i += chunk.len();
if i >= self.rope.len() {
last = true
}
let (result, units, replaced) = encoder.encode_from_utf8_to_vec(chunk, &mut buf, last);
trace!("{units} processed");
if replaced {
warn!("replacement occured in `{chunk}`");
}
match result {
CoderResult::InputEmpty => match last {
true => f.write_all(buf.as_slice())?,
false => continue,
},
CoderResult::OutputFull => f.write_all(buf.as_slice())?,
}
}
v => {
use encoding_rs::CoderResult;

let Some(enc) = Encoding::for_label(v.as_bytes()) else {
bail!("Failed to obtain valid encoding to use for saving file");
};
let mut encoder = enc.new_encoder();

let mut buf = vec![];
let mut last = false;
let mut i = 0;
for chunk in self.rope.iter_chunks(..self.rope.len()) {
i += chunk.len();
if i >= self.rope.len() {
last = true
}
let (result, units, replaced) =
encoder.encode_from_utf8_to_vec(chunk, &mut buf, last);
trace!("{units} processed");
if replaced {
warn!("replacement occured in `{chunk}`");
}
match result {
CoderResult::InputEmpty => match last {
true => f.write_all(buf.as_slice())?,
false => continue,
},
CoderResult::OutputFull => f.write_all(buf.as_slice())?,
}
}
}
}

self.mod_time = get_mod_time(&path);
if !new_file {
Expand Down

0 comments on commit 6f97ac3

Please sign in to comment.