fix: immediate exprs
This commit is contained in:
1 parent
1737c55575
commit
b6e4db1f2f
4 files changed
+14
-8
No files matched your search
@@ -16,11 +16,8 @@ impl Writer<'_> {
|
|||||||
|
|
||||||
// if the expr is on one line, just write it directly
|
// if the expr is on one line, just write it directly
|
||||||
if start.line == end.line {
|
if start.line == end.line {
|
||||||
write!(
|
let row = &self.src[start.line - 1][start.column..end.column].trim();
|
||||||
self.out,
|
write!(self.out, "{}", row)?;
|
||||||
"{}",
|
|
||||||
&self.src[start.line - 1][start.column - 1..end.column].trim()
|
|
||||||
)?;
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::writer::*;
|
use crate::writer::*;
|
||||||
use collect_macros::byte_offset;
|
use collect_macros::byte_offset;
|
||||||
use dioxus_rsx::CallBody;
|
use dioxus_rsx::{BodyNode, CallBody};
|
||||||
use proc_macro2::LineColumn;
|
use proc_macro2::LineColumn;
|
||||||
use syn::{ExprMacro, MacroDelimiter};
|
use syn::{ExprMacro, MacroDelimiter};
|
||||||
|
|
||||||
@@ -105,7 +105,11 @@ pub fn fmt_file(contents: &str) -> Vec<FormattedBlock> {
|
|||||||
let start = byte_offset(contents, span.start()) + 1;
|
let start = byte_offset(contents, span.start()) + 1;
|
||||||
let end = byte_offset(contents, span.end()) - 1;
|
let end = byte_offset(contents, span.end()) - 1;
|
||||||
|
|
||||||
if formatted.len() <= 80 && !formatted.contains('\n') {
|
// Rustfmt will remove the space between the macro and the opening paren if the macro is a single expression
|
||||||
|
let body_is_solo_expr =
|
||||||
|
body.roots.len() == 1 && matches!(body.roots[0], BodyNode::RawExpr(_));
|
||||||
|
|
||||||
|
if formatted.len() <= 80 && !formatted.contains('\n') && !body_is_solo_expr {
|
||||||
formatted = format!(" {} ", formatted);
|
formatted = format!(" {} ", formatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,5 +37,6 @@ twoway![
|
|||||||
long_exprs,
|
long_exprs,
|
||||||
ifchain_forloop,
|
ifchain_forloop,
|
||||||
t2,
|
t2,
|
||||||
reallylong
|
reallylong,
|
||||||
|
immediate_expr
|
||||||
];
|
];
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fn it_works() {
|
||||||
|
cx.render(rsx!(()))
|
||||||
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user