From ed26a995139f8a59e82d5fa4e694265593d9bd09 Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Thu, 12 Dec 2024 19:14:44 +0100 Subject: [PATCH] [formatter] do not merge scala directive tokens starting with dot #SCL-23326 fixed --- .../processors/ScalaSpacingProcessor.scala | 5 +++-- .../tests/ScalaDirectiveFormattingTest.scala | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/formatting/processors/ScalaSpacingProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/formatting/processors/ScalaSpacingProcessor.scala index fedf6278b1d..b4a01179316 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/formatting/processors/ScalaSpacingProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/formatting/processors/ScalaSpacingProcessor.scala @@ -15,7 +15,7 @@ import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.TokenSets import org.jetbrains.plugins.scala.lang.formatting.ScalaBlock import org.jetbrains.plugins.scala.lang.formatting.settings.ScalaCodeStyleSettings -import org.jetbrains.plugins.scala.lang.lexer.{ScalaKeywordTokenType, ScalaTokenType, ScalaTokenTypes, ScalaTokenTypesEx, ScalaXmlTokenTypes} +import org.jetbrains.plugins.scala.lang.lexer.{ScalaTokenType, ScalaTokenTypes, ScalaTokenTypesEx, ScalaXmlTokenTypes} import org.jetbrains.plugins.scala.lang.parser.{ScCodeBlockElementType, ScalaElementType} import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.base._ @@ -39,6 +39,7 @@ import org.jetbrains.plugins.scala.lang.scaladoc.parser.ScalaDocElementTypes import org.jetbrains.plugins.scala.lang.scaladoc.psi.api.ScDocComment import org.jetbrains.plugins.scala.util.MultilineStringUtil import org.jetbrains.plugins.scalaDirective.lang.parser.ScalaDirectiveElementTypes +import org.jetbrains.plugins.scalaDirective.psi.api.ScDirectiveToken import scala.annotation.{nowarn, tailrec} @@ -1057,7 +1058,7 @@ object ScalaSpacingProcessor extends ScalaTokenTypes { if (rightBlockString.startsWith(".") && rightElementType != ScalaTokenType.Float && rightElementType != ScalaTokenType.Double && - !rightPsi.isInstanceOf[ScLiteral]) { + !rightPsi.is[ScLiteral, ScDirectiveToken]) { return WITHOUT_SPACING } if (rightBlockString.startsWith(",")) { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/formatter/intellij/tests/ScalaDirectiveFormattingTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/formatter/intellij/tests/ScalaDirectiveFormattingTest.scala index fc0a80cc6a1..9ed18ca52d4 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/formatter/intellij/tests/ScalaDirectiveFormattingTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/formatter/intellij/tests/ScalaDirectiveFormattingTest.scala @@ -102,4 +102,16 @@ class ScalaDirectiveFormattingTest extends AbstractScalaFormatterTestBase { |// Foo |""".stripMargin ) + + // SCL-23326 + def test_do_not_merge_tokens_starting_with_dot(): Unit = doTextTest( + """ + |//> using file ../common/util.scala + |//> using file ../common/util.scala + |""".stripMargin, + """ + |//> using file ../common/util.scala + |//> using file ../common/util.scala + |""".stripMargin + ) }