From f23c768204b7347744cbb8250e7097c9f1c799f1 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Wed, 14 Feb 2024 22:36:03 +0500 Subject: [PATCH] fmt: Fix no whitespace after function return_type --- tools/lsp/fmt/fmt.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/lsp/fmt/fmt.rs b/tools/lsp/fmt/fmt.rs index e4c7021d115..586a8eca7ea 100644 --- a/tools/lsp/fmt/fmt.rs +++ b/tools/lsp/fmt/fmt.rs @@ -605,8 +605,13 @@ fn format_codeblock( // empty CodeBlock happens when there is no `else` for example return Ok(()); } + + let prev_is_return_type = + node.prev_sibling().map(|s| s.kind() == SyntaxKind::ReturnType).unwrap_or(false); + let mut sub = node.children_with_tokens(); - if !whitespace_to(&mut sub, SyntaxKind::LBrace, writer, state, "")? { + let prefix_whitespace = if prev_is_return_type { " " } else { "" }; + if !whitespace_to(&mut sub, SyntaxKind::LBrace, writer, state, prefix_whitespace)? { finish_node(sub, writer, state)?; return Ok(()); } @@ -1193,7 +1198,7 @@ component ABC { r#" component ABC { in-out property logged_in: false; - function clicked() -> bool{ + function clicked() -> bool { if (logged_in) { logged_in = false; return true;