Git Product home page Git Product logo

Comments (19)

iromeo avatar iromeo commented on May 29, 2024 3

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

from snakecharm.

iromeo avatar iromeo commented on May 29, 2024 2

Snakemake specific codestyle settings paged added in coming 0.9.0
image

from snakecharm.

iromeo avatar iromeo commented on May 29, 2024 1

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

from snakecharm.

winni2k avatar winni2k commented on May 29, 2024

yes please.

from snakecharm.

winni2k avatar winni2k commented on May 29, 2024

:)

from snakecharm.

iromeo avatar iromeo commented on May 29, 2024

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.

from snakecharm.

winni2k avatar winni2k commented on May 29, 2024

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.

from snakecharm.

iromeo avatar iromeo commented on May 29, 2024

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

from snakecharm.

winni2k avatar winni2k commented on May 29, 2024

Hmmm, that may be worse than before?

from snakecharm.

iromeo avatar iromeo commented on May 29, 2024

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

from snakecharm.

winni2k avatar winni2k commented on May 29, 2024

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?

from snakecharm.

iromeo avatar iromeo commented on May 29, 2024

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

from snakecharm.

winni2k avatar winni2k commented on May 29, 2024

Ah! Yes, that's an improvement :D

from snakecharm.

iromeo avatar iromeo commented on May 29, 2024

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

from snakecharm.

winni2k avatar winni2k commented on May 29, 2024

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!

from snakecharm.

winni2k avatar winni2k commented on May 29, 2024

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?

from snakecharm.

lpla avatar lpla commented on May 29, 2024

Hi! Any progress on this?

from snakecharm.

winni2k avatar winni2k commented on May 29, 2024

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

from snakecharm.

iromeo avatar iromeo commented on May 29, 2024

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

from snakecharm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.