@@ -9,6 +9,7 @@ use std::str::FromStr;
99use std::sync::Arc;
1010
1111use helix_core::{
12+ encoding,
1213 history::History,
1314 indent::{auto_detect_indent_style, IndentStyle},
1415 line_ending::auto_detect_line_ending,
@@ -74,7 +75,7 @@ pub struct Document {
7475 pub(crate) selections: HashMap<ViewId, Selection>,
7576
7677 path: Option<PathBuf>,
77− encoding: &'static encoding_rs::Encoding,
78+ encoding: &'static encoding::Encoding,
7879
7980 /// Current editing mode.
8081 pub mode: Mode,
@@ -143,8 +144,8 @@ impl fmt::Debug for Document {
143144/// be used to override encoding auto-detection.
144145pub fn from_reader<R: std::io::Read + ?Sized>(
145146 reader: &mut R,
146− encoding: Option<&'static encoding_rs::Encoding>,
147−) -> Result<(Rope, &'static encoding_rs::Encoding), Error> {
147+ encoding: Option<&'static encoding::Encoding>,
148+) -> Result<(Rope, &'static encoding::Encoding), Error> {
148149 // These two buffers are 8192 bytes in size each and are used as
149150 // intermediaries during the decoding process. Text read into `buf`
150151 // from `reader` is decoded into `buf_out` as UTF-8. Once either
@@ -212,11 +213,11 @@ pub fn from_reader<R: std::io::Read + ?Sized>(
212213 total_read += read;
213214 total_written += written;
214215 match result {
215− encoding_rs::CoderResult::InputEmpty => {
216+ encoding::CoderResult::InputEmpty => {
216217 debug_assert_eq!(slice.len(), total_read);
217218 break;
218219 }
219− encoding_rs::CoderResult::OutputFull => {
220+ encoding::CoderResult::OutputFull => {
220221 debug_assert!(slice.len() > total_read);
221222 builder.append(&buf_str[..total_written]);
222223 total_written = 0;
@@ -251,7 +252,7 @@ pub fn from_reader<R: std::io::Read + ?Sized>(
251252/// replacement characters may appear in the encoded text.
252253pub async fn to_writer<'a, W: tokio::io::AsyncWriteExt + Unpin + ?Sized>(
253254 writer: &'a mut W,
254− encoding: &'static encoding_rs::Encoding,
255+ encoding: &'static encoding::Encoding,
255256 rope: &'a Rope,
256257) -> Result<(), Error> {
257258 // Text inside a `Rope` is stored as non-contiguous blocks of data called
@@ -286,12 +287,12 @@ pub async fn to_writer<'a, W: tokio::io::AsyncWriteExt + Unpin + ?Sized>(
286287 total_read += read;
287288 total_written += written;
288289 match result {
289− encoding_rs::CoderResult::InputEmpty => {
290+ encoding::CoderResult::InputEmpty => {
290291 debug_assert_eq!(chunk.len(), total_read);
291292 debug_assert!(buf.len() >= total_written);
292293 break;
293294 }
294− encoding_rs::CoderResult::OutputFull => {
295+ encoding::CoderResult::OutputFull => {
295296 debug_assert!(chunk.len() > total_read);
296297 writer.write_all(&buf[..total_written]).await?;
297298 total_written = 0;
@@ -322,8 +323,8 @@ use helix_lsp::lsp;
322323use url::Url;
323324
324325impl Document {
325− pub fn from(text: Rope, encoding: Option<&'static encoding_rs::Encoding>) -> Self {
326− let encoding = encoding.unwrap_or(encoding_rs::UTF_8);
326+ pub fn from(text: Rope, encoding: Option<&'static encoding::Encoding>) -> Self {
327+ let encoding = encoding.unwrap_or(encoding::UTF_8);
327328 let changes = ChangeSet::new(&text);
328329 let old_state = None;
329330
@@ -356,7 +357,7 @@ impl Document {
356357 /// overwritten with the `encoding` parameter.
357358 pub fn open(
358359 path: &Path,
359− encoding: Option<&'static encoding_rs::Encoding>,
360+ encoding: Option<&'static encoding::Encoding>,
360361 theme: Option<&Theme>,
361362 config_loader: Option<&syntax::Loader>,
362363 ) -> Result<Self, Error> {
@@ -366,7 +367,7 @@ impl Document {
366367 std::fs::File::open(path).context(format!("unable to open {:?}", path))?;
367368 from_reader(&mut file, encoding)?
368369 } else {
369− let encoding = encoding.unwrap_or(encoding_rs::UTF_8);
370+ let encoding = encoding.unwrap_or(encoding::UTF_8);
370371 (Rope::from(DEFAULT_LINE_ENDING.as_str()), encoding)
371372 };
372373
@@ -548,7 +549,7 @@ impl Document {
548549
549550 /// Sets the [`Document`]'s encoding with the encoding correspondent to `label`.
550551 pub fn set_encoding(&mut self, label: &str) -> Result<(), Error> {
551− match encoding_rs::Encoding::for_label(label.as_bytes()) {
552+ match encoding::Encoding::for_label(label.as_bytes()) {
552553 Some(encoding) => self.encoding = encoding,
553554 None => return Err(anyhow::anyhow!("unknown encoding")),
554555 }
@@ -556,7 +557,7 @@ impl Document {
556557 }
557558
558559 /// Returns the [`Document`]'s current encoding.
559− pub fn encoding(&self) -> &'static encoding_rs::Encoding {
560+ pub fn encoding(&self) -> &'static encoding::Encoding {
560561 self.encoding
561562 }
562563
@@ -1123,7 +1124,7 @@ mod test {
11231124
11241125 macro_rules! test_decode {
11251126 ($label:expr, $label_override:expr) => {
1126− let encoding = encoding_rs::Encoding::for_label($label_override.as_bytes()).unwrap();
1127+ let encoding = encoding::Encoding::for_label($label_override.as_bytes()).unwrap();
11271128 let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/encoding");
11281129 let path = base_path.join(format!("{}_in.txt", $label));
11291130 let ref_path = base_path.join(format!("{}_in_ref.txt", $label));
@@ -1142,7 +1143,7 @@ mod test {
11421143
11431144 macro_rules! test_encode {
11441145 ($label:expr, $label_override:expr) => {
1145− let encoding = encoding_rs::Encoding::for_label($label_override.as_bytes()).unwrap();
1146+ let encoding = encoding::Encoding::for_label($label_override.as_bytes()).unwrap();
11461147 let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/encoding");
11471148 let path = base_path.join(format!("{}_out.txt", $label));
11481149 let ref_path = base_path.join(format!("{}_out_ref.txt", $label));