@@ -9,6 +9,7 @@ use std::str::FromStr;
9use std::sync::Arc;
9use std::sync::Arc;
11use helix_core::{
11use helix_core::{
12 history::History,
13 history::History,
13 indent::{auto_detect_indent_style, IndentStyle},
14 indent::{auto_detect_indent_style, IndentStyle},
14 line_ending::auto_detect_line_ending,
15 line_ending::auto_detect_line_ending,
@@ -74,7 +75,7 @@ pub struct Document {
74 pub(crate) selections: HashMap<ViewId, Selection>,
75 pub(crate) selections: HashMap<ViewId, Selection>,
76 path: Option<PathBuf>,
77 path: Option<PathBuf>,
77− encoding: &'static encoding_rs::Encoding,
78+ encoding: &'static encoding::Encoding,
79 /// Current editing mode.
80 /// Current editing mode.
80 pub mode: Mode,
81 pub mode: Mode,
@@ -143,8 +144,8 @@ impl fmt::Debug for Document {
143/// be used to override encoding auto-detection.
144/// be used to override encoding auto-detection.
144pub fn from_reader<R: std::io::Read + ?Sized>(
145pub fn from_reader<R: std::io::Read + ?Sized>(
145 reader: &mut R,
146 reader: &mut R,
146− encoding: Option<&'static encoding_rs::Encoding>,
147+ encoding: Option<&'static encoding::Encoding>,
147−) -> Result<(Rope, &'static encoding_rs::Encoding), Error> {
148+) -> Result<(Rope, &'static encoding::Encoding), Error> {
148 // These two buffers are 8192 bytes in size each and are used as
149 // These two buffers are 8192 bytes in size each and are used as
149 // intermediaries during the decoding process. Text read into `buf`
150 // intermediaries during the decoding process. Text read into `buf`
150 // from `reader` is decoded into `buf_out` as UTF-8. Once either
151 // 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>(
212 total_read += read;
213 total_read += read;
213 total_written += written;
214 total_written += written;
214 match result {
215 match result {
215− encoding_rs::CoderResult::InputEmpty => {
216+ encoding::CoderResult::InputEmpty => {
216 debug_assert_eq!(slice.len(), total_read);
217 debug_assert_eq!(slice.len(), total_read);
219− encoding_rs::CoderResult::OutputFull => {
220+ encoding::CoderResult::OutputFull => {
220 debug_assert!(slice.len() > total_read);
221 debug_assert!(slice.len() > total_read);
221 builder.append(&buf_str[..total_written]);
222 builder.append(&buf_str[..total_written]);
222 total_written = 0;
223 total_written = 0;
@@ -251,7 +252,7 @@ pub fn from_reader<R: std::io::Read + ?Sized>(
251/// replacement characters may appear in the encoded text.
252/// replacement characters may appear in the encoded text.
252pub async fn to_writer<'a, W: tokio::io::AsyncWriteExt + Unpin + ?Sized>(
253pub async fn to_writer<'a, W: tokio::io::AsyncWriteExt + Unpin + ?Sized>(
253 writer: &'a mut W,
254 writer: &'a mut W,
254− encoding: &'static encoding_rs::Encoding,
255+ encoding: &'static encoding::Encoding,
255 rope: &'a Rope,
256 rope: &'a Rope,
256) -> Result<(), Error> {
257) -> Result<(), Error> {
257 // Text inside a `Rope` is stored as non-contiguous blocks of data called
258 // 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>(
286 total_read += read;
287 total_read += read;
287 total_written += written;
288 total_written += written;
288 match result {
289 match result {
289− encoding_rs::CoderResult::InputEmpty => {
290+ encoding::CoderResult::InputEmpty => {
290 debug_assert_eq!(chunk.len(), total_read);
291 debug_assert_eq!(chunk.len(), total_read);
291 debug_assert!(buf.len() >= total_written);
292 debug_assert!(buf.len() >= total_written);
294− encoding_rs::CoderResult::OutputFull => {
295+ encoding::CoderResult::OutputFull => {
295 debug_assert!(chunk.len() > total_read);
296 debug_assert!(chunk.len() > total_read);
296 writer.write_all(&buf[..total_written]).await?;
297 writer.write_all(&buf[..total_written]).await?;
297 total_written = 0;
298 total_written = 0;
@@ -322,8 +323,8 @@ use helix_lsp::lsp;
322use url::Url;
323use url::Url;
324impl Document {
325impl Document {
325− pub fn from(text: Rope, encoding: Option<&'static encoding_rs::Encoding>) -> Self {
326+ pub fn from(text: Rope, encoding: Option<&'static encoding::Encoding>) -> Self {
326− let encoding = encoding.unwrap_or(encoding_rs::UTF_8);
327+ let encoding = encoding.unwrap_or(encoding::UTF_8);
327 let changes = ChangeSet::new(&text);
328 let changes = ChangeSet::new(&text);
328 let old_state = None;
329 let old_state = None;
@@ -356,7 +357,7 @@ impl Document {
356 /// overwritten with the `encoding` parameter.
357 /// overwritten with the `encoding` parameter.
357 pub fn open(
358 pub fn open(
358 path: &Path,
359 path: &Path,
359− encoding: Option<&'static encoding_rs::Encoding>,
360+ encoding: Option<&'static encoding::Encoding>,
360 theme: Option<&Theme>,
361 theme: Option<&Theme>,
361 config_loader: Option<&syntax::Loader>,
362 config_loader: Option<&syntax::Loader>,
362 ) -> Result<Self, Error> {
363 ) -> Result<Self, Error> {
@@ -366,7 +367,7 @@ impl Document {
366 std::fs::File::open(path).context(format!("unable to open {:?}", path))?;
367 std::fs::File::open(path).context(format!("unable to open {:?}", path))?;
367 from_reader(&mut file, encoding)?
368 from_reader(&mut file, encoding)?
369− let encoding = encoding.unwrap_or(encoding_rs::UTF_8);
370+ let encoding = encoding.unwrap_or(encoding::UTF_8);
370 (Rope::from(DEFAULT_LINE_ENDING.as_str()), encoding)
371 (Rope::from(DEFAULT_LINE_ENDING.as_str()), encoding)
@@ -548,7 +549,7 @@ impl Document {
549 /// Sets the [`Document`]'s encoding with the encoding correspondent to `label`.
550 /// Sets the [`Document`]'s encoding with the encoding correspondent to `label`.
550 pub fn set_encoding(&mut self, label: &str) -> Result<(), Error> {
551 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()) {
552 Some(encoding) => self.encoding = encoding,
553 Some(encoding) => self.encoding = encoding,
553 None => return Err(anyhow::anyhow!("unknown encoding")),
554 None => return Err(anyhow::anyhow!("unknown encoding")),
@@ -556,7 +557,7 @@ impl Document {
558 /// Returns the [`Document`]'s current encoding.
559 /// Returns the [`Document`]'s current encoding.
559− pub fn encoding(&self) -> &'static encoding_rs::Encoding {
560+ pub fn encoding(&self) -> &'static encoding::Encoding {
560 self.encoding
561 self.encoding
@@ -1123,7 +1124,7 @@ mod test {
1124 macro_rules! test_decode {
1125 macro_rules! test_decode {
1125 ($label:expr, $label_override:expr) => {
1126 ($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();
1127 let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/encoding");
1128 let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/encoding");
1128 let path = base_path.join(format!("{}_in.txt", $label));
1129 let path = base_path.join(format!("{}_in.txt", $label));
1129 let ref_path = base_path.join(format!("{}_in_ref.txt", $label));
1130 let ref_path = base_path.join(format!("{}_in_ref.txt", $label));
@@ -1142,7 +1143,7 @@ mod test {
1143 macro_rules! test_encode {
1144 macro_rules! test_encode {
1144 ($label:expr, $label_override:expr) => {
1145 ($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();
1146 let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/encoding");
1147 let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/encoding");
1147 let path = base_path.join(format!("{}_out.txt", $label));
1148 let path = base_path.join(format!("{}_out.txt", $label));
1148 let ref_path = base_path.join(format!("{}_out_ref.txt", $label));
1149 let ref_path = base_path.join(format!("{}_out_ref.txt", $label));