File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed
metals/src/main/scala/scala/meta/internal/metals/formatting
tests/unit/src/test/scala/tests/rangeFormatting Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff 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 + " |"
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments