-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix parsing of braced expressions followed by a method #4035
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
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 this! Unfortunately, I think the issue is slightly broader than just method calls. If we find anything except a comma after a braced expression we should try to parse it as a normal expression. The check you added fixes this expression width: {"100%"}.to_string(),, but this expression still fails width: {|| "100%"}(),
|
@ealmloff These new changes should fix the issue. Could you please check again if there is another case I'm missing? |
|
I found a few more cases that are broken. This test fails on the PR, but passes on the main branch: #[test]
fn invalid_braced_expression() {
let item = quote::quote! {
// Partial expressions in braces rsx should be allowed and output as-is
// for autocomplete
{invalid.}
div {}
{invalid.}
// Comments should be ignored
div {}
{invalid.}
"hello world"
{invalid.}
if true {}
};
let cb: CallBody = syn::parse2(item).unwrap();
println!("{}", cb.to_token_stream());
}These all pass now which is great! #[test]
fn expressions_after_braced() {
let item = quote::quote! {
div {
width: {100} - 50,
width: {"100%"}.to_string(),
width: {|| "100%"}(),
}
};
let cb: CallBody = syn::parse2(item).unwrap();
println!("{}", cb.to_token_stream());
}I think these two cases should cover everything?
|
|
This new change fixes the missing cases. Please let me know if there are more test cases I should include. |
ealmloff
left a comment
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.
Looks great, thanks for fixing this! Confirmed autocomplete still works with the base raw brace expressions
* Fix parsing of braced expressions followed by a method * Improves the logic for parsing braced expressions * Fix hot-reload issue * Added cases for braced expressions followed by identifiers or string literals
* Fix parsing of braced expressions followed by a method * Improves the logic for parsing braced expressions * Fix hot-reload issue * Added cases for braced expressions followed by identifiers or string literals
This is an attempt at solving issue #3945 when parsing attributes.
I added code that checks if there is a TokenTree::Group followed by a dot. If it finds it, it parses the whole attribute as an expression. It stops if it finds a comma, signaling the end of the attribute.
I added the example in the original issue to the "complex_kitchen_sink" test, and everything passed.