From 7cbfdfac0f15cc5e964fba69664c1c79dfac59a2 Mon Sep 17 00:00:00 2001 From: mridulTripathi Date: Sun, 24 Aug 2025 14:50:57 +0530 Subject: [PATCH 1/4] fix: resolve Arc and WASM thread safety issues - Fix Arc thread safety issues with proper Send+Sync bounds in lsp-async-stub - Fix WASM thread safety issues with proper Send+Sync implementations This commit contains ONLY the essential Arc/WASM thread safety fixes requested for merge. --- crates/lsp-async-stub/src/lib.rs | 4 ++-- crates/taplo-wasm/src/lsp.rs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/lsp-async-stub/src/lib.rs b/crates/lsp-async-stub/src/lib.rs index b484904e7..30b3f5019 100644 --- a/crates/lsp-async-stub/src/lib.rs +++ b/crates/lsp-async-stub/src/lib.rs @@ -269,8 +269,8 @@ impl RequestWriter for Context { } } -pub trait MessageWriter: Sink + Unpin {} -impl + Unpin> MessageWriter for T {} +pub trait MessageWriter: Sink + Unpin + Send + Sync {} +impl + Unpin + Send + Sync> MessageWriter for T {} struct Inner { next_request_id: i32, diff --git a/crates/taplo-wasm/src/lsp.rs b/crates/taplo-wasm/src/lsp.rs index 86eb5b768..91f125cb8 100644 --- a/crates/taplo-wasm/src/lsp.rs +++ b/crates/taplo-wasm/src/lsp.rs @@ -38,6 +38,10 @@ pub(crate) struct WasmLspInterface { js_on_message: Function, } +// SAFETY: This is safe because WASM is single-threaded +unsafe impl Send for WasmLspInterface {} +unsafe impl Sync for WasmLspInterface {} + impl From for WasmLspInterface { fn from(val: JsValue) -> Self { Self { From 6c06f11fd9c79327f082cba552192a86eb8d604a Mon Sep 17 00:00:00 2001 From: mridulTripathi Date: Sun, 24 Aug 2025 14:51:07 +0530 Subject: [PATCH 2/4] refactor: remove unused methods and traits - Remove unused method() from Handler trait in lsp-async-stub - Remove unused syntax() method from FormattedItem trait - Clean up trait implementations and improve code organization --- crates/lsp-async-stub/src/handler.rs | 10 ---------- crates/taplo/src/formatter/mod.rs | 15 +++------------ 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/crates/lsp-async-stub/src/handler.rs b/crates/lsp-async-stub/src/handler.rs index 45f4fafb3..8c31430d4 100644 --- a/crates/lsp-async-stub/src/handler.rs +++ b/crates/lsp-async-stub/src/handler.rs @@ -8,8 +8,6 @@ use std::marker::PhantomData; #[async_trait(?Send)] pub(crate) trait Handler { - fn method(&self) -> &'static str; - async fn handle( &mut self, context: Context, @@ -72,10 +70,6 @@ where F: Future> + 'static, W: Clone + 'static, { - fn method(&self) -> &'static str { - R::METHOD - } - async fn handle( &mut self, context: Context, @@ -160,10 +154,6 @@ where F: Future + 'static, W: Clone + 'static, { - fn method(&self) -> &'static str { - N::METHOD - } - async fn handle( &mut self, context: Context, diff --git a/crates/taplo/src/formatter/mod.rs b/crates/taplo/src/formatter/mod.rs index d5565c869..0ace61933 100644 --- a/crates/taplo/src/formatter/mod.rs +++ b/crates/taplo/src/formatter/mod.rs @@ -138,10 +138,10 @@ impl core::fmt::Display for OptionParseError { "invalid formatting option: {}", match self { OptionParseError::InvalidOption(k) => { - format!(r#"invalid option "{}""#, k) + format!(r#"invalid option "{k}""#) } OptionParseError::InvalidValue { key, error } => { - format!(r#"invalid value for option "{}": {}"#, key, error) + format!(r#"invalid value for option "{key}": {error}"#) } } ) @@ -418,10 +418,6 @@ impl FormattedItem for FormattedEntry { fn trailing_comment(&self) -> Option { self.comment.clone() } - - fn syntax(&self) -> SyntaxElement { - self.syntax.clone() - } } fn format_root(node: SyntaxNode, options: &Options, context: &Context) -> String { @@ -1194,7 +1190,7 @@ fn format_table_header( } // Simply a tuple of the formatted item and an optional trailing comment. -impl> FormattedItem for (SyntaxElement, T, Option) { +impl + Clone> FormattedItem for (SyntaxElement, T, Option) { fn write_to(&self, formatted: &mut String, _options: &Options) { *formatted += self.1.as_ref() } @@ -1202,14 +1198,9 @@ impl> FormattedItem for (SyntaxElement, T, Option) { fn trailing_comment(&self) -> Option { self.2.as_ref().map(|s| s.as_ref().to_string()) } - - fn syntax(&self) -> SyntaxElement { - self.0.clone() - } } trait FormattedItem { - fn syntax(&self) -> SyntaxElement; #[allow(clippy::ptr_arg)] fn write_to(&self, formatted: &mut String, options: &Options); fn trailing_comment(&self) -> Option; From bda8683f286be6e14a3b1f55881786296b8349fb Mon Sep 17 00:00:00 2001 From: mridulTripathi Date: Sun, 24 Aug 2025 14:51:19 +0530 Subject: [PATCH 3/4] style: modernize format strings to use inline syntax - Update format strings to use modern Rust inline syntax (e.g., {variable}) - Apply consistent formatting across taplo, taplo-cli, and formatter modules - Improve readability and follow Rust best practices --- crates/taplo-cli/src/commands/format.rs | 2 +- crates/taplo-wasm/src/environment.rs | 14 +++++--------- crates/taplo/src/dom/to_toml.rs | 4 ++-- crates/taplo/src/tests/mod.rs | 4 ++-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/crates/taplo-cli/src/commands/format.rs b/crates/taplo-cli/src/commands/format.rs index 0407f1e84..792635569 100644 --- a/crates/taplo-cli/src/commands/format.rs +++ b/crates/taplo-cli/src/commands/format.rs @@ -260,7 +260,7 @@ impl Taplo { self.env .stderr() .write_all( - format!("Failed to write diff to stdout: {:?}", e) + format!("Failed to write diff to stdout: {e:?}") .as_str() .as_bytes(), ) diff --git a/crates/taplo-wasm/src/environment.rs b/crates/taplo-wasm/src/environment.rs index da40f90dc..04670afef 100644 --- a/crates/taplo-wasm/src/environment.rs +++ b/crates/taplo-wasm/src/environment.rs @@ -36,10 +36,7 @@ impl AsyncRead for JsAsyncRead { let ret: JsValue = match self.f.call1(&this, &JsValue::from(buf.remaining())) { Ok(val) => val, Err(error) => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::Other, - format!("{:?}", error), - ))); + return Poll::Ready(Err(io::Error::other(format!("{error:?}")))); } }; @@ -58,7 +55,7 @@ impl AsyncRead for JsAsyncRead { Ok(()) } - Err(err) => Err(io::Error::new(io::ErrorKind::Other, format!("{:?}", err))), + Err(err) => Err(io::Error::other(format!("{err:?}"))), }; self.fut = None; @@ -96,9 +93,8 @@ impl AsyncWrite for JsAsyncWrite { let ret: JsValue = match self.f.call1(&this, &Uint8Array::from(buf).into()) { Ok(val) => val, Err(error) => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::Other, - format!("{:?}", error), + return Poll::Ready(Err(io::Error::other( + format!("{error:?}"), ))); } }; @@ -114,7 +110,7 @@ impl AsyncWrite for JsAsyncWrite { let n = num_written.as_f64().unwrap_or(0.0).floor() as usize; Ok(n) } - Err(err) => Err(io::Error::new(io::ErrorKind::Other, format!("{:?}", err))), + Err(err) => Err(io::Error::other(format!("{err:?}"))), }; self.fut = None; diff --git a/crates/taplo/src/dom/to_toml.rs b/crates/taplo/src/dom/to_toml.rs index 7b3e60ba6..fa5b0d728 100644 --- a/crates/taplo/src/dom/to_toml.rs +++ b/crates/taplo/src/dom/to_toml.rs @@ -41,7 +41,7 @@ impl Node { // Use the original representation of primitives if available. if let Some(syntax) = self.syntax() { - return write!(f, "{}", syntax); + return write!(f, "{syntax}"); } } @@ -153,7 +153,7 @@ impl Node { Node::Bool(b) => write!(f, "{}", b.value())?, Node::Str(s) => { if let Some(syntax) = s.syntax() { - write!(f, "{}", syntax)?; + write!(f, "{syntax}")?; } else { let escaped = escape(s.value()); diff --git a/crates/taplo/src/tests/mod.rs b/crates/taplo/src/tests/mod.rs index 4511e7944..3c4d12f2a 100644 --- a/crates/taplo/src/tests/mod.rs +++ b/crates/taplo/src/tests/mod.rs @@ -14,7 +14,7 @@ fn time_in_arrays() { let errors = parse(src).errors; - assert!(errors.is_empty(), "{:#?}", errors); + assert!(errors.is_empty(), "{errors:#?}"); } #[test] @@ -25,5 +25,5 @@ fn comments_after_tables() { "#; let errors = parse(src).errors; - assert!(errors.is_empty(), "{:#?}", errors); + assert!(errors.is_empty(), "{errors:#?}"); } From cabd0683dfbf92d7ad7e699cb1d11b5802524b72 Mon Sep 17 00:00:00 2001 From: mridulTripathi Date: Sun, 24 Aug 2025 14:51:27 +0530 Subject: [PATCH 4/4] fix: add missing semicolons in VSCode extension - Fix missing semicolons in comment.ts syntax definitions - Ensure proper TypeScript syntax compliance --- editors/vscode/src/syntax/comment.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editors/vscode/src/syntax/comment.ts b/editors/vscode/src/syntax/comment.ts index d10bbab04..cbc32fba9 100644 --- a/editors/vscode/src/syntax/comment.ts +++ b/editors/vscode/src/syntax/comment.ts @@ -9,7 +9,7 @@ export const comment = { }, comment: 'Comments', match: '\\s*((#).*)$', -} +}; export const commentDirective = { captures: { @@ -22,5 +22,5 @@ export const commentDirective = { }, comment: 'Comments', match: '\\s*((#):.*)$', -} +};