KronicDeth / intellij-elixir

Elixir plugin for JetBrain's IntelliJ Platform (including Rubymine)
Other
1.84k stars 154 forks source link

Code Formatter #98

Closed KronicDeth closed 7 years ago

KronicDeth commented 9 years ago

Use guide to write formatter to reformat code to some style. Find out if there is a style-guide for Elixir yet or just copy @pragdave's style from his books.

KronicDeth commented 8 years ago

@smeevil you wanted this too, right?

smeevil commented 8 years ago

Oh yes ! 9configurable) reformat document would be very welkome :)

acrolink commented 8 years ago

I agree, this is the last missing piece of this great language and plugin .. Currently there are no online tools, notepad++ plugins etc. for this purpose.

zapient commented 8 years ago

+1

joshuataylor commented 8 years ago

Following https://github.com/levionessa/elixir_style_guide would be a good idea - 1400 stars, active community.

dhonig commented 8 years ago

👍

ghost commented 7 years ago

👍

stevepm commented 7 years ago

👍

philippearnaud commented 7 years ago

👍

timigod commented 7 years ago

👍

mkuznetsov commented 7 years ago

Looks like formatting is not working. I used 4.7.0 and still no code style preset in editor and no code formatting. Sad. Are there some hack to activate it for at least so basic elements like modules, functions and cond operators. Erlang plugin struggle for a long time with good one, but basic things they did fast.

KronicDeth commented 7 years ago

@mkuznetsov, the issue is still open, if the issue were closed it would indicate the feature was complete and a PR implementing it had been merged to master. What led you to believe 4.7.0 would included the feature?

KronicDeth commented 7 years ago

Currently stuck on https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000192950-Extra-blankline-for-custom-formatter-when-different-value-used-for-indent-align-do-end-blocks-to-call

KronicDeth commented 7 years ago

I found an ExtensionPoint called PredefinedCodeStyle, which looks like it may allow the plugin to define multiple styles, so both "The Elixir Style Guide" and "Credo's Elixir Style Guide" could be shipped and selectable.

smeevil commented 7 years ago

That's really nice :)

PhillippOhlandt commented 7 years ago

Hey,

just asked myself it it is possible to format the code like with supported IDE languages. Great to see some activity here recently. So this will come in the near future?

KronicDeth commented 7 years ago

@PhillippOhlandt this is my active issue. I forgot to mark it as assigned to me.

PhillippOhlandt commented 7 years ago

@KronicDeth Awesome! No more manual switching from 2 space indent to 4 space indent when copying from the docs soon :P

johannesE commented 7 years ago

FYI: At elixirconfeu, Jose presented the idea of elixirfmt. https://github.com/beamcommunity/beamcommunity.github.com/wiki/Project:-Elixir

Implement a formatter for Elixir code that can take a piece of Elixir code and format it according to a standard style guide. Very similar to tools such as rustfmt and gofmt. Expected results: a command-line tool that takes Elixir code as input and returns formatted Elixir code as output

KronicDeth commented 7 years ago

@mudasobwa told me about elixirfmt already. To summarize the thread, just like using alchemist-server, which many people suggested before I implemented all the references for Go To Declaration, the problem is the tools written in Elixir usually depend on the elixir lexer (tokenizer) and/or parser to get them an AST, so the code has to be valid Elixir code before it works.

I'm of the opinion that IDEs need to be more forgiving than compiler parsers of user mistakes and work while you're still typing code (which also looks like mistakes), so I prefer to use the JetBrains OpenAPI system available to plugins because I can format (and highlight and annotate) code that has syntax errors while I doubt elixirfmt will be able to do that.

KronicDeth commented 7 years ago

Found a new bug in the native grammar while splitting not from ! (since not needs a spaces and ! does not, but they're both unary operators in the native and current IntelliJ elixir grammar): https://groups.google.com/d/msg/elixir-lang-core/aZ7KkHrAVzc/g2oA1-6rAQAJ

KronicDeth commented 7 years ago

Bug from https://groups.google.com/d/msg/elixir-lang-core/aZ7KkHrAVzc/g2oA1-6rAQAJ fixed in https://github.com/elixir-lang/elixir/commit/9747e58db773c716c01c210642ec1d91475e0c83