Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sum type info in suggestions DB #3422

Merged
merged 10 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sealed trait Suggestion extends ToLogString {
def externalId: Option[Suggestion.ExternalId]
def module: String
def name: String
def returnType: Suggestion.TypeRep
def returnType: String
}

object Suggestion {
Expand Down Expand Up @@ -110,44 +110,6 @@ object Suggestion {
}
}

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes(
Array(
new JsonSubTypes.Type(
value = classOf[TypeRep.Legacy],
name = "typeRepLegacy"
),
new JsonSubTypes.Type(
value = classOf[TypeRep.Sum],
name = "typeRepSum"
),
new JsonSubTypes.Type(
value = classOf[TypeRep.Cons],
name = "typeRepCons"
)
)
)
sealed trait TypeRep {
def toLegacy: TypeRep.Legacy
}

object TypeRep {
implicit def asLegacyRep(contents: String): TypeRep = Legacy(contents)

case class Legacy(contents: String) extends TypeRep {
override def toLegacy: Legacy = this
override def toString: String = contents
}

case class Sum(name: String, variants: Seq[TypeRep]) extends TypeRep {
override def toLegacy: Legacy = Legacy(this.name)
}

case class Cons(name: String) extends TypeRep {
override def toLegacy: Legacy = Legacy(this.name)
}
}

/** An argument of an atom or a function.
*
* @param name the argument name
Expand All @@ -158,10 +120,11 @@ object Suggestion {
*/
case class Argument(
name: String,
reprType: TypeRep,
reprType: String,
isSuspended: Boolean,
hasDefault: Boolean,
defaultValue: Option[String]
defaultValue: Option[String],
tagValues: Option[Seq[String]] = None
) extends ToLogString {

/** @inheritdoc */
Expand Down Expand Up @@ -211,7 +174,7 @@ object Suggestion {
override def externalId: Option[ExternalId] =
None

override def returnType: Suggestion.TypeRep =
override def returnType: String =
module

/** @inheritdoc */
Expand All @@ -237,7 +200,7 @@ object Suggestion {
module: String,
name: String,
arguments: Seq[Argument],
returnType: Suggestion.TypeRep,
returnType: String,
documentation: Option[String],
documentationHtml: Option[String] = None,
documentationSections: Option[List[DocSection]] = None,
Expand Down Expand Up @@ -276,7 +239,7 @@ object Suggestion {
name: String,
arguments: Seq[Argument],
selfType: String,
returnType: TypeRep,
returnType: String,
documentation: Option[String],
documentationHtml: Option[String] = None,
documentationSections: Option[List[DocSection]] = None,
Expand Down Expand Up @@ -313,7 +276,7 @@ object Suggestion {
module: String,
arguments: Seq[Argument],
sourceType: String,
returnType: Suggestion.TypeRep,
returnType: String,
documentation: Option[String],
documentationHtml: Option[String] = None,
documentationSections: Option[List[DocSection]] = None,
Expand Down Expand Up @@ -350,7 +313,7 @@ object Suggestion {
module: String,
name: String,
arguments: Seq[Argument],
returnType: Suggestion.TypeRep,
returnType: String,
scope: Scope
) extends Suggestion
with ToLogString {
Expand Down Expand Up @@ -379,7 +342,7 @@ object Suggestion {
externalId: Option[ExternalId],
module: String,
name: String,
returnType: Suggestion.TypeRep,
returnType: String,
scope: Scope
) extends Suggestion {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,16 +529,20 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
reprType = buildTypeArgumentName(targ),
isSuspended = varg.suspended,
hasDefault = varg.defaultValue.isDefined,
defaultValue = varg.defaultValue.flatMap(buildDefaultValue)
defaultValue = varg.defaultValue.flatMap(buildDefaultValue),
tagValues = targ match {
case TypeArg.Sum(_, variants) => Some(variants.map(_.toString))
case _ => None
}
)

/** Build the name of type argument.
*
* @param targ the type argument
* @return the name of type argument
*/
private def buildTypeArgumentName(targ: TypeArg): Suggestion.TypeRep = {
def go(targ: TypeArg, level: Int): Suggestion.TypeRep =
private def buildTypeArgumentName(targ: TypeArg): String = {
def go(targ: TypeArg, level: Int): String =
targ match {
case TypeArg.Value(name) => name.toString
case TypeArg.Function(Vector(typeArg)) =>
Expand All @@ -557,11 +561,7 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
val argsList = args.map(go(_, level + 1)).mkString(" ")
val typeName = s"$funText $argsList"
if (level > 0) s"($typeName)" else typeName
case TypeArg.Sum(n, vs) =>
Suggestion.TypeRep.Sum(
n.toString,
vs.map(qn => Suggestion.TypeRep.Cons(qn.toString))
)
case TypeArg.Sum(n, _) => n.toString
}

go(targ, 0)
Expand All @@ -586,7 +586,7 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
* @param typeDef the type definition
* @return the type name
*/
private def buildReturnType(typeDef: Option[TypeArg]): Suggestion.TypeRep =
private def buildReturnType(typeDef: Option[TypeArg]): String =
typeDef.map(buildTypeArgumentName).getOrElse(Any)

/** Build argument default value from the expression.
Expand Down Expand Up @@ -688,6 +688,6 @@ object SuggestionBuilder {

}

val Any: Suggestion.TypeRep = Constants.ANY
val Any: String = Constants.ANY

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ object SuggestionDiff {
op = op.copy(name = Some(b.name))
}
if (a.reprType != b.reprType) {
op = op.copy(reprType = Some(b.reprType.toLegacy.contents))
op = op.copy(reprType = Some(b.reprType))
}
if (a.isSuspended != b.isSuspended) {
op.copy(isSuspended = Some(b.isSuspended))
Expand Down Expand Up @@ -155,7 +155,7 @@ object SuggestionDiff {
op = op.copy(arguments = Some(diffArguments(e1.arguments, e2.arguments)))
}
if (e1.returnType != e2.returnType) {
op = op.copy(returnType = Some(e2.returnType.toLegacy.contents))
op = op.copy(returnType = Some(e2.returnType))
}
if (e1.documentation != e2.documentation) {
op = op.copy(documentation = Some(e2.documentation))
Expand All @@ -175,7 +175,7 @@ object SuggestionDiff {
op = op.copy(arguments = Some(diffArguments(e1.arguments, e2.arguments)))
}
if (e1.returnType != e2.returnType) {
op = op.copy(returnType = Some(e2.returnType.toLegacy.contents))
op = op.copy(returnType = Some(e2.returnType))
}
if (e1.documentation != e2.documentation) {
op = op.copy(documentation = Some(e2.documentation))
Expand All @@ -195,7 +195,7 @@ object SuggestionDiff {
op = op.copy(arguments = Some(diffArguments(e1.arguments, e2.arguments)))
}
if (e1.returnType != e2.returnType) {
op = op.copy(returnType = Some(e2.returnType.toLegacy.contents))
op = op.copy(returnType = Some(e2.returnType))
}
if (e1.scope != e2.scope) {
op = op.copy(scope = Some(e2.scope))
Expand All @@ -212,7 +212,7 @@ object SuggestionDiff {
op = op.copy(externalId = Some(e2.externalId))
}
if (e1.returnType != e2.returnType) {
op = op.copy(returnType = Some(e2.returnType.toLegacy.contents))
op = op.copy(returnType = Some(e2.returnType))
}
if (e1.scope != e2.scope) {
op = op.copy(scope = Some(e2.scope))
Expand Down
Loading