obiwan87 / odin-intellij

Odin Support plugin for JetBrains IDEs
https://plugins.jetbrains.com/plugin/22933-odin-support
MIT License
37 stars 2 forks source link

Fix reformatting issues with comments and imports #64

Open Dima-369 opened 1 month ago

Dima-369 commented 1 month ago

1. Too many newlines inserted without any import statements (presumably where the imports would be)

package main

main :: proc() {

}

reformats to:

package main

main :: proc() {

}

2. Comments to a proc are indented incorrectly with too much prefix

package main

...

// hey there
// foo
main :: proc() {

}

results in:

    // hey there
    // foo
main :: proc() {

}

You can try to reformat /opt/homebrew/Cellar/odin/2024-07/libexec/core/fmt/fmt_os.odin which ends up like this with all the indentation being off:

  //+build !freestanding
    //+build !js
    //+build !orca
  package fmt

  import "base:runtime"
  import "core:bufio"
  import "core:io"
  import "core:os"
    // fprint formats using the default print settings and writes to fd
  fprint :: proc(fd: os.Handle, args: ..any, sep := " ", flush := true) -> int {
    buf: [1024]byte
    b: bufio.Writer
    defer bufio.writer_flush(&b)

    bufio.writer_init_with_buf(&b, os.stream_from_handle(fd), buf[:])
    w := bufio.writer_to_writer(&b)
    return wprint(w, ..args, sep=sep, flush=flush)
  }

    // fprintln formats using the default print settings and writes to fd
  fprintln :: proc(fd: os.Handle, args: ..any, sep := " ", flush := true) -> int {
obiwan87 commented 1 month ago

I have now removed comment indentation. But now the problem should be that comments inside blocks are not indented with what is inside blocks. E.g:

Put a comment inside a procedure block and reformat. The comment will not be indented. Working on it

obiwan87 commented 1 month ago

Blank lines after optimizing imports and/or reformatting code is now fixed

Dima-369 commented 1 month ago

Here is still one weird case:

Before:

package main

import "core:os"

// oeu
foo :: proc() {
    os.exit(1)
}

// foo
main :: proc() {
}

After, the comment to the first proc under the imports always shifts up:

package main

import "core:os"
// oeu

foo :: proc() {
    os.exit(1)
}

// foo
main :: proc() {
}