@ -9,6 +9,7 @@ use std::str::FromStr;
use std ::sync ::Arc ;
use std ::sync ::Arc ;
use helix_core ::{
use helix_core ::{
encoding ,
history ::History ,
history ::History ,
indent ::{ auto_detect_indent_style , IndentStyle } ,
indent ::{ auto_detect_indent_style , IndentStyle } ,
line_ending ::auto_detect_line_ending ,
line_ending ::auto_detect_line_ending ,
@ -74,7 +75,7 @@ pub struct Document {
pub ( crate ) selections : HashMap < ViewId , Selection > ,
pub ( crate ) selections : HashMap < ViewId , Selection > ,
path : Option < PathBuf > ,
path : Option < PathBuf > ,
encoding : & ' static encoding _rs ::Encoding ,
encoding : & ' static encoding ::Encoding ,
/// Current editing mode.
/// Current editing mode.
pub mode : Mode ,
pub mode : Mode ,
@ -143,8 +144,8 @@ impl fmt::Debug for Document {
/// be used to override encoding auto-detection.
/// be used to override encoding auto-detection.
pub fn from_reader < R : std ::io ::Read + ? Sized > (
pub fn from_reader < R : std ::io ::Read + ? Sized > (
reader : & mut R ,
reader : & mut R ,
encoding : Option < & ' static encoding _rs ::Encoding > ,
encoding : Option < & ' static encoding ::Encoding > ,
) -> Result < ( Rope , & ' static encoding _rs ::Encoding ) , Error > {
) -> Result < ( Rope , & ' static encoding ::Encoding ) , Error > {
// These two buffers are 8192 bytes in size each and are used as
// These two buffers are 8192 bytes in size each and are used as
// intermediaries during the decoding process. Text read into `buf`
// intermediaries during the decoding process. Text read into `buf`
// from `reader` is decoded into `buf_out` as UTF-8. Once either
// 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>(
total_read + = read ;
total_read + = read ;
total_written + = written ;
total_written + = written ;
match result {
match result {
encoding _rs ::CoderResult ::InputEmpty = > {
encoding ::CoderResult ::InputEmpty = > {
debug_assert_eq! ( slice . len ( ) , total_read ) ;
debug_assert_eq! ( slice . len ( ) , total_read ) ;
break ;
break ;
}
}
encoding _rs ::CoderResult ::OutputFull = > {
encoding ::CoderResult ::OutputFull = > {
debug_assert! ( slice . len ( ) > total_read ) ;
debug_assert! ( slice . len ( ) > total_read ) ;
builder . append ( & buf_str [ .. total_written ] ) ;
builder . append ( & buf_str [ .. total_written ] ) ;
total_written = 0 ;
total_written = 0 ;
@ -251,7 +252,7 @@ pub fn from_reader<R: std::io::Read + ?Sized>(
/// replacement characters may appear in the encoded text.
/// replacement characters may appear in the encoded text.
pub async fn to_writer < ' a , W : tokio ::io ::AsyncWriteExt + Unpin + ? Sized > (
pub async fn to_writer < ' a , W : tokio ::io ::AsyncWriteExt + Unpin + ? Sized > (
writer : & ' a mut W ,
writer : & ' a mut W ,
encoding : & ' static encoding _rs ::Encoding ,
encoding : & ' static encoding ::Encoding ,
rope : & ' a Rope ,
rope : & ' a Rope ,
) -> Result < ( ) , Error > {
) -> Result < ( ) , Error > {
// Text inside a `Rope` is stored as non-contiguous blocks of data called
// 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>(
total_read + = read ;
total_read + = read ;
total_written + = written ;
total_written + = written ;
match result {
match result {
encoding _rs ::CoderResult ::InputEmpty = > {
encoding ::CoderResult ::InputEmpty = > {
debug_assert_eq! ( chunk . len ( ) , total_read ) ;
debug_assert_eq! ( chunk . len ( ) , total_read ) ;
debug_assert! ( buf . len ( ) > = total_written ) ;
debug_assert! ( buf . len ( ) > = total_written ) ;
break ;
break ;
}
}
encoding _rs ::CoderResult ::OutputFull = > {
encoding ::CoderResult ::OutputFull = > {
debug_assert! ( chunk . len ( ) > total_read ) ;
debug_assert! ( chunk . len ( ) > total_read ) ;
writer . write_all ( & buf [ .. total_written ] ) . await ? ;
writer . write_all ( & buf [ .. total_written ] ) . await ? ;
total_written = 0 ;
total_written = 0 ;
@ -322,8 +323,8 @@ use helix_lsp::lsp;
use url ::Url ;
use url ::Url ;
impl Document {
impl Document {
pub fn from ( text : Rope , encoding : Option < & ' static encoding _rs ::Encoding > ) -> Self {
pub fn from ( text : Rope , encoding : Option < & ' static encoding ::Encoding > ) -> Self {
let encoding = encoding . unwrap_or ( encoding _rs ::UTF_8 ) ;
let encoding = encoding . unwrap_or ( encoding ::UTF_8 ) ;
let changes = ChangeSet ::new ( & text ) ;
let changes = ChangeSet ::new ( & text ) ;
let old_state = None ;
let old_state = None ;
@ -356,7 +357,7 @@ impl Document {
/// overwritten with the `encoding` parameter.
/// overwritten with the `encoding` parameter.
pub fn open (
pub fn open (
path : & Path ,
path : & Path ,
encoding : Option < & ' static encoding _rs ::Encoding > ,
encoding : Option < & ' static encoding ::Encoding > ,
theme : Option < & Theme > ,
theme : Option < & Theme > ,
config_loader : Option < & syntax ::Loader > ,
config_loader : Option < & syntax ::Loader > ,
) -> Result < Self , Error > {
) -> Result < Self , Error > {
@ -366,7 +367,7 @@ impl Document {
std ::fs ::File ::open ( path ) . context ( format! ( "unable to open {:?}" , path ) ) ? ;
std ::fs ::File ::open ( path ) . context ( format! ( "unable to open {:?}" , path ) ) ? ;
from_reader ( & mut file , encoding ) ?
from_reader ( & mut file , encoding ) ?
} else {
} else {
let encoding = encoding . unwrap_or ( encoding _rs ::UTF_8 ) ;
let encoding = encoding . unwrap_or ( encoding ::UTF_8 ) ;
( Rope ::from ( DEFAULT_LINE_ENDING . as_str ( ) ) , encoding )
( Rope ::from ( DEFAULT_LINE_ENDING . as_str ( ) ) , encoding )
} ;
} ;
@ -548,7 +549,7 @@ impl Document {
/// Sets the [`Document`]'s encoding with the encoding correspondent to `label`.
/// Sets the [`Document`]'s encoding with the encoding correspondent to `label`.
pub fn set_encoding ( & mut self , label : & str ) -> Result < ( ) , Error > {
pub fn set_encoding ( & mut self , label : & str ) -> Result < ( ) , Error > {
match encoding _rs ::Encoding ::for_label ( label . as_bytes ( ) ) {
match encoding ::Encoding ::for_label ( label . as_bytes ( ) ) {
Some ( encoding ) = > self . encoding = encoding ,
Some ( encoding ) = > self . encoding = encoding ,
None = > return Err ( anyhow ::anyhow ! ( "unknown encoding" ) ) ,
None = > return Err ( anyhow ::anyhow ! ( "unknown encoding" ) ) ,
}
}
@ -556,7 +557,7 @@ impl Document {
}
}
/// Returns the [`Document`]'s current encoding.
/// Returns the [`Document`]'s current encoding.
pub fn encoding ( & self ) -> & ' static encoding _rs ::Encoding {
pub fn encoding ( & self ) -> & ' static encoding ::Encoding {
self . encoding
self . encoding
}
}
@ -1123,7 +1124,7 @@ mod test {
macro_rules! test_decode {
macro_rules! test_decode {
( $label :expr , $label_override :expr ) = > {
( $label :expr , $label_override :expr ) = > {
let encoding = encoding _rs ::Encoding ::for_label ( $label_override . as_bytes ( ) ) . unwrap ( ) ;
let encoding = encoding ::Encoding ::for_label ( $label_override . as_bytes ( ) ) . unwrap ( ) ;
let base_path = PathBuf ::from ( env! ( "CARGO_MANIFEST_DIR" ) ) . join ( "tests/encoding" ) ;
let base_path = PathBuf ::from ( env! ( "CARGO_MANIFEST_DIR" ) ) . join ( "tests/encoding" ) ;
let path = base_path . join ( format! ( "{}_in.txt" , $label ) ) ;
let path = base_path . join ( format! ( "{}_in.txt" , $label ) ) ;
let ref_path = base_path . join ( format! ( "{}_in_ref.txt" , $label ) ) ;
let ref_path = base_path . join ( format! ( "{}_in_ref.txt" , $label ) ) ;
@ -1142,7 +1143,7 @@ mod test {
macro_rules! test_encode {
macro_rules! test_encode {
( $label :expr , $label_override :expr ) = > {
( $label :expr , $label_override :expr ) = > {
let encoding = encoding _rs ::Encoding ::for_label ( $label_override . as_bytes ( ) ) . unwrap ( ) ;
let encoding = encoding ::Encoding ::for_label ( $label_override . as_bytes ( ) ) . unwrap ( ) ;
let base_path = PathBuf ::from ( env! ( "CARGO_MANIFEST_DIR" ) ) . join ( "tests/encoding" ) ;
let base_path = PathBuf ::from ( env! ( "CARGO_MANIFEST_DIR" ) ) . join ( "tests/encoding" ) ;
let path = base_path . join ( format! ( "{}_out.txt" , $label ) ) ;
let path = base_path . join ( format! ( "{}_out.txt" , $label ) ) ;
let ref_path = base_path . join ( format! ( "{}_out_ref.txt" , $label ) ) ;
let ref_path = base_path . join ( format! ( "{}_out_ref.txt" , $label ) ) ;