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

Code indentation fix in rules #26

Open
iromeo opened this issue Jan 11, 2019 · 19 comments
Open

Code indentation fix in rules #26

iromeo opened this issue Jan 11, 2019 · 19 comments
Labels
formatter Code formatter

Comments

@iromeo
Copy link
Contributor

iromeo commented Jan 11, 2019

Code indentation fix in rules for new line after:

  • rule name declaration
  • rule parameter name
@iromeo iromeo added the formatter Code formatter label Jan 11, 2019
@iromeo iromeo self-assigned this Jan 11, 2019
@winni2k
Copy link

winni2k commented Jan 12, 2019

yes please.

@winni2k
Copy link

winni2k commented Jan 12, 2019

:)

iromeo added a commit that referenced this issue Feb 3, 2019
…ion is inserted, by next line is aligned relatively to ':'
@iromeo
Copy link
Contributor Author

iromeo commented Feb 3, 2019

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.

@winni2k
Copy link

winni2k commented Feb 4, 2019

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.

@iromeo
Copy link
Contributor Author

iromeo commented Feb 4, 2019

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

@winni2k
Copy link

winni2k commented Feb 4, 2019

Hmmm, that may be worse than before?

@iromeo
Copy link
Contributor Author

iromeo commented Feb 4, 2019

I think not worse because we don't need '\' here and moving caret back to prev line to delete '\' is more annoying.

@winni2k
Copy link

winni2k commented Feb 4, 2019

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?

@iromeo
Copy link
Contributor Author

iromeo commented Feb 4, 2019

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=".*"

@winni2k
Copy link

winni2k commented Feb 4, 2019

Ah! Yes, that's an improvement :D

@iromeo
Copy link
Contributor Author

iromeo commented Feb 4, 2019

@winni2k Updated plugin is available in JetBrains Plugins Repository and could be installed using Preferences|Plugins

@winni2k
Copy link

winni2k commented Feb 12, 2019

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!

@winni2k
Copy link

winni2k commented Jun 26, 2019

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?

@iromeo
Copy link
Contributor Author

iromeo commented Jun 27, 2019

@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.

@iromeo iromeo added the major label Jun 27, 2019
@lpla
Copy link

lpla commented Dec 4, 2019

Hi! Any progress on this?

@iromeo
Copy link
Contributor Author

iromeo commented Dec 4, 2019

@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

image

Then instead of
image

reformat code will behave like:
image

The formatter is still not ideal, but to my mind, it works quite ok and this issue isn't critical at the moment.

@winni2k
Copy link

winni2k commented Dec 4, 2019

Thanks for the workaround! This has been driving me insane.

@iromeo iromeo added this to the Backlog milestone Jul 3, 2020
@iromeo iromeo removed their assignment Jul 3, 2020
@iromeo iromeo modified the milestones: Backlog, 0.8.x Jul 9, 2020
@iromeo
Copy link
Contributor Author

iromeo commented Jul 13, 2020

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

@iromeo iromeo modified the milestones: 0.8.x, 0.8.1 Jul 13, 2020
@iromeo
Copy link
Contributor Author

iromeo commented Dec 15, 2020

Snakemake specific codestyle settings paged added in coming 0.9.0
image

@iromeo iromeo removed this from the 0.9.0 milestone Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Code formatter
Projects
None yet
Development

No branches or pull requests

3 participants