From f3093b1266cb3473630c3805e7ae01f8507cbb26 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Fri, 1 Dec 2023 16:41:27 +0800 Subject: [PATCH] fix: follow up dprint issue --- crates/ruff_fmt_dprint/src/format_text.rs | 2 +- crates/ruff_fmt_dprint/src/wasm_plugin.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/ruff_fmt_dprint/src/format_text.rs b/crates/ruff_fmt_dprint/src/format_text.rs index 8ee8db2..b2f5bc4 100644 --- a/crates/ruff_fmt_dprint/src/format_text.rs +++ b/crates/ruff_fmt_dprint/src/format_text.rs @@ -9,7 +9,7 @@ pub fn format_text(text: &str, file_path: &Path, config: &Configuration) -> Form let config = config.clone().with_path(file_path.to_string_lossy().to_string()); format_module_source(text, config.into()) .map_err(|err| err.into()) - .map(|result| (result.as_code() != text).then_some(result.into_code())) + .map(|result| (result.as_code() != text).then_some(result.into_code().into_bytes())) } #[cfg(test)] diff --git a/crates/ruff_fmt_dprint/src/wasm_plugin.rs b/crates/ruff_fmt_dprint/src/wasm_plugin.rs index 8e7a982..5afeecb 100644 --- a/crates/ruff_fmt_dprint/src/wasm_plugin.rs +++ b/crates/ruff_fmt_dprint/src/wasm_plugin.rs @@ -1,5 +1,3 @@ -use std::path::Path; - use dprint_core::configuration::ConfigKeyMap; use dprint_core::configuration::GlobalConfiguration; use dprint_core::configuration::ResolveConfigurationResult; @@ -60,11 +58,11 @@ impl SyncPluginHandler for RuffFmtWasmPlugin { fn format( &mut self, file_path: &std::path::Path, - file_text: &str, + file_bytes: Vec, config: &Configuration, - mut _format_with_host: impl FnMut(&Path, String, &ConfigKeyMap) -> FormatResult, + _format_with_host: impl FnMut(&std::path::Path, Vec, &ConfigKeyMap) -> FormatResult, ) -> FormatResult { - format_text(file_text, file_path, config) + format_text(&String::from_utf8_lossy(&file_bytes), file_path, config) } }