CppCXY / EmmyLuaCodeStyle

fast, powerful, and feature-rich Lua formatting and checking tool.
MIT License
140 stars 27 forks source link

[Feature request] space_before_function_open_braces option that controls spaces before curly braces in function calls #83

Closed ArmoredPony closed 1 year ago

ArmoredPony commented 1 year ago

If space_before_function_open_parenthesis parameter is set to false then f (...) call is formatted to f(...). But curly braces are always formatted with space: f {...}. Would be nice to control this space presence with the same option or with a new one, like space_before_function_open_braces.

CppCXY commented 1 year ago

The reason single-parameter calls are uncontrolled is that for consecutive calls, spaces must be kept between them, for eg.

p "12313" "12313131" { aaa = bbb }

Probably you just hope:

p{ a = 123 } "123131" "4665465"
ArmoredPony commented 1 year ago

But if we call function not with curly braces but parentheses, then there will be no space after function name, considering space_before_function_open_parenthesis is false. If I use parenthesis in consecutive calls then it would look like this: p(var) '123' '456' which looks similar to p{a = 123} "123131" "4665465". Why curly braces should be treated differently than parentheses in terms of formatting?

CppCXY commented 1 year ago

their grammatical components are different, and this feature(space_before_function_open_parenthesis) was originally added by other contributor. If you want to implement this feature, you can think of a name

CppCXY commented 1 year ago

I decided to implement this feature before the 1.0.0 release

CppCXY commented 1 year ago

feature complete, option name is space_before_function_call_single_arg

ArmoredPony commented 1 year ago

I love how this feature works with tables, but I would gladly disable it when it comes to strings. In SpaceAnalyzer.cpp, I tried to implement this myself by catching curly brace at this else branch with something like GetChildToken('{', t), however I appear to be not competent enough to comprehend your parser and implement my idea. Would you please consider reopening the request and splitting this feature into two: space_before_function_call_single_table for tables and space_before_function_call_single_string for strings?

CppCXY commented 1 year ago

if you want to develop this project, please see test2, this will print lua syntax tree. And this feature has been completed space_before_function_call_single_arg=only_string