Inline functions are broken after formatting
I think inline functions should stay inline after formatting:
like in my code:
return {
normal = pipe.new
* func.map2(tracks1, tracks2,
function(t1, t2)
local seg = {junction.generateArc(t1)[1], junction.generateArc(t2)[2]}
seg[1][2], seg[2][1] = average(seg[1][2], seg[2][1])
seg[1][4], seg[2][3] = average(seg[1][4], seg[2][3])
return pipe.new
* seg
* pipe.map(pipe.map(coor.vec2Tuple))
* pipe.zip({{false, false}, {false, false}}, {"edge", "snap"})
end)
* pipe.flatten()
* station.prepareEdges
* function(r) return func.with(r, {edges = coor.applyEdges(trans.mpt, trans.mvec)(r.edges)}) end,
ext = pipe.new
* func.map2(tracks1, tracks2,
function(t1, t2)
local seg = {junction.generateArc(t1)[3], junction.generateArc(t2)[4]}
return pipe.new
* seg
* pipe.map(pipe.map(coor.vec2Tuple))
* pipe.zip({{true, false}, {false, true}}, {"edge", "snap"})
end)
* pipe.flatten()
* station.prepareEdges
* function(r) return func.with(r, {edges = coor.applyEdges(trans.mpt, trans.mvec)(r.edges)}) end
}
after formatting, it's not good as before, since inline functions are broken, and my pipe operators goes to the end of the line
I think the user should be able to configure on some formatting options.
return {
normal = pipe.new *
func.map2(
tracks1,
tracks2,
function(t1, t2)
local seg = {junction.generateArc(t1)[1], junction.generateArc(t2)[2]}
seg[1][2], seg[2][1] = average(seg[1][2], seg[2][1])
seg[1][4], seg[2][3] = average(seg[1][4], seg[2][3])
return pipe.new * seg * pipe.map(pipe.map(coor.vec2Tuple)) *
pipe.zip({{false, false}, {false, false}}, {"edge", "snap"})
end
) *
pipe.flatten() *
station.prepareEdges *
function(r)
return func.with(r, {edges = coor.applyEdges(trans.mpt, trans.mvec)(r.edges)})
end,
ext = pipe.new *
func.map2(
tracks1,
tracks2,
function(t1, t2)
local seg = {junction.generateArc(t1)[3], junction.generateArc(t2)[4]}
return pipe.new * seg * pipe.map(pipe.map(coor.vec2Tuple)) *
pipe.zip({{true, false}, {false, true}}, {"edge", "snap"})
end
) *
pipe.flatten() *
station.prepareEdges *
function(r)
return func.with(r, {edges = coor.applyEdges(trans.mpt, trans.mvec)(r.edges)})
end
}
I think this might be difficult to address in a broad and generic way, as it would definitely have knock-on effects with legitimate code. What kind of options would you like to see to address this?
I do agree that this is a drastic change to the obviously preferred operator * concatenation in your original sample, though.
Don't know how your formatter works, but if it exists AST, the CR should be considered, and I think you can put some switches in options for different styles, for example left { should be in a new line or not, or just keep, or in my case, a line feed before an operator should be conserved or not. Don't know if you are using VS (the big one) there are many such options like this in formatting.
I am currently using the formatter in this extension, https://marketplace.visualstudio.com/items?itemName=gccfeli.vscode-lua, it works but it's quite slow, however it respects the line feed, the formatter or it can be found here: https://github.com/GCCFeli/LuaFormat (in C#)