DanielGavin / ols

Language server for Odin
MIT License
439 stars 67 forks source link

[odinfmt] weird `return {...}` struct formatting #346

Closed jakubtomsu closed 5 months ago

jakubtomsu commented 5 months ago

A return statement with a multiline struct initializer gets formatted weirdly.

Here is an example. This is the what it should look like:

return {
    alloc_fn = allocator_alloc_func,
    free_fn = allocator_free_func,
    user_data = cast(rawptr)context_ptr,
}

And here is what it gets formatted into:

return(
     {
        alloc_fn = allocator_alloc_func,
        free_fn = allocator_free_func,
        user_data = cast(rawptr)context_ptr,
    } \
)

The parentheses and backslash don't look very good...

DanielGavin commented 5 months ago

The format style was thought for:

return(
    imp1.derived.(^ast.Import_Decl).fullpath <
    imp2.derived.(^ast.Import_Decl).fullpath \
)

Instead it would have to be

return imp1.derived.(^ast.Import_Decl).fullpath <
       imp2.derived.(^ast.Import_Decl).fullpath \

OR

return 
    imp1.derived.(^ast.Import_Decl).fullpath <
    imp2.derived.(^ast.Import_Decl).fullpath \

Maybe that should be changed aswell, but with braces I agree it makes no sense.

jakubtomsu commented 5 months ago

I think this looks the best:

return imp1.derived.(^ast.Import_Decl).fullpath <
       imp2.derived.(^ast.Import_Decl).fullpath \

The braces do make things a bit clearer, but it's not something I would write without odinfmt. I'm not entirely sure but I think the core: libs don't use them as well.

Feoramund commented 5 months ago

Looks to be a duplicate of #271.

DanielGavin commented 5 months ago

Fixed.