-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First attempt to add newlines between attributes. (#275) #731
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on it. I think, that my initial proposal is simpler to use. To implement it we need a 3-state enum:
enum AttributeIndent {
/// Initial state
NoneAttributesWritten,
/// Keep indent that should be used if `new_line()` would be called
SomeAttributesWritten(usize),
/// Write specified indent before writing attribute in `with_attribute()`
Indent(usize),
}
// in new_line()
match state {
NoneAttributesWritten => state = Indent(self.writer.indent.len()),
SomeAttributesWritten(i) => state = Indent(i),
Indent(_) => // write \n
}
// in with_attribute()
let i = match state {
// neither .new_line() or .with_attribute() not yet called
NoneAttributesWritten => self.writer.indent.len(),
// .new_line() was not called, but .with_attribute() was
SomeAttributesWritten(i) => i,
Indent(i) => {
// write \n + self.writer.indent + i
i
}
};
// write attribute
state = SomeAttributesWritten(i);
The resulting state diagram:
stateDiagram-v2
[*] --> NoneAttributesWritten
NoneAttributesWritten --> SomeAttributesWritten1 : .with_attribute()
NoneAttributesWritten --> Indent2 : .new_line()
SomeAttributesWritten1 --> SomeAttributesWritten1 : .with_attribute()
SomeAttributesWritten1 --> Indent1 : .new_line()
Indent1 --> SomeAttributesWritten1 : .with_attribute()
Indent1 --> Indent1 : .new_line()
SomeAttributesWritten2 --> SomeAttributesWritten2 : .with_attribute()
SomeAttributesWritten2 --> Indent2 : .new_line()
Indent2 --> SomeAttributesWritten2 : .with_attribute()
Indent2 --> Indent2 : .new_line()
@Mingun Thanks a lot for the review, I implemented your suggestion. I hope I interpreted it properly. Let me know if you think it needs changes, otherwise I will write a couple of tests to look for edge cases. |
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #731 +/- ##
==========================================
+ Coverage 61.24% 61.90% +0.66%
==========================================
Files 39 39
Lines 16277 16520 +243
==========================================
+ Hits 9969 10227 +258
+ Misses 6308 6293 -15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't run code myself, but it seems to be correct. Please add other tests, update changelog.md and I think, it would be almost complete.
bcb7fb4
to
ea6a118
Compare
Thanks for you work! I squashed all your commits, write tests in my standards (nested modules), add documentation. I realized, that currently, because In any case, current writer code is not good, because:
For this reason, I want to hold onto a little bit of this PR to adapt my old code and then use its results here. |
ea6a118
to
2053bd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I found a way to do that without much refactoring.
@dralley, would you like to look? Otherwise it is good to me.
2053bd0
to
613b230
Compare
Wait on merge it this, I found that tests are incomplete. In case of <element first="1"
second="2"/> we always should use spaces, but now indent symbols are used. The fix is trivial, just need to add a buffer to <element
first="1"
second="2"/> To test this situation it is enough adjust tests to use |
What about implementing it in such a way that (1) only happens if the indent symbol is set to b
I'm coming from the opinion that combining indentation symbols is not a good idea. (Even the rendering of \t in GitHub was different from what I was hoping, another example of why I would avoid mixing indentation symbols) |
Yes, I also think, that mixing indentation symbols is a bad idea, because some editors can easily break things by replacing spaces with tabs, but auto-selecting behaviour based on intendation settings seems to me even worse. The user can implement such behaviour yourself using our stupid plumbing interface. |
613b230
to
c8b427f
Compare
Closes #275
This is an implementation of the suggestion here: #275 (comment)
It may be a little hacky, I am new to Rust so if I am doing some obvious mistake please tell me.