Force new line if the whitespace between comments doesn't have a line break
Tweeking KEEP_FIRST_COLUMN_COMMENT setting and one-line comments generated on the same line. #KT-4175 In Progress
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.formatting.Spacing
|
||||
import com.intellij.formatting.SpacingBuilder
|
||||
import com.intellij.formatting.SpacingBuilder.RuleBuilder
|
||||
import com.intellij.lang.ASTNode
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings
|
||||
import com.intellij.psi.formatter.FormatterUtil
|
||||
import com.intellij.psi.tree.IElementType
|
||||
@@ -289,6 +290,17 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
|
||||
}
|
||||
|
||||
if (kotlinCommonSettings.KEEP_FIRST_COLUMN_COMMENT) {
|
||||
inPosition(parent = null, left = EOL_COMMENT, right = EOL_COMMENT).customRule { parent, left, right ->
|
||||
val nodeBeforeRight = right.node.treePrev
|
||||
if (nodeBeforeRight is PsiWhiteSpace && !nodeBeforeRight.textContains('\n')) {
|
||||
// Several line comments happened to be generated in one line
|
||||
Spacing.createSpacing(1, 0, 1, settings.KEEP_LINE_BREAKS, settings.KEEP_BLANK_LINES_IN_CODE)
|
||||
}
|
||||
else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
inPosition(rightSet = TokenSet.create(EOL_COMMENT, BLOCK_COMMENT)).spacing(
|
||||
Spacing.createKeepingFirstColumnSpacing(0, Integer.MAX_VALUE, settings.KEEP_LINE_BREAKS, kotlinCommonSettings.KEEP_BLANK_LINES_IN_CODE))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user