LuaFormatter icon indicating copy to clipboard operation
LuaFormatter copied to clipboard

Add Seperate Table Length Maximum

Open benrob0329 opened this issue 5 years ago • 8 comments

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.

benrob0329 avatar Dec 12 '19 03:12 benrob0329

Seems reasonable to me to have such distinction.

What are your thoughts @Koihik ?

tammela avatar Dec 13 '19 18:12 tammela

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.

Koihik avatar Dec 14 '19 06:12 Koihik

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.

benrob0329 avatar Dec 14 '19 17:12 benrob0329

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.

benrob0329 avatar Dec 15 '19 19:12 benrob0329

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.

The behavior of chop_down_kv_table is right now. I made a mistake.

Koihik avatar Dec 16 '19 04:12 Koihik

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.

Koihik avatar Dec 16 '19 04:12 Koihik

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.

Koihik avatar Dec 16 '19 04:12 Koihik

this has been added, although the setting for table length limit doesn't appear to be respected

nathanloyer avatar Oct 08 '21 21:10 nathanloyer