WrapToColumn icon indicating copy to clipboard operation
WrapToColumn copied to clipboard

Regression: Python docstrings fail wrapping

Open edgarsi opened this issue 1 year ago • 7 comments

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.

edgarsi avatar Sep 24 '24 06:09 edgarsi

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

kristaps4 avatar Sep 24 '24 09:09 kristaps4

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

idenisovs avatar Sep 30 '24 13:09 idenisovs

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

rogerdahl avatar Nov 02 '24 02:11 rogerdahl

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

edgarsi avatar Nov 02 '24 07:11 edgarsi

I would also really like this to be fixed! Definitely bugging me in python code. Also the new version's settings page gets stuck on the loading spinner for me.

JamesB797 avatar Nov 19 '24 18:11 JamesB797

@edgarsi Maybe you should just do that PR? Wrapping in Python is already broken and it seems unlikely that it will break things even more, given that only Python has docstrings.

rogerdahl avatar Nov 20 '24 02:11 rogerdahl

#66

The bug was deeper than initially guessed.

edgarsi avatar Nov 23 '24 23:11 edgarsi