DanielGavin / ols

Language server for Odin
MIT License
375 stars 56 forks source link

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

Open jakubtomsu opened 2 months ago

jakubtomsu commented 2 months ago

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...

DanielGavin commented 2 months ago

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.

jakubtomsu commented 2 months ago

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