-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Introduce Token element #7048
Introduce Token element #7048
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
3ed2546
to
2e61a54
Compare
/// indent(&format_args![ | ||
/// hard_line_break(), | ||
/// text("indent level 1"), | ||
/// token("indent level 1"), |
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.
This is arguably worse because these aren't really tokens but having a text
builder just for the examples feels overkill (and the examples don't violate any constraint)
2e61a54
to
ce2b166
Compare
ce2b166
to
e1e047f
Compare
Cool! I like the rename of dynamic_text to text as well |
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 support changing DynamicText
to text
.
fc0d6aa
to
409f8f9
Compare
fmt.debug_tuple("DynamicText").field(text).finish() | ||
} | ||
FormatElement::Token { text } => fmt.debug_tuple("Token").field(text).finish(), | ||
FormatElement::Text { text, .. } => fmt.debug_tuple("DynamicText").field(text).finish(), |
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 guess that DynamicText
-> Text
.
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.
Yes, that's correct
Summary
This PR replaces
StaticText
with a stricterToken
elementThis proves to be sufficient for the
text
usages in Ruff's formatter today (and probably all code formatters) and has the advantage that the formatter can take shortcuts for these strings.I thought about introducing a new
Token
element instead of replacingText
. But we don't really have any use case for it other than doctests, which doesn't justify adding a new format element.Feedback welcome on
Should we rename
dynamic_text
totext
?Test Plan
cargo test
Performance
This improves performance between 2-3%