feat: set constructor args tag values (#6801)

related #6611

Changelog:
- update: set tag values for arguments with ascribed types

# Important Notes
![2023-05-23-002112_697x311_scrot](https://github.com/enso-org/enso/assets/357683/10d1c03b-45b7-4133-b4aa-80d1f1ea8e84)
This commit is contained in:
Dmitry Bushev 2023-05-23 09:07:40 +01:00 committed by GitHub
parent f8cb908095
commit 7471e38ff6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 19 deletions

View File

@ -638,19 +638,18 @@ final class SuggestionBuilder[A: IndexedSource](
* @return the suggestion argument
*/
private def buildArgument(arg: IR.DefinitionArgument): Suggestion.Argument = {
val signatureOpt = arg.name.getMetadata(TypeSignatures).map { meta =>
buildTypeSignature(meta.signature) match {
case Vector(targ) => buildTypeArgumentName(targ)
case _ => Any
}
buildTypeSignatureFromMetadata(arg.name.getMetadata(TypeSignatures)) match {
case Vector(targ) =>
buildTypedArgument(arg, targ)
case _ =>
Suggestion.Argument(
name = arg.name.name,
reprType = Any,
isSuspended = arg.suspended,
hasDefault = arg.defaultValue.isDefined,
defaultValue = arg.defaultValue.flatMap(buildDefaultValue)
)
}
Suggestion.Argument(
name = arg.name.name,
reprType = signatureOpt.getOrElse(Any),
isSuspended = arg.suspended,
hasDefault = arg.defaultValue.isDefined,
defaultValue = arg.defaultValue.flatMap(buildDefaultValue)
)
}
/** Build return type from the type definition.

View File

@ -2016,10 +2016,12 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
"build type with ascribed constructor" in {
val code =
"""type X
"""type S
| X
| Y
|
|type T
| A (x : X)
| A (x : S)
|""".stripMargin
val module = code.preprocessModule
@ -2030,14 +2032,36 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
Suggestion.Type(
externalId = None,
module = "Unnamed.Test",
name = "X",
name = "S",
params = Seq(),
returnType = "Unnamed.Test.X",
returnType = "Unnamed.Test.S",
parentType = Some(SuggestionBuilder.Any),
documentation = None
),
Vector()
),
Tree.Node(
Suggestion.Constructor(
externalId = None,
module = "Unnamed.Test",
name = "X",
arguments = Seq(),
returnType = "Unnamed.Test.S",
documentation = None
),
Vector()
),
Tree.Node(
Suggestion.Constructor(
externalId = None,
module = "Unnamed.Test",
name = "Y",
arguments = Seq(),
returnType = "Unnamed.Test.S",
documentation = None
),
Vector()
),
Tree.Node(
Suggestion.Type(
externalId = None,
@ -2056,8 +2080,14 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
module = "Unnamed.Test",
name = "A",
arguments = Seq(
Suggestion
.Argument("x", "Unnamed.Test.X", false, false, None)
Suggestion.Argument(
"x",
"Unnamed.Test.S",
false,
false,
None,
Some(Seq("Unnamed.Test.S.X", "Unnamed.Test.S.Y"))
)
),
returnType = "Unnamed.Test.T",
documentation = None
@ -2074,7 +2104,7 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
.Argument("self", "Unnamed.Test.T", false, false, None)
),
selfType = "Unnamed.Test.T",
returnType = "Unnamed.Test.X",
returnType = "Unnamed.Test.S",
isStatic = false,
documentation = None
),