summaryrefslogtreecommitdiff
path: root/src/types
diff options
context:
space:
mode:
authorPolesznyák Márk <contact@pml68.dev>2025-09-22 20:27:20 +0200
committerPolesznyák Márk <contact@pml68.dev>2025-09-22 20:27:20 +0200
commit5316c53b1fe82f5dc75bf575a39ef5f3a7c8d995 (patch)
tree8d4a7c4e8bac2343034c6ae78fbd5ce8fbc7dc4d /src/types
parentfeat(wip): iced_material based code highlighting (diff)
downloadiced-builder-5316c53b1fe82f5dc75bf575a39ef5f3a7c8d995.tar.gz
feat: switch to `prettyplease` for code formatting
No more external rustfmt dependency
Diffstat (limited to 'src/types')
-rw-r--r--src/types/project.rs30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/types/project.rs b/src/types/project.rs
index 13f84eb..ceb4f84 100644
--- a/src/types/project.rs
+++ b/src/types/project.rs
@@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
extern crate fxhash;
use iced::Theme;
-use rust_format::{Edition, Formatter, RustFmt};
+use rust_format::{Formatter, PostProcess, PrettyPlease};
use serde::{Deserialize, Serialize};
use super::rendered_element::RenderedElement;
@@ -103,25 +103,37 @@ impl Project {
r#"// Automatically generated by iced Builder
use iced::{{widget::{{{imports}}},Element}};
+_blank_!();
+
fn main() -> iced::Result {{
iced::application(State::default, State::update, State::view).title("{title}").theme(State::theme).run()
}}
+_blank_!();
+
#[derive(Default)]
struct State;
+_blank_!();
+
#[derive(Debug, Clone)]
enum Message {{}}
+_blank_!();
+
impl State {{
fn update(&mut self, _message: Message) {{
// Insert your desired update logic here
}}
+ _blank_!();
+
fn theme(&self) -> iced::Theme {{
iced::Theme::{theme}
}}
+ _blank_!();
+
fn view(&self) -> Element<Message> {{
{view}.into()
}}
@@ -134,19 +146,9 @@ impl State {{
);
let config = rust_format::Config::new_str()
- .edition(Edition::Rust2021)
- .option("trailing_comma", "Never")
- .option("imports_granularity", "Crate");
- let rustfmt = RustFmt::from_config(config);
-
- match rustfmt.format_str(&app_code) {
- Ok(code) => return Ok(code),
- // rustfmt is missing, that's fine, we fall back to manual formatting
- Err(rust_format::Error::IOError(_)) => {
- return Ok(app_code);
- }
- Err(err) => return Err(err.into()),
- }
+ .post_proc(PostProcess::ReplaceMarkers);
+
+ Ok(PrettyPlease::from_config(config).format_str(&app_code)?)
}
None => Err("No element tree present".into()),
};