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

Moving code onto one line with comment breaks code #23

Closed
NPhrd opened this issue Jan 3, 2021 · 5 comments · Fixed by #29
Closed

Moving code onto one line with comment breaks code #23

NPhrd opened this issue Jan 3, 2021 · 5 comments · Fixed by #29
Labels
bug Something isn't working

Comments

@NPhrd
Copy link

NPhrd commented Jan 3, 2021

Before running StyLua:

local foo_result = foo( --a comment
	"oof"
)

local expr_result = 1 + 2 + 3 + 4 + 5 --a comment
	+ 6 + 6 + 8

After running StyLua:

local foo_result = foo( --a comment"oof")

local expr_result = 1 + 2 + 3 + 4 + 5 --a comment + 6 + 6 + 8
@JohnnyMorganz JohnnyMorganz added the bug Something isn't working label Jan 4, 2021
@JohnnyMorganz
Copy link
Owner

This is an interesting problem. I'm going to need to create some sort of buffer for any comments within expressions, and then push them towards the end of the line where its "safe" to place them.

Is this a common occurrence in your codebase? I'm currently busy with some other work at the moment but I can take a look at this soon - from first glance, it does look like I'll need to think some more about how to solve this.

@NPhrd
Copy link
Author

NPhrd commented Jan 4, 2021

I only found a couple instances of this, so I'm in no big trouble at the moment 👍

@NPhrd
Copy link
Author

NPhrd commented Jan 9, 2021

Depending on your solution, this probably won't be a separate issue, but I'll mention it just in case

Before running StyLua:

print"text" --a comment

After running StyLua:

print("text" --a comment)

@JohnnyMorganz
Copy link
Owner

Thanks, I think that's a separate case handled differently inside the codebase (with the same problem) so I'll also need to check that out.

Sorry, I've been bombarded with work recently so I'll see when I can make time to fix this bug

@JohnnyMorganz
Copy link
Owner

a0f6bdd is a partial fix for this, mainly the situations where there are comments present inside of function arguments, and comments trailing commas in punctuated sequences. Function calls will now remain expanded if there is a comment present inside of them, to keep the comments as close as possible to original code. Currently, in other cases where comments are in weird locations, I'm buffering them to the end of the line. This does mean that they may move from where people originally wanted them to be, and if that is a problem, please do let me know!

I still need to figure out a way to handle comments within expression properly (the example you gave above with the summation of the numbers). I think I need to do something similar as with function call arguments, where I just leave them wrapped onto multiple lines - but currently StyLua doesn't support multiline expressions anyways. This will probably have to wait until a change to support #25 is added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants