DioxusLabs / DioxusLabs/dioxus

Interaction between IfmtInput::push_* and rsx-autoformat

Open
#3,503 1 comment 0 reactions 0 assignees View on GitHub
autoformatting bug rsx
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

**Problem**

IfmtInput has methods like `push_raw_str` to modify the segments, but those methods do not effect the source. Since the autoformatter only uses the source it was originally parsed from formatting a ifmt segment reverts the segments that were pushed. This behavior caused [this](https://github.com/DioxusLabs/docsite/issues/369) bug in the docsite codegen. The patch works around the issue by not merging adjacent text segments

**Steps To Reproduce**

Run this code and observe it panics:
```rust

#[test]
fn fails() {
let mut rsx: CallBody = parse_quote! { "hello world" };
if let dioxus_rsx::BodyNode::Text(text) = &mut rsx.body.roots[0] {
// Modifying the IfmtInput directly is allowed, but it doesn't update the source that autofmt uses
text.input
.formatted_input
.push_raw_str(" this isn't added to the formatted version".to_string());
}
let block = dioxus_autofmt::write_block_out(&rsx).unwrap();
let re_parsed: CallBody = syn::parse_str(&block).unwrap();

// normalize line endings for windows tests to pass
assert_eq!(rsx.body, re_parsed.body);
}
```

**Expected behavior**

You should not be able to edit IfmtInput internals or modifying IfmtInput should work with the autoformatter

**Environment:**
- Dioxus version: `master`
- Rust version: `nightly`
- OS info: MacOS

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.