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

String-based line-wrapping for formatter #1232

Merged
merged 2 commits into from
Jun 14, 2022

Conversation

billy-bao
Copy link
Collaborator

@billy-bao billy-bao commented Jun 14, 2022

This is a basic implementation for line-wrapping LF code. The formatter takes into account the current level of indentation when breaking lines for line-wrapping, but will always break at spaces (violating the line-wrap limit if it cannot find a space before the limit). Set the line-wrap limit with ToLf.instance.setLineWrap().
Part of #1227.

@lhstrh lhstrh requested a review from petervdonovan June 14, 2022 01:27
Copy link
Collaborator

@petervdonovan petervdonovan left a comment

Choose a reason for hiding this comment

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

This implementation is way simpler and less messy than what I had in mind.

I left some nitpicks. My only real concern with this approach is what I said on Slack -- that to do this at the level of string processing as opposed to AST processing, while respecting single-line comments and strings and Python code blocks etc., will effectively result in a re-implementation of part of our parser. We have done something like that with semantic highlighting, but it was a little messy and I am not sure if it was a good idea (as in, we might eventually delete those 500 lines of code and replace them with queries to the language server, which has the AST).

I advocate for merging this into the pretty-printer branch now so that we can move on to other things, with the understanding that if we do run into the problems that I have talked about, I am not in favor of investing a lot of time into getting this to work well without directly processing the AST.

org.lflang/src/org/lflang/ast/ToLf.java Show resolved Hide resolved
org.lflang/src/org/lflang/ast/ToLf.java Show resolved Hide resolved
Co-authored-by: Marten Lohstroh <marten@berkeley.edu>
@lhstrh lhstrh marked this pull request as ready for review June 14, 2022 17:03
@lhstrh lhstrh merged commit 90a4c97 into pretty-printer Jun 14, 2022
@cmnrd cmnrd deleted the formatter-linewrap-string branch June 8, 2023 07:48
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.

3 participants