Skip to content

Commit b9b8c5b

Browse files
kasiaMarektgodzik
authored andcommitted
fix: pc functions for multiline strings in worksheets in scala 3
1 parent a067026 commit b9b8c5b

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

metals/src/main/scala/scala/meta/internal/worksheets/WorksheetProvider.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,8 @@ object WorksheetProvider {
498498
originInput: Input.VirtualFile
499499
): Option[(Input.VirtualFile, AdjustLspData)] = {
500500
val ident = " "
501-
val withOuter = s"""|object worksheet{
502-
|$ident${originInput.value.replace("\n", "\n" + ident)}
503-
|}""".stripMargin
501+
val withOuter =
502+
s"""object worksheet{\n$ident${originInput.value.replace("\n", "\n" + ident)}\n}"""
504503
val modifiedInput =
505504
originInput.copy(value = withOuter)
506505
val adjustLspData = AdjustedLspData.create(

tests/unit/src/main/scala/tests/BaseWorksheetLspSuite.scala

+31
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,37 @@ abstract class BaseWorksheetLspSuite(
400400
} yield ()
401401
}
402402

403+
test("multi-line-string") {
404+
cleanWorkspace()
405+
val tripleQuotes = (1 to 3).map(_ => '"').mkString
406+
for {
407+
_ <- initialize(
408+
s"""|/metals.json
409+
|{"a": {"scalaVersion": "$scalaVersion"}}
410+
|/a/src/main/scala/Main.worksheet.sc
411+
|s${tripleQuotes}|# Spear $${2.max(1)}
412+
||smth: $${9.max(8)}
413+
||${tripleQuotes}.stripMargin
414+
|""".stripMargin
415+
)
416+
_ <- server.didOpen("a/src/main/scala/Main.worksheet.sc")
417+
_ = assertNoDiagnostics()
418+
max <- server.completion(
419+
"a/src/main/scala/Main.worksheet.sc",
420+
s"|smth: $${9.max@@",
421+
)
422+
// completions work despite error
423+
_ = assertNoDiff(
424+
max,
425+
s"""|max(that: Double): Double
426+
|max(that: Float): Float
427+
|max(that: Int): Int
428+
|max(that: Long): Long
429+
|""".stripMargin,
430+
)
431+
} yield ()
432+
}
433+
403434
test("update-classpath") {
404435
cleanWorkspace()
405436
for {

0 commit comments

Comments
 (0)