From bcba92084748e8124a1c74fd255280dbc3db729f Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Wed, 30 Oct 2024 17:54:31 +0100 Subject: [PATCH] bugfix: When determining indent first check for pipe Fixes https://github.com/scalameta/metals/issues/6798 --- .../metals/formatting/MultilineString.scala | 4 +++- ...ineStringRangeFormattingWhenPastingSuite.scala | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/formatting/MultilineString.scala b/metals/src/main/scala/scala/meta/internal/metals/formatting/MultilineString.scala index 20d18535328..44d75db4eeb 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/formatting/MultilineString.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/formatting/MultilineString.scala @@ -60,9 +60,11 @@ case class MultilineString(userConfig: () => UserConfiguration) val index = if (lineToCheck.contains("\"\"\"|")) { lineToCheck.indexOf('"') + 3 + } else if (lineToCheck.contains("|")) { + lineToCheck.indexOf('|') } else if (lineToCheck.contains("\"\"\"")) { lineToCheck.indexOf('"') + 2 - } else lineToCheck.indexOf('|') + } else 0 space * index } diff --git a/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala b/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala index d2e72d470c0..f3cf74ec180 100644 --- a/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala +++ b/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala @@ -339,6 +339,19 @@ class MultilineStringRangeFormattingWhenPastingSuite |}""".stripMargin, ) + check( + "i6798", + s"""|val x = + | s'''|Hello + | |Good@@'''.stripMargin + |}""".stripMargin, + "bye", + s"""|val x = + | s'''|Hello + | |Goodbye'''.stripMargin + |}""".stripMargin, + ) + def check( name: TestOptions, testCase: String, @@ -358,7 +371,7 @@ class MultilineStringRangeFormattingWhenPastingSuite s"""/metals.json |{"a":{}} |/a/src/main/scala/a/Main.scala - """.stripMargin + base + |""".stripMargin + base ) _ <- server.didOpen("a/src/main/scala/a/Main.scala") _ <- server.rangeFormatting(