-
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.
Refactor context suggestions in ContextAdvisor + hovering stability i…
…mprovement + handling multiple opened files in the same time
- Loading branch information
Showing
13 changed files
with
109 additions
and
61 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
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.context | ||
|
||
trait ContextAdvisor: | ||
def generateSuggestions(context: SDLBContext): List[ContextSuggestion] |
26 changes: 26 additions & 0 deletions
26
src/main/scala/io/smartdatalake/context/ContextAdvisorImpl.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,26 @@ | ||
package io.smartdatalake.context | ||
|
||
import com.typesafe.config.ConfigObject | ||
import org.eclipse.lsp4j.CompletionItem | ||
import java.util.Map as JMap | ||
|
||
import scala.collection.immutable.List | ||
|
||
import io.smartdatalake.conversions.ScalaJavaConverterAPI.* | ||
|
||
|
||
class ContextAdvisorImpl extends ContextAdvisor: | ||
override def generateSuggestions(context: SDLBContext): List[ContextSuggestion] = context.parentPath.lastOption match | ||
case Some(value) => value match | ||
case "inputId" | "outputId" | "inputIds" | "outputIds" => retrieveDataObjectIds(context) | ||
case _ => List.empty[ContextSuggestion] | ||
case None => List.empty[ContextSuggestion] | ||
|
||
private def retrieveDataObjectIds(context: SDLBContext): List[ContextSuggestion] = | ||
Option(context.textContext.rootConfig.root().get("dataObjects")) match | ||
case Some(asConfigObject: ConfigObject) => asConfigObject.unwrapped().toScala.map { (k, v) => v match | ||
case jMap: JMap[String, Object] => ContextSuggestion(k, Option(jMap.get("type")).map(_.toString).getOrElse("")) | ||
case _ => ContextSuggestion(k, "") | ||
}.toList | ||
case _ => List.empty[ContextSuggestion] | ||
|
3 changes: 3 additions & 0 deletions
3
src/main/scala/io/smartdatalake/context/ContextSuggestion.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.context | ||
|
||
case class ContextSuggestion(value: String, label: String) |
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
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
25 changes: 25 additions & 0 deletions
25
src/test/scala/io/smartdatalake/context/ContextAdvisorSpec.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,25 @@ | ||
package io.smartdatalake.context | ||
|
||
import com.typesafe.config.{Config, ConfigRenderOptions, ConfigUtil} | ||
import io.smartdatalake.UnitSpec | ||
import io.smartdatalake.context.hocon.HoconParser | ||
import io.smartdatalake.utils.MultiLineTransformer as MLT | ||
|
||
import scala.io.Source | ||
import scala.util.Using | ||
|
||
class ContextAdvisorSpec extends UnitSpec { | ||
|
||
private val context: SDLBContext = SDLBContext.fromText(loadFile("fixture/hocon/airport-example.conf")) | ||
|
||
|
||
"Context Advisor" should "generate correctly dataObject suggestions when on inputId attribute" in { | ||
val inputIdContext = context.withCaretPosition(62, 14) | ||
val suggestions = contextAdvisor.generateSuggestions(inputIdContext) | ||
suggestions should have size 7 | ||
suggestions should contain (ContextSuggestion("ext-airports", "WebserviceFileDataObject")) | ||
suggestions should contain (ContextSuggestion("btl-distances", "CsvFileDataObject")) | ||
|
||
} | ||
|
||
} |
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