Skip to content

Commit

Permalink
Making newlines os-independent by correcting stripMargin behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsalathe committed Sep 23, 2023
1 parent 19e123e commit 4127d96
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ class SDLBCompletionEngineImpl(private val schemaReader: SchemaReader) extends S
val keyName = if templateType == TemplateType.OBJECT then s"${actionType.toLowerCase}_PLACEHOLDER" else ""
val startObject = if templateType != TemplateType.ATTRIBUTES then "{" else ""
val endObject = if templateType != TemplateType.ATTRIBUTES then "}" else ""
val newLine = sys.props("line.separator") // Useful to permit to package the LSP independently of the platform
completionItem.setInsertText( //TODO handle indentation
s"""$keyName $startObject
|${
def generatePlaceHolderValue(att: SchemaItem) = {
if att.name == "type" then actionType else att.itemType.defaultValue
}
attributes.map(att => "\t\t" + att.name + " = " + generatePlaceHolderValue(att)).mkString(newLine)}$newLine\t$endObject
|""".stripMargin) //TODO remove blank lines?
attributes.map(att => "\t\t" + att.name + " = " + generatePlaceHolderValue(att)).mkString("\n")}\n\t$endObject
|""".stripMargin.replace("\r\n", "\n")) //TODO remove blank lines?
completionItem.setKind(CompletionItemKind.Snippet)
completionItem
}.toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SchemaReaderImpl(val schemaPath: String) extends SchemaReader {

private val logger = LoggerFactory.getLogger(getClass)
private val schema = ujson.read(Using.resource(getClass.getClassLoader.getResourceAsStream(schemaPath)) { inputStream =>
Source.fromInputStream(inputStream).getLines().mkString(sys.props("line.separator")).trim
Source.fromInputStream(inputStream).getLines().mkString("\n").trim
})


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object MultiLineTransformer {

def flattenMultiLines(text: String): String =
val pattern = raw"""(?s)\"\"\".*?\"\"\"""".r
pattern.replaceAllIn(text, m => m.matched.replace(sys.props("line.separator"), ""))
pattern.replaceAllIn(text, m => m.matched.replace("\n", ""))


def computeCorrectedPosition(text: String, lineNumber: Int, columnNumber: Int): (Int, Int) =
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/io/smartdatalake/UnitSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import scala.util.Using
abstract class UnitSpec extends AnyFlatSpec with should.Matchers with OptionValues with Inside with Inspectors with TestModule:
def loadFile(filePath: String): String =
Using.resource(getClass.getClassLoader.getResourceAsStream(filePath)) { inputStream =>
Source.fromInputStream(inputStream).getLines().mkString(sys.props("line.separator")).trim
Source.fromInputStream(inputStream).getLines().mkString("\n").trim
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SDLBHoverEngineSpec extends UnitSpec {
val expected =
"""Configuration of a custom Spark-DataFrame transformation between many inputs and many outputs (n:m).
|Define a transform function which receives a map of input DataObjectIds with DataFrames and a map of options and has
|to return a map of output DataObjectIds with DataFrames, see also trait[[CustomDfsTransformer]] .""".stripMargin
|to return a map of output DataObjectIds with DataFrames, see also trait[[CustomDfsTransformer]] .""".stripMargin.replace("\r\n", "\n")
hoverEngine.generateHoveringInformation(context).getContents.getRight.getValue shouldBe expected //TODO more tests
}

Expand Down

0 comments on commit 4127d96

Please sign in to comment.