crystal icon indicating copy to clipboard operation
crystal copied to clipboard

crystal tool format no-op if indentation error on macro

Open zw963 opened this issue 3 years ago • 2 comments

Bug Report

Following is a very simple example

# 1.cr
module SomeController
  macro included
    def hello
      puts "hello"
    end
      end           # <= this indentation is wrong.
end

when i run code like this:

$: crystal tool format 1.cr

because LSP use the advice come from compiler. as this issue. this make users with LSP enabled in editor, write code about macro, quite annoy.

version

 ╰─ $ cry version
Crystal 1.5.0-dev [ff55fb1bb] (2022-06-22)  # <= latest master.

LLVM: 13.0.1
Default target: x86_64-pc-linux-gnu

Arch linux.

zw963 avatar Jun 26 '22 18:06 zw963

I guess, if a macro consist exactly of a series of MacroLiterals but without any expressions in them, we could turn that into a String, parse it, then format it.

asterite avatar Jun 29 '22 12:06 asterite

Hi, any update for this?

i have to say, from my point of view, this is a big issue for me, it prevent my to use crystal tool format.

Because most of my web logic code is organized by ???_controller, but kemal is no way to do this, so, i have to use code like this.

# company_controller.cr

module Admin::CompanyController
  macro included
    get path.admin_company_index do |env|  # -------------------------------------------------------------------
       # many line code here ...
    end

    get path.admin_company do |env|
       # many line code here
    end
#                                                         all more than 60 lines code nested here could not format corrctly
    # many many code here

    delete path.admin_company_delete do |env|
      # many code here
    end
  end
end    # this file have 68 lines code. -----------------------------------------------------------------------------

Do you know where is the issue come from?

All more than 60 lines crystal code which nested in macro included, could not formatted automatially!

I have to add space manually to make code more neat, so, instead, the result is i never use format tools.

So, i consider this is a big issue.

Thank you.

zw963 avatar Aug 11 '22 05:08 zw963