Skip to content

Commit 075b1e0

Browse files
authored
bugfix: Fix issue with not adding | in the last line (#7880)
Fixes #7873
1 parent c90ae93 commit 075b1e0

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

metals/src/main/scala/scala/meta/internal/metals/formatting/MultilineString.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,18 @@ case class MultilineString(userConfig: () => UserConfiguration)
290290
Some(textEdit)
291291
}
292292
case _ =>
293-
val isFirstLineOfMultiLine = lineText.trim.contains("\"\"\"")
294-
if (isFirstLineOfMultiLine) {
293+
val isBeforeOpeningQuotes = lineText.indexOf("\"\"\"") match {
294+
case -1 => false
295+
case idx =>
296+
val lastQuote = idx + 3
297+
lineText.indexOf("stripMargin", lastQuote) match {
298+
case -1 =>
299+
!lines.lift(line + 1).exists(_.trim.startsWith(".stripMargin"))
300+
case _ => false
301+
}
302+
}
303+
304+
if (isBeforeOpeningQuotes) {
295305
None
296306
} else {
297307
val newText = defaultIndent + "|"

tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,36 @@ class MultilineStringRangeFormattingWhenPastingSuite
343343
|}""".stripMargin,
344344
)
345345

346+
check(
347+
"paste-after-pipe",
348+
s"""|object Main {
349+
| val x = '''|@@'''.stripMargin
350+
|}""".stripMargin,
351+
s"""|Some
352+
|multiline
353+
|text""".stripMargin,
354+
s"""|object Main {
355+
| val x = '''|Some
356+
| |multiline
357+
| |text'''.stripMargin
358+
|}""".stripMargin,
359+
)
360+
361+
check(
362+
"paste-after-pipe2",
363+
s"""|object Main {
364+
| val x = '''|@@'''
365+
| .stripMargin
366+
|}""".stripMargin,
367+
s"""|Some
368+
|multiline
369+
|text""".stripMargin,
370+
s"""|object Main {
371+
| val x = '''|Some
372+
| |multiline
373+
| |text'''
374+
| .stripMargin
375+
|}""".stripMargin,
376+
)
377+
346378
}

0 commit comments

Comments
 (0)