snakecharm
snakecharm copied to clipboard
Code indentation fix in rules
Code indentation fix in rules for new line after:
- rule name declaration
- rule parameter name
yes please.
:)
Now next line is aligned relative to ':' and no line continuation is inserted. I think better to align rule parameter values relative to rule parameter name start pos + indent, but not clear how to fix this at the moment.
Hey, I am not sure I understand everything, but this looks like it might be useful!
Just to re-iterate what I would expect to happen: On a line that ends with a colon, when I hit enter, my cursor is sent to the next line and indented by four spaces compared to the previous line.
Let me show you an example:
rule all:
wildcard_constraints:<caret> fooo=".*"
After my previous commit. If you press 'Enter', you will get
rule all:
wildcard_constraints:
<caret>fooo=".*"
instead of
rule all:
wildcard_constraints:\
<caret>fooo=".*"
On a line that ends with a colon, when I hit enter, my cursor is sent to the next line and indented by four spaces compared to the previous line.
Yes, agree, I'd like to get:
rule all:
wildcard_constraints:
<caret>fooo=".*"
P.S: Example updated, the initial version was incorrect
Hmmm, that may be worse than before?
I think not worse because we don't need '\' here and moving caret back to prev line to delete '\' is more annoying.
Hmm, currently when I start with this:
rule all:
wildcard_constraints:<caret>
and hit enter, I get this:
rule all:
wildcard_constraints:
<caret>
I then have to hit space four times to get a sensible indent. Am I on an outdated version of the plugin?
Ok, correct my minimal example was too minimal, indeed for
rule all:
wildcard_constraints:<caret>
you will get
rule all:
wildcard_constraints:
<caret>
I was talking about the case:
rule all:
wildcard_constraints:<caret> fooo=".*"
or
rule all:
wildcard_constraints:<caret>
fooo=".*"
When I want to add new param to the existing single line definition, I don't want to get \
char on Enter
rule all:
wildcard_constraints: \
fooo=".*"
And the desired behavior should be
rule all:
wildcard_constraints:
fooo=".*"
At the moment I've implemented a partial fix which doesn't insert line continuation \
, but unfortunately aligns text relatively to ':'
rule all:
wildcard_constraints:
<caret>fooo=".*"
Ah! Yes, that's an improvement :D
@winni2k Updated plugin is available in JetBrains Plugins Repository and could be installed using Preferences|Plugins
Just a bit of feedback on our conversation above: I've started using this version of the plugin, and I love that the code -> reformat code
option now works!
I am still quite happy with this plugin, but I have a request for an improvement:
When I use code -> reformat code
on the this code (note the indentation of two spaces before """cats"""):
rule bla:
shell:
"""cats"""
then the code is reformatted as:
rule bla:
shell:
"""cats"""
with an indentation of five spaces.
I see this happening a lot. Is there any way to constrain the indents to be four spaces?
@winni2k At the moment you cannot change that. You get 5 space indentation because """cats"""
is aligned relative to shell
keyword end offset. I also don't like that section arguments get different indentation depending on it's section name length (e.g. resources
vs input
)
This issue is likely to be connected with #16. Snakemake language support reuses parts of Python
plugin parser and code formater and at some points we cannot tune python
code formatter to process snakemake
syntax in the way which we want.
We are going to work on these 2 issues during this summer.
Hi! Any progress on this?
@lpla Yes, there is some progress, you can configure the formatter to keep constant indent independent on section keyword length. To do this:
- Uncheck checkbox
PyCharm | Preferences | Editor | Code Style | Python | Wrapping and Braces | Method call args | Align when multiline
Then instead of
reformat code will behave like:
The formatter is still not ideal, but to my mind, it works quite ok and this issue isn't critical at the moment.
Thanks for the workaround! This has been driving me insane.
Related API docs - https://www.jetbrains.org/intellij/sdk/docs/reference_guide/custom_language_support/code_formatting.html
We need own formatting model builder base extending com.jetbrains.python.formatter.PythonFormattingModelBuilder
and com.jetbrains.python.formatter.PyBlock
. E.g. add support for Snakemake specific PSI + change some rules for py arg lists inside snakemake sections
Also we want to get Uncheck checkbox PyCharm | Preferences | Editor | Code Style | Python | Wrapping and Braces | Method call args | Align when multiline
behaviour w/o modifiying python formatting settings.
See tests examples in PyFormatterTest
Snakemake specific codestyle settings paged added in coming 0.9.0