lua-lsp icon indicating copy to clipboard operation
lua-lsp copied to clipboard

There is no standard lua formatter

Open Alloyed opened this issue 7 years ago • 6 comments

:thinking:

I'm not willing to write my own but it's interesting that it doesn't exist to begin with prior art: https://github.com/trixnz/lua-fmt written by the vscode server author https://github.com/trixnz/vscode-lua

Alloyed avatar Sep 05 '17 04:09 Alloyed

Most formatters I've encountered have used the Metalua-based formatter:

  • Eclipse LDT (https://projects.eclipse.org/projects/tools.ldt)
  • atom-format-lua for Atom (https://github.com/mingjunyang/atom-format-lua)
  • FormatLua for SublimeText (https://github.com/denglf/FormatLua)

I've never found the upstream source for this formatter, but I haven't searched a whole lot. As far as I can tell the source is just copy-pasted around.

Although widely used, this formatter does choke on Lua 5.3's new bitwise operators because it's based on Lua 5.1.

ryanplusplus avatar Sep 14 '17 11:09 ryanplusplus

Thanks, the parser I'm using implements a subset of metalua so I can probably just retrofit this onto its output.

the EPL suggest that it started in eclipse, and it even includes a CLI interface (!) I might leave that in there so if somebody just wants a standalone formatter they can install my package and call it from there

Alloyed avatar Sep 14 '17 15:09 Alloyed

:+1:

ryanplusplus avatar Sep 14 '17 15:09 ryanplusplus

https://github.com/Koihik/LuaFormatter

shuxiao9058 avatar Jan 09 '19 17:01 shuxiao9058

https://github.com/trixnz/lua-fmt

Alloyed avatar Mar 23 '19 15:03 Alloyed

https://github.com/JohnnyMorganz/StyLua

lblasc avatar Apr 04 '21 07:04 lblasc