erlang / sourcer

An Erlang language server, providing IDE services.
Apache License 2.0
122 stars 19 forks source link

Elvis integration? #14

Open deadtrickster opened 6 years ago

deadtrickster commented 6 years ago

Elvis is the Erlang style reviewer (https://github.com/inaka/elvis).

Many use elvis to enforce code style (me included). There are rules related to text formatting, such as:

I would like to have sourcer_indent integrated with elvis, i.e. understand formatting specific rules and apply them (e.g. add space after ,).

vladdu commented 6 years ago

That's a good idea - I assume you mean that we could autocorrect some style issues that elvis reports, using elvis.config as guide/config? It's definitely a useful feature.

This will be something for later (for what I am concerned, I want to get the server going first). The code formatter right now is actually an indenter only, as we don't break any lines. Breaking lines at the right place is not very easy to do right.

As long as we don't have a full formatter, I would probably do these fixes as a separate command. If elvis is integrated in the editor/IDE, then the user can choose a "quick fix" operation for each one (or each type) and see and review the results right away.

deadtrickster commented 6 years ago

ok, I'll do this as a separate command, maybe reusing some of (or depending on) the elvis core (https://github.com/inaka/elvis_core). What you think? something like erlang_ls -i --elvis.

vladdu commented 6 years ago

There should be some configuration to specify which fixes to apply (to which elvis rules). Maybe "--elvis" to use info in config file and "--elvis ruleX,ruleY" will correct only ruleX and ruleY.

This functionality is in a bit of gray zone: elvis could just as well have a "--fix" parameter that would make the corrections. I don't think that the implementation will make use of any sourcer-specific code.

deadtrickster commented 6 years ago

I agree, at least right now adding this directly to elvis might be a better idea.

I was trying to study indenter code a bit more, but there lots of things are going on. Any documentation/blog post? In theory if it's building AST, then said AST could be dumped as text following configured formatting rules. I feel like indenter and elvis probably overlap here to some extent.

vladdu commented 6 years ago

Sorry, there is no documentation but the code. I didn't wrote any of it, so I confess I don't know much about how it works. I don't think it parses into an AST, because then we could have had a full formatter (like erl_tidy) and also it would only have worked on compileable code (which when editing is not always the case). I think it uses empiric rules and looks at the previous row to decide how to indent the current one (a bit simplified, of course).