in scala-interpreter/src/main/scala-2.12/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala [320:343]
override def isComplete(code: String): (String, String) = {
val result = iMain.beSilentDuring {
val parse = iMain.parse
parse(code) match {
case t: parse.Error => ("invalid", "")
case t: parse.Success =>
val lines = code.split("\n", -1)
val numLines = lines.length
// for multiline code blocks, require an empty line before executing
// to mimic the behavior of ipython
if (numLines > 1 && lines.last.matches("\\s*\\S.*")) {
("incomplete", startingWhiteSpace(lines.last))
} else {
("complete", "")
}
case t: parse.Incomplete =>
val lines = code.split("\n", -1)
// For now lets just grab the indent of the current line, if none default to 2 spaces.
("incomplete", startingWhiteSpace(lines.last))
}
}
lastResultOut.reset()
result
}