tnorbye/kdoc-formatter

Edge case with annotations

Opened this issue · 3 comments

I have code like below that has an annotation above the comment because I need to suppress spell checking in the comment. If I
do that the the comment is indented 8 spaces (continuation indentation). This happens on a function, not a class. All of the rest of the code and comments are indented properly.

@Suppress("SpellCheckingInspection")
        /**
         * Lorem ipsum dolor sit amet, consectetur adipiscing elit.
         */
fun KDocFormatterTest() {
}

I can't reproduce this. Can you say more about how to reproduce it? Was it in the IDE, or from the command line? (I did fix a bug recently where the formatter misbehaved if the kdoc comment starts at the end of a line (E.g. there is non-whitespace on the beginning line of the comment) but that doesn't seem to be the case here.

It was in an IDE (IntelliJ) as I do all of my work there. I have never tried the command line (my mistake I should have before reporting). I will try it again and also from the command line.

I see! In the IDE, this plugin doesn't decide where the comment itself gets indented; it only reformats the internal contents within the comment; the actual indentation of where the comment is located is decided by the Kotlin plugin formatter.

The same is (almost) the case for the command line formatter. It doesn't try to format/reindent any non-comment elements; only the comment. (However, if the comment is at the ending of a line with code on it, and it cannot fit the comment fully on the line, then it does go and push the whole comment to the next line (by reusing the indentation it finds there (well, in the next version anyway)); that's the only time when it actually affects where the comment itself is indented.