DanielGavin / ols

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

Odinfmt: Breaks code on long "If-statements with initialization" #379

Open p1xelHer0 opened 2 months ago

p1xelHer0 commented 2 months ago

I stumbled upon this when using some code from the Odin examples repo: https://github.com/odin-lang/examples/blob/73ce95aacfaf85c22e728cfaddfa308fd0b132b0/sdl2/microui/microui_sdl_demo.odin#L94. It uses "If-statements with initialization".

Here's a small reproduction of the issue I am facing:

test :: proc() {
    Thing :: enum {
        .ReallyLongEnum,
        .AnotherReallyLongEnum,
    }

    my_really_long_variable: Thing
    another_really_long_variable: Thing

    test := my_really_long_variable if another_really_long_variable == .ReallyLongEnum else .AnotherReallyLongEnum
}

Which formats into:

test :: proc() {
    Thing :: enum {
        .ReallyLongEnum,
        .AnotherReallyLongEnum,
    }

    my_really_long_variable: Thing
    another_really_long_variable: Thing

    test :=
        my_really_long_variable \
        if another_really_long_variable == .ReallyLongEnum \
        else .AnotherReallyLongEnum
}

Which does not compile for me:

/game.odin(15:9) Syntax Error: Expected '{', got 'else'
        else .AnotherReallyLongEnum
        ^
/game.odin(15:14) Syntax Error: Expected a statement, got '.'
        else .AnotherReallyLongEnum
             ^
/game.odin(17:0) Syntax Error: Expected '}', got 'EOF'

        ^

I am using the following:

Odin: odin version dev-2024-05:17a01a81d OLS: built from commit 49a6347 My ols.json:

{
  "$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/ols.schema.json",
  "collections": [
    {
      "name": "src",
      "path": "src"
    },
    {
      "name": "sokol-odin",
      "path": "libs/sokol-odin"
    }
  ],
  "profile": "default",
  "profiles": [{ "name": "default", "checker_path": ["src", "libs"] }],
  "checker_args": "-vet -strict-style",
  "enable_format": true,
  "enable_semantic_tokens": true,
  "enable_document_symbols": true,
  "enable_hover": true,
  "enable_snippets": false,
  "enable_procedure_snippet": false,
  "enable_inlay_hints": false,
  "enable_references": true,
  "enable_fake_methods": false,
  "enable_checker_only_saved": true
}