Skip to content

Commit

Permalink
Added test to cover hovering capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
dsalathe committed Sep 24, 2023
1 parent 4127d96 commit d5dc0eb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SDLBCompletionEngineImpl(private val schemaReader: SchemaReader) extends S
override def generateCompletionItems(context: SDLBContext): List[CompletionItem] =
val itemSuggestionsFromSchema = schemaReader.retrieveAttributeOrTemplateCollection(context) match
case AttributeCollection(attributes) => generateAttributeSuggestions(attributes, context.getParentContext)
case TemplateCollection(templates, templateType) => generateTemplateSuggestions(templates, templateType, context.isInList)
case TemplateCollection(templates, templateType) => generateTemplateSuggestions(templates, templateType)

val itemSuggestionsFromConfig = generateItemSuggestionsFromConfig(context)
val allItems = itemSuggestionsFromConfig ++ itemSuggestionsFromSchema //TODO better split schema and config suggestions
Expand All @@ -38,7 +38,7 @@ class SDLBCompletionEngineImpl(private val schemaReader: SchemaReader) extends S
case _ => attributes
items.map(createCompletionItem).toList

private[completion] def generateTemplateSuggestions(templates: Iterable[(String, Iterable[SchemaItem])], templateType: TemplateType, isInList: Boolean): List[CompletionItem] =
private[completion] def generateTemplateSuggestions(templates: Iterable[(String, Iterable[SchemaItem])], templateType: TemplateType): List[CompletionItem] =
templates.map { case (actionType, attributes) =>
val completionItem = new CompletionItem()
completionItem.setLabel(actionType.toLowerCase)
Expand Down
9 changes: 4 additions & 5 deletions src/main/scala/io/smartdatalake/context/SDLBContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.smartdatalake.utils.MultiLineTransformer

import scala.annotation.tailrec

case class SDLBContext private(textContext: TextContext, parentPath: List[String], word: String, isInList: Boolean) {
case class SDLBContext private(textContext: TextContext, parentPath: List[String], word: String) {

def withText(newText: String): SDLBContext = copy(textContext = textContext.update(newText))

Expand All @@ -23,8 +23,7 @@ case class SDLBContext private(textContext: TextContext, parentPath: List[String
val parentPath = oIndex match
case Some(index) => if isParentListKind then parentPathInitialList :+ index.toString else parentPathInitialList
case None => parentPathInitialList
val isInList = HoconParser.isInList(configText, newLine, newCol)
copy(parentPath = parentPath, word = word, isInList = isInList)
copy(parentPath = parentPath, word = word)


def getParentContext: Option[ConfigValue] =
Expand All @@ -41,9 +40,9 @@ case class SDLBContext private(textContext: TextContext, parentPath: List[String
}

object SDLBContext {
val EMPTY_CONTEXT: SDLBContext = SDLBContext(EMPTY_TEXT_CONTEXT, List(), "", false)
val EMPTY_CONTEXT: SDLBContext = SDLBContext(EMPTY_TEXT_CONTEXT, List(), "")

def fromText(originalText: String): SDLBContext = SDLBContext(TextContext.create(originalText), List(), "", false)
def fromText(originalText: String): SDLBContext = SDLBContext(TextContext.create(originalText), List(), "")

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private[context] object HoconParser:
if col > keyValSplit(0).length then
val keyName = keyValSplit(0).trim
@tailrec
def findValidDirectParentName(line: Int): Option[(Int, String)] = if line <= 0 then None else //TODO test
def findValidDirectParentName(line: Int): Option[(Int, String)] = if line <= 0 then None else
val textLine = text.split(Token.NEW_LINE_PATTERN, -1)(line-1).takeWhile(_ != Token.COMMENT).mkString
if textLine.isBlank then findValidDirectParentName(line-1) else
val words = textLine.filterNot(c => c == Token.START_LIST || c == Token.END_LIST || c == Token.START_OBJECT || c == Token.END_OBJECT || c == '=' || c == '"').split(" ")
Expand Down Expand Up @@ -148,7 +148,7 @@ private[context] object HoconParser:
case None => None
case Some((startPosition, endPosition)) =>
@tailrec
def buildObjectPositions(currentPosition: Int, currentList: List[(Int, Int)]): List[(Int, Int)] = //TODO unit test?
def buildObjectPositions(currentPosition: Int, currentList: List[(Int, Int)]): List[(Int, Int)] =
val nextStartObjectTokenRelativePosition = text.substring(currentPosition).indexOf(Token.START_OBJECT)
if nextStartObjectTokenRelativePosition == -1 then
currentList
Expand All @@ -174,9 +174,6 @@ private[context] object HoconParser:
private[hocon] def findObjectAreaFrom(text: String, position: Int): Option[(Int, Int)] = findAreaFrom(text, position, Token.START_OBJECT, Token.END_OBJECT)
private[hocon] def findListAreaFrom(text: String, position: Int): Option[(Int, Int)] = findAreaFrom(text, position, Token.START_LIST, Token.END_LIST)

def isInList(text: String, line: Int, column: Int): Boolean =
val absolutePosition = lineColToAbsolutePosition(text, line, column)
findListAreaFrom(text, absolutePosition).isDefined

private def findAreaFrom(text: String, position: Int, startToken: Char, endToken: Char): Option[(Int, Int)] =
@tailrec
Expand Down
28 changes: 27 additions & 1 deletion src/test/scala/io/smartdatalake/schema/SchemaContextSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,32 @@ class SchemaContextSpec extends UnitSpec {
attributes(3).required shouldBe true
}

//TODO add test for descriptions
// ===================================================================================================================

it should "generate a description for action" in {
val actionContext = actionSchemaContext.get
actionContext.getDescription shouldBe "Map of Action name and definition"
}

it should "generate a description for CopyAction" in {
val copyActionContext = specificActionSchemaContext.get
copyActionContext.getDescription.take(20) shouldBe "This[[Action]] copie"
}

it should "generate a description for metaData attribute" in {
val metadataContext = copyActionMetaDataSchemaContext.get
metadataContext.getDescription shouldBe "Additional metadata for an Action"
}

it should "generate a general description for executionMode without any defined type" in {
val globalExecutionModeContext = copyActionExecutionModeWithoutTypeSchemaContext.get
globalExecutionModeContext.getDescription shouldBe "optional execution mode for this Action"
}

it should "generate a precise description for executionMode with a defined type" in {
val dataFrameIncrementalModeContext = copyActionExecutionModeWithTypeSchemaContext.get
dataFrameIncrementalModeContext.getDescription.take(21) shouldBe "Compares max entry in"
}


}
16 changes: 12 additions & 4 deletions src/test/scala/io/smartdatalake/schema/SchemaReaderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,17 @@ class SchemaReaderSpec extends UnitSpec {

it should "remain quiet when path is wrong" in {
val context = initialContext.withCaretPosition(9, 4)
println(context.parentPath.appended(context.word))
println(schemaReader.retrieveDescription(context))
schemaReader.retrieveDescription(context) shouldBe empty
}

//TODO add tests for description

it should "find description of join-departures-airports as a CustomDataFrameAction object" in {
val context = initialContext.withCaretPosition(15, 5)
schemaReader.retrieveDescription(context).take(60) shouldBe "This[[Action]] transforms data between many input and output"
}

it should "find description of metadata" in {
val context = initialContext.withCaretPosition(31, 10)
schemaReader.retrieveDescription(context) shouldBe "Additional metadata for an Action"
}

}

0 comments on commit d5dc0eb

Please sign in to comment.