Skip to content
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

formatting fixes and improvements #4625

Merged
merged 9 commits into from
Feb 16, 2024
Merged

Conversation

Waqar144
Copy link
Contributor

@Waqar144 Waqar144 commented Feb 15, 2024

  • states with multiple state element are now formatted properly
  • arrays with trailing commas no longer result in error
  • large arrays (len=80) and arrays with trailing comma are formatted with new line
  • for with index no longer errors out and is formatted properly
  • property animations are now supported
  • object literals are now supported. big literals (len=80) and literals with trailing comma are broken into multiple lines

With these patches I can run slint-lsp format on slint files in examples and the result seems to be acceptable.

Closes #3900

@Waqar144
Copy link
Contributor Author

should fix everything in #3900

@tronical
Copy link
Member

That sounds super promising ❤️❤️. Looking forward to trying this out.

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

This definitively improves things.

I left a few comments for things that could be done in follow up.

&& whitespace_to(&mut sub, SyntaxKind::LBracket, writer, state, " ")?;

if !ok {
eprintln!("Inconsistency: Expect states and ']'");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we should get rid of these warnings.
They'd be shown in the Slint LSP output tab in vscode and maybe other editors also show it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it will make these function a bit more flexible. Currently they just error out

Comment on lines +1456 to +1458
animate background {
duration: 800ms;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like when it is in one single line. Perhaps we could have the same trick as array, if it is fitting in 80 character it shouldn't be formatted in several lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the next pr, I have changed it so that if there is only binding it will be kept on a single line, but with multiple it is broken into multiple lines.

But I can change it to 80 char limit too if that's better.

} else {
(SyntaxKind::Identifier, " ")
};
let el = whitespace_to_one_of(&mut sub, &[kind], writer, state, prefix_whitespace)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess you can just call whitespace_to here. In fact i'd do it in the if above.

Can you also check for [index] in model without an name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also check for [index] in model without an name?

Typing that out results in a compiler error with 1.4.0, is this a new syntax?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking it was allowed (i remember wanting this to be allowed while parsing for expressions:

/// for [idx] in mm: Elem { }
)

But it's actually indeed not accepted, you're right

@ogoffart ogoffart merged commit cc58cdc into slint-ui:master Feb 16, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Format tool creates strange looking code and shows errors
3 participants