Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crystal tool format no-op if indentation error on macro #12164

Closed
zw963 opened this issue Jun 26, 2022 · 2 comments · Fixed by #12378
Closed

crystal tool format no-op if indentation error on macro #12164

zw963 opened this issue Jun 26, 2022 · 2 comments · Fixed by #12378
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter

Comments

@zw963
Copy link
Contributor

zw963 commented Jun 26, 2022

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 zw963 added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Jun 26, 2022
@asterite
Copy link
Member

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.

@zw963
Copy link
Contributor Author

zw963 commented Aug 11, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants