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

Total line length not taken into account in for loops #322

Closed
evaera opened this issue Dec 24, 2021 · 2 comments · Fixed by #337
Closed

Total line length not taken into account in for loops #322

evaera opened this issue Dec 24, 2021 · 2 comments · Fixed by #337
Labels
enhancement New feature or request

Comments

@evaera
Copy link

evaera commented Dec 24, 2021

I have a for loop with a long initial line. StyLua formats it like this:

local function system(world)
	for id, model, lasering, transform in world:query(Components.Model, Components.Lasering, Components.Transform, Components.Mothership) do
	end
end

If I make the function call longer, StyLua formats it more correctly:

local function system(world)
	for id, model, lasering, transform in world:query(
		Components.Model,
		Components.Lasering,
		Components.Transform,
		Components.Mothership,
		Components.Mothership
	) do
	end
end

But if I add more variables to the loop, it does not do anything:

local function system(world)
	for id, model, lasering, transform, id, model, lasering, transform, id, model, lasering, transform, id, model, lasering, transform in world:query(Components.Model, Components.Lasering, Components.Transform, Components.Mothership) do
	end
end

Ideally, the formatter should probably produce something close to this:

local function system(world)
	for id, model, lasering, transform,
		id, model, lasering, transform, 
		id, model, lasering, transform, 
		id, model, lasering, transform 
	in
		world:query(
			Components.Model,
			Components.Lasering,
			Components.Transform,
			Components.Mothership,
			Components.Model,
			Components.Lasering,
			Components.Transform,
			Components.Mothership
		)
	do
	end
end
@JohnnyMorganz JohnnyMorganz added the enhancement New feature or request label Dec 24, 2021
@JohnnyMorganz
Copy link
Owner

The initial input is over width, so we seem to be incorrectly calculating the current amount of line width taken up here. Prettier example for reference

In your ideal case, I think the best we could do is probably split each individual variable on its own line. Splitting every X (in this case 4) variables seems very arbitrary (in this case it works since its 4 variables repeated), so I'm not sure if its the right way to go. Of course, the downside is that it takes up a lot of vertical space sticking each variable on a new line, but this is the format prettier also uses.

@evaera
Copy link
Author

evaera commented Jan 7, 2022

The initial input is over width, so we seem to be incorrectly calculating the current amount of line width taken up here. Prettier example for reference

In your ideal case, I think the best we could do is probably split each individual variable on its own line. Splitting every X (in this case 4) variables seems very arbitrary (in this case it works since its 4 variables repeated), so I'm not sure if its the right way to go. Of course, the downside is that it takes up a lot of vertical space sticking each variable on a new line, but this is the format prettier also uses.

👍 Whatever you think is best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants