-
Notifications
You must be signed in to change notification settings - Fork 22
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 a LineSuffix Doc #65
Comments
Can't say I have had this problem, my line comments always have a
|
An example, in Lua foo( -- comment
"bar"
) I want this to be collapsed onto a single line, but I can't add a hardline at the end of the comment here foo( -- comment "bar") But ideally, it should be buffered so that it outputs something like foo("bar") -- comment |
That seems surprising to me, personally if I placed a comment like that I would expect the comment to just prevent the function call from appearing on a single line. The comment could even be explaining something about the argument itself, in which case moving it out and after the call loses the intent of whoever wrote the comment. |
Adding something like this could still be useful, but I want to make sure it targets the right issue here, and perhaps other similar problems as well. |
Hm, I've been rethinking this and I actually do agree with you there - I should probably be leaving comments as close to where they are originally. I guess another place where this could occur would be when a user inputs print"foo" -- a comment where omitting parentheses goes against the code style enforced, so it would want to be reformatted as print("foo") -- a comment but would currently be reformatted as print("foo" -- a comment) I also just saw your "Why not" comment in your original reply. In this case (atleast, for the current way my formatter is setup, which could theoretically change), the formatting of the string literal, which would be local foo = "bar" -- a comment I guess it is up to you if you think this is in scope for pretty.rs to handle instead, and I understand if it isn't - I could probably work my code around for this. |
I think you may be able to hack into what you want by implementing https://docs.rs/pretty/0.10.0/pretty/trait.RenderAnnotated.html yourself and attach the comments as annotations. Then the renderer would buffer the comments until Maybe that breaks down at some point but it could be a POC of this solution. |
Alright, I'll check it out and see how I get on (it may be a while as I'm currently working on some other stuff right now). Thanks! |
I'm currently thinking about using pretty.rs for one of my projects, but one thing holding me back is that I can't seem to find a nice way to handle comments currently. Trailing comments can be quite a pain, and you don't want them to be introduced in between code, rather pushed towards the end of the line and then printed there.
From what I can see, there isn't a simple way to do this (please let me know if I'm missing something!). Prettier implements a lineSuffix and lineSuffixBoundary Doc, which places the Doc into a buffer and then outputs it just before a new line - which would immediately help with this problem.
The text was updated successfully, but these errors were encountered: