-
Notifications
You must be signed in to change notification settings - Fork 323
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bd023de
introduce the IR
kustosz 12680fb
it works???? question mark
kustosz cd8c962
make it spec-conformant
kustosz 01e76a0
undo the refactor to not hide changes
kustosz be29dae
fix test
kustosz d957fb1
Merge branch 'develop' into wip/mk/retain-sum-types
kustosz 5303a1f
style
kustosz 73dbc2d
changelog
kustosz de766d0
docs
kustosz 73ce78e
Merge branch 'develop' into wip/mk/retain-sum-types
kustosz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,13 +336,22 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) { | |
resolvedName match { | ||
case BindingsMap.ResolvedModule(module) => | ||
Some(module.getName) | ||
case BindingsMap.ResolvedConstructor(module, cons) => | ||
Some(module.getName.createChild(cons.name)) | ||
case cons: BindingsMap.ResolvedConstructor => | ||
Some(cons.qualifiedName) | ||
case _ => | ||
None | ||
} | ||
} | ||
|
||
private def buildResolvedUnionTypeName( | ||
resolvedName: BindingsMap.ResolvedTypeName | ||
): Option[TypeArg] = resolvedName match { | ||
case tp: BindingsMap.ResolvedType => | ||
Some(TypeArg.Sum(tp.qualifiedName, tp.getVariants.map(_.qualifiedName))) | ||
case other: BindingsMap.ResolvedName => | ||
buildResolvedTypeName(other).map(TypeArg.Value) | ||
} | ||
|
||
/** Build type signature from the ir metadata. | ||
* | ||
* @param typeSignature the type signature metadata | ||
|
@@ -380,19 +389,18 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) { | |
args :++ arg | ||
case IR.Function.Lambda(List(targ), body, _, _, _, _) => | ||
val typeName = targ.name.name | ||
val qualifiedTypeName = resolveTypeName(bindings, typeName) | ||
.getOrElse(QualifiedName.simpleName(typeName)) | ||
val tdef = TypeArg.Value(qualifiedTypeName) | ||
val tdef = resolveTypeName(bindings, typeName) | ||
.getOrElse(TypeArg.Value(QualifiedName.simpleName(typeName))) | ||
go(body, args :+ tdef) | ||
case IR.Application.Prefix(tfun, targs, _, _, _, _) => | ||
val appFunction = go(tfun, Vector()).head | ||
val appArgs = targs.flatMap(arg => go(arg.value, Vector())) | ||
args :+ TypeArg.Application(appFunction, appArgs.toVector) | ||
case tname: IR.Name => | ||
val typeName = tname.name | ||
val qualifiedTypeName = resolveTypeName(bindings, typeName) | ||
.getOrElse(QualifiedName.simpleName(typeName)) | ||
args :+ TypeArg.Value(qualifiedTypeName) | ||
val tdef = resolveTypeName(bindings, typeName) | ||
.getOrElse(TypeArg.Value(QualifiedName.simpleName(typeName))) | ||
args :+ tdef | ||
case _ => | ||
args | ||
} | ||
|
@@ -415,10 +423,10 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) { | |
private def resolveTypeName( | ||
bindings: Option[BindingAnalysis.Metadata], | ||
name: String | ||
): Option[QualifiedName] = { | ||
): Option[TypeArg] = { | ||
bindings | ||
.flatMap(_.resolveUppercaseName(name).toOption) | ||
.flatMap(buildResolvedTypeName) | ||
.flatMap(_.resolveTypeName(name).toOption) | ||
.flatMap(buildResolvedUnionTypeName) | ||
} | ||
|
||
/** Build arguments of a method. | ||
|
@@ -521,7 +529,11 @@ 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. | ||
|
@@ -549,6 +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, _) => n.toString | ||
} | ||
|
||
go(targ, 0) | ||
|
@@ -639,6 +652,13 @@ object SuggestionBuilder { | |
sealed private trait TypeArg | ||
private object TypeArg { | ||
|
||
/** A sum type – one of many possible options. | ||
* @param name the qualified name of the type. | ||
* @param variants the qualified names of constituent atoms. | ||
*/ | ||
case class Sum(name: QualifiedName, variants: Seq[QualifiedName]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. documentation |
||
extends TypeArg | ||
|
||
/** Type with the name, like `A`. | ||
* | ||
* @param name the name of the type | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some documentation