@@ -22,7 +22,7 @@ use clock::Lamport;
pub use clock::ReplicaId;
use collections::HashMap;
use encoding_rs::Encoding;
-use fs::MTime;
+use fs::{MTime, encodings::EncodingWrapper};
use futures::channel::oneshot;
use gpui::{
App, AppContext as _, BackgroundExecutor, Context, Entity, EventEmitter, HighlightStyle,
@@ -414,7 +414,8 @@ pub trait LocalFile: File {
fn abs_path(&self, cx: &App) -> PathBuf;
/// Loads the file contents from disk and returns them as a UTF-8 encoded string.
- fn load(&self, cx: &App) -> Task<Result<String>>;
+ fn load(&self, cx: &App, encoding: EncodingWrapper, detect_utf16: bool)
+ -> Task<Result<String>>;
/// Loads the file's contents from disk.
fn load_bytes(&self, cx: &App) -> Task<Result<Vec<u8>>>;
@@ -1344,12 +1345,15 @@ impl Buffer {
/// Reloads the contents of the buffer from disk.
pub fn reload(&mut self, cx: &Context<Self>) -> oneshot::Receiver<Option<Transaction>> {
let (tx, rx) = futures::channel::oneshot::channel();
+ let encoding = EncodingWrapper::new(*(self.encoding.lock().unwrap()));
let prev_version = self.text.version();
self.reload_task = Some(cx.spawn(async move |this, cx| {
let Some((new_mtime, new_text)) = this.update(cx, |this, cx| {
let file = this.file.as_ref()?.as_local()?;
- Some((file.disk_state().mtime(), { file.load(cx) }))
+ Some((file.disk_state().mtime(), {
+ file.load(cx, encoding, false)
+ }))
})?
else {
return Ok(());
@@ -5223,7 +5227,12 @@ impl LocalFile for TestFile {
.join(self.path.as_std_path())
}
- fn load(&self, _cx: &App) -> Task<Result<String>> {
+ fn load(
+ &self,
+ _cx: &App,
+ _encoding: EncodingWrapper,
+ _detect_utf16: bool,
+ ) -> Task<Result<String>> {
unimplemented!()
}
@@ -3115,11 +3115,19 @@ impl language::LocalFile for File {
self.worktree.read(cx).absolutize(&self.path)
}
- fn load(&self, cx: &App) -> Task<Result<String>> {
+ fn load(
+ &self,
+ cx: &App,
+ encoding: EncodingWrapper,
+ detect_utf16: bool,
+ ) -> Task<Result<String>> {
let worktree = self.worktree.read(cx).as_local().unwrap();
let abs_path = worktree.absolutize(&self.path);
let fs = worktree.fs.clone();
- cx.background_spawn(async move { fs.load(&abs_path).await })
+ cx.background_spawn(async move {
+ fs.load_with_encoding(&abs_path?, encoding, detect_utf16)
+ .await
+ })
}
fn load_bytes(&self, cx: &App) -> Task<Result<Vec<u8>>> {