ols icon indicating copy to clipboard operation
ols copied to clipboard

[odinfmt idea] Better formatting for procs with a single struct initializer parameter

Open jakubtomsu opened this issue 10 months ago • 2 comments

In Sokol libraries it's very common to pass a single "_Desc" struct with all parameters, instead of passing them individually.

For example:

make_buffer :: proc(#by_ptr desc: Buffer_Desc) -> Buffer ---

Which when called is formatted into something like this:

    model_vertex_buf := sg.make_buffer(
         {
            type = .VERTEXBUFFER,
            usage = .IMMUTABLE,
            size = u64(len(vertices) * size_of(vertices[0])),
            data = sg_range_slice(vertices),
        },
    )

But it would be nicer if it was formatted like this:

    model_vertex_buf := sg.make_buffer({
        type = .VERTEXBUFFER,
        usage = .IMMUTABLE,
        size = u64(len(vertices) * size_of(vertices[0])),
        data = sg_range_slice(vertices),
    })

In case this would add unnecessary complexity to the formatter or just isn't something you want, feel free to close this issue. It's just a small idea...

jakubtomsu avatar Apr 15 '24 15:04 jakubtomsu

Yeah seems like a better option. Can always start just doing that specific format when there is only one argument with comp literal. Not sure how nice it would look if there are more arguments.

DanielGavin avatar Apr 15 '24 22:04 DanielGavin

Yeah I think it would totally make sense to limit it to procs with only one parameter

jakubtomsu avatar Apr 16 '24 04:04 jakubtomsu