abrookins / WrapToColumn

An IntelliJ plugin that wraps text
Apache License 2.0
62 stars 12 forks source link

Regression: Python docstrings fail wrapping #65

Open edgarsi opened 1 month ago

edgarsi commented 1 month ago

The new version wrapping Python docstrings adds * prefix to lines, if the comment starts on the docstring line.

Input:

def a():
    """ a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a """

Output:

def a():
    """ a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
     * a a a a """

Looks like it is added by this ancient hack makes sense for C-style comments but not for Python i.e. not if firstLineIsDocstring.

            if (i > 0 && firstLineIsCommentOpener) {
                // This is a hack. We don't know how much whitespace to use!
                lineIndent = "$whitespaceBeforeOpener * "
            }

Fix:

            if (i > 0 && firstLineIsCommentOpener && !firstLineIsDocstring) {
                // This is a hack. We don't know how much whitespace to use!
                lineIndent = "$whitespaceBeforeOpener * "
            }

Wrapping (at least Wrap Line to Column) was not adding these asterix in earlier versions, though you'll have a better understanding of why it was so. I'm not making a pull request because of this unclarity.

kristaps4 commented 1 month ago

Experiencing the same issue. PyCharm version: 2024.2.1. Plugin version: 1.9.1.

idenisovs commented 1 month ago

I have the same issue in IntelliJ IDEA 2024.2.2 with Python plugin (242.22855.74) and Wrap To Column plugin 1.9.1

rogerdahl commented 2 weeks ago

@edgarsi You say "ancient hack", but this is a recent regression... Could you elaborate?

edgarsi commented 2 weeks ago

@rogerdahl Recent versions unified much of the line wrapping and paragraph wrapping code. This C hack was not called before, at least not for line wrapping. I'm 95% sure this hack still makes sense after unification, but it needs the fix proposed.