diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 9c094530b16efc6438be04382f116e11cb65018b..029619a4ad7cc697c0d5625c706f3a573b07ae12 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -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>; + fn load(&self, cx: &App, encoding: EncodingWrapper, detect_utf16: bool) + -> Task>; /// Loads the file's contents from disk. fn load_bytes(&self, cx: &App) -> Task>>; @@ -1344,12 +1345,15 @@ impl Buffer { /// Reloads the contents of the buffer from disk. pub fn reload(&mut self, cx: &Context) -> oneshot::Receiver> { 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> { + fn load( + &self, + _cx: &App, + _encoding: EncodingWrapper, + _detect_utf16: bool, + ) -> Task> { unimplemented!() } diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index c1061f40ab0ee6ecea202db334bb4cac24901f30..4b69787acf9c045c5d330a7a292101bdcac46751 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -3115,11 +3115,19 @@ impl language::LocalFile for File { self.worktree.read(cx).absolutize(&self.path) } - fn load(&self, cx: &App) -> Task> { + fn load( + &self, + cx: &App, + encoding: EncodingWrapper, + detect_utf16: bool, + ) -> Task> { 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>> {