Fix: #2604, Fix: #2240, Fix: #2341, Fix #1355 - Better error handling and and spaces handling in autofmt (#2736)

* add new autofmt sample
* Feat: implement rustfmt::skip support for rsx
* generally improve error handling with better expect messages
* wip: nested rsx formatting and expression formatting
* nested rsx formatting works
* collapse autofmt crate
* cast indent through macros
* use proper whitespace
* no more eating comments!
* Use proper error handling
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-07-30 18:36:13 -07:00
1 parent ef0202f999
commit 828cc502f1
47 files changed
+1621 -1055

No files matched your search

+1
View File
@@ -11,6 +11,7 @@ wasm-bindgen = { workspace = true }
dioxus-autofmt = { workspace = true }
rsx-rosetta = { workspace = true }
html_parser = { workspace = true }
syn ={ workspace = true }
[lib]
crate-type = ["cdylib", "rlib"]
+19 -11
View File
@@ -65,18 +65,26 @@ impl FormatBlockInstance {
#[wasm_bindgen]
pub fn format_file(contents: String, use_tabs: bool, indent_size: usize) -> FormatBlockInstance {
let _edits = dioxus_autofmt::fmt_file(
&contents,
IndentOptions::new(
if use_tabs {
IndentType::Tabs
} else {
IndentType::Spaces
},
indent_size,
false,
),
// todo: use rustfmt for this instead
let options = IndentOptions::new(
if use_tabs {
IndentType::Tabs
} else {
IndentType::Spaces
},
indent_size,
false,
);
let Ok(Ok(_edits)) = syn::parse_file(&contents)
.map(|file| dioxus_autofmt::try_fmt_file(&contents, &file, options))
else {
return FormatBlockInstance {
new: contents,
_edits: Vec::new(),
};
};
let out = dioxus_autofmt::apply_formats(&contents, _edits.clone());
FormatBlockInstance { new: out, _edits }
}
+9 -9
View File
@@ -65,9 +65,9 @@ function fmtSelection() {
// Select full lines of selection
let selection_range = new vscode.Range(
editor.selection.start.line,
0,
end_line,
editor.selection.start.line,
0,
end_line,
editor.document.lineAt(end_line).range.end.character
);
@@ -83,9 +83,9 @@ function fmtSelection() {
end_line += 1;
selection_range = new vscode.Range(
editor.selection.start.line,
0,
end_line,
editor.selection.start.line,
0,
end_line,
editor.document.lineAt(end_line).range.end.character
);
@@ -103,8 +103,8 @@ function fmtSelection() {
let lines_above = editor.document.getText(
new vscode.Range(
0,
0,
0,
0,
end_above,
editor.document.lineAt(end_above).range.end.character
)
@@ -115,7 +115,7 @@ function fmtSelection() {
try {
let formatted = dioxus.format_selection(unformatted, !editor.options.insertSpaces, tabSize, base_indentation);
for(let i = 0; i <= base_indentation; i++) {
for (let i = 0; i <= base_indentation; i++) {
formatted = (editor.options.insertSpaces ? " ".repeat(tabSize) : "\t") + formatted;
}
if (formatted.length > 0) {