LuaFormatter
LuaFormatter copied to clipboard
Add Seperate Table Length Maximum
Sometimes you want tables to be broken earlier than the standard line limit, it'd be nice to have an extra setting to break tables earlier/later than other lines.
Examples:
Current:
some.really.long.function_call(with, many, parameters)
table = {that = should, really = be, broken = sooner}
Or:
some.really.long.function_call(with, many,
parameters)
table = {
that = now,
is = actually,
broken = sooner,
}
Suggested:
some.really.long.function_call(with, many, parameters)
table = {
that = now,
is = actually,
broken = sooner,
}
Note that chop_down_table only seems to "chop down" tables if they would be longer than the line length limit. This is sane behavior, just not exactly what is needed for my project.
Seems reasonable to me to have such distinction.
What are your thoughts @Koihik ?
The meaning of config chop_down_kv_table
should be "force chop down those table with key-value pairs". But it doesn't work now. It seems can resolve your problem after fix it.
Chopping down all kv tables would also chop down vector tables such as {x=3, y=7, z=11}
which is silly and ugly. This also applies to indexed tables as well because they can be rather long too (just not longer than my rather large line-length limit usually).
Fixing the option would be nice though, but there should be notes in the documentation that chop_down_tables
respects the line limit, while chop_down_kv_tables
does not.
An alternative which has been suggested to me is a behavior some other (non Lua) formatters have, chopping down tables based on whether or not they have an extra separator at the end.
So:
single_line = {"a", "b", "c"}
multi_line = {
"a",
"b",
"c",
}
The extra comma tells the formatter to break/chop down the table.
Chopping down all kv tables would also chop down vector tables such as
{x=3, y=7, z=11}
which is silly and ugly. This also applies to indexed tables as well because they can be rather long too (just not longer than my rather large line-length limit usually).Fixing the option would be nice though, but there should be notes in the documentation that
chop_down_tables
respects the line limit, whilechop_down_kv_tables
does not.
The behavior of chop_down_kv_table
is right now. I made a mistake.
An alternative which has been suggested to me is a behavior some other (non Lua) formatters have, chopping down tables based on whether or not they have an extra separator at the end.
So:
single_line = {"a", "b", "c"} multi_line = { "a", "b", "c", }
The extra comma tells the formatter to break/chop down the table.
It seems feasible.
When there was no column_limit
, formatter use some strange conditions to judge whether a table need to break. Such as contains key-value pairs and length greater than 1 or length greater than 10
. It's hard to handle all cases.
I thought the best behavior of formatter is to recognize the customer line break:
If the table has line break originally, then the formatter just chop down it.
If the table has no line break, then the formatter judge the column limit.
this has been added, although the setting for table length limit doesn't appear to be respected