-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Schema reader, completion engine and a demo
- Loading branch information
Showing
28 changed files
with
20,516 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10,111 changes: 10,111 additions & 0 deletions
10,111
src/main/resources/sdl-schema/sdl-schema-2.5.0.json
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/main/scala/io/smartdatalake/completion/SDLBCompletionEngine.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.smartdatalake.completion | ||
|
||
import io.smartdatalake.context.SDLBContext | ||
import org.eclipse.lsp4j.CompletionItem | ||
|
||
trait SDLBCompletionEngine: | ||
def generateCompletionItems(context: SDLBContext): List[CompletionItem] |
37 changes: 37 additions & 0 deletions
37
src/main/scala/io/smartdatalake/completion/SDLBCompletionEngineImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.smartdatalake.completion | ||
|
||
import io.smartdatalake.completion.SDLBCompletionEngine | ||
import io.smartdatalake.completion.schema.{ItemType, SchemaItem, SchemaReader, SchemaReaderImpl} | ||
import io.smartdatalake.context.SDLBContext | ||
import org.eclipse.lsp4j.{CompletionItem, CompletionItemKind} | ||
|
||
import scala.util.{Failure, Success, Try} | ||
|
||
class SDLBCompletionEngineImpl extends SDLBCompletionEngine { | ||
|
||
val schemaReader: SchemaReader = new SchemaReaderImpl("sdl-schema/sdl-schema-2.5.0.json") //TODO should be retrieved from a service keeping its state, object for example | ||
|
||
override def generateCompletionItems(context: SDLBContext): List[CompletionItem] = context.parentPath match | ||
case path if path.startsWith("actions") && path.count(_ == '.') == 1 => generatePropertiesOfAction(context) | ||
case path if path.startsWith("actions") && !path.contains('.') => List.empty[CompletionItem] //TODO discuss about this placeholder idea | ||
case path if path.startsWith("actions") => List.empty[CompletionItem] //TODO when going deeper find a good recursive approach and mb merge it with first case | ||
case _ => List.empty[CompletionItem] | ||
|
||
|
||
private def generatePropertiesOfAction(context: SDLBContext): List[CompletionItem] = | ||
val tActionType: Try[String] = Try(context.config.getString(context.parentPath + ".type")) | ||
tActionType match | ||
case Success(actionType) => schemaReader.retrieveActionProperties(actionType).map(createCompletionItem).toList | ||
case Failure(_) => typeList | ||
|
||
private def createCompletionItem(item: SchemaItem): CompletionItem = | ||
val completionItem = new CompletionItem() | ||
completionItem.setLabel(item.name) | ||
completionItem.setDetail(item.description) | ||
completionItem.setInsertText(item.name + (if item.itemType.isComplexValue then " " else " = ")) | ||
completionItem.setKind(CompletionItemKind.Snippet) | ||
completionItem | ||
|
||
private val typeItem = createCompletionItem(SchemaItem("type", ItemType.STRING, " type of object")) | ||
private val typeList = List(typeItem) | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/scala/io/smartdatalake/completion/schema/ItemType.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.smartdatalake.completion.schema | ||
|
||
enum ItemType(val name: String) { | ||
case STRING extends ItemType("string") | ||
case BOOLEAN extends ItemType("boolean") | ||
case INTEGER extends ItemType("integer") | ||
case OBJECT extends ItemType("object") | ||
case ARRAY extends ItemType("array") | ||
|
||
def isPrimitiveValue: Boolean = this == ItemType.STRING || this == ItemType.BOOLEAN || this == ItemType.INTEGER | ||
|
||
def isComplexValue: Boolean = this == ItemType.OBJECT || this == ItemType.ARRAY | ||
|
||
} | ||
|
||
object ItemType: | ||
def fromName(name: String): ItemType = name match | ||
case "string" => ItemType.STRING | ||
case "boolean" => ItemType.BOOLEAN | ||
case "integer" => ItemType.INTEGER | ||
case "object" => ItemType.OBJECT | ||
case "array" => ItemType.ARRAY |
3 changes: 3 additions & 0 deletions
3
src/main/scala/io/smartdatalake/completion/schema/SchemaItem.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.smartdatalake.completion.schema | ||
|
||
case class SchemaItem(name: String, itemType: ItemType, description: String) //TODO title as well? |
4 changes: 4 additions & 0 deletions
4
src/main/scala/io/smartdatalake/completion/schema/SchemaReader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package io.smartdatalake.completion.schema | ||
|
||
trait SchemaReader: | ||
def retrieveActionProperties(typeName: String): Iterable[SchemaItem] |
22 changes: 22 additions & 0 deletions
22
src/main/scala/io/smartdatalake/completion/schema/SchemaReaderImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.smartdatalake.completion.schema | ||
|
||
import scala.io.Source | ||
import scala.util.Using | ||
|
||
class SchemaReaderImpl(val schemaPath: String) extends SchemaReader { | ||
|
||
private val schema = ujson.read(Using.resource(getClass.getClassLoader.getResourceAsStream(schemaPath)) { inputStream => | ||
Source.fromInputStream(inputStream).getLines().mkString("\n").trim | ||
}) | ||
|
||
override def retrieveActionProperties(typeName: String): Iterable[SchemaItem] = | ||
val properties = schema("definitions")("Action")(typeName)("properties") | ||
|
||
properties.obj.map { case (keyName, value) => | ||
val typeName = value.obj.get("type").map(_.str).getOrElse("string") | ||
val description = value.obj.get("description").map(_.str).getOrElse("") | ||
SchemaItem(keyName, ItemType.fromName(typeName), description) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.