Skip to content

Commit

Permalink
Offer no suggestion for single constructor (#5747)
Browse files Browse the repository at this point in the history
Resolving #5055 - avoid putting single constructor into suggestion database.

# Important Notes
Another way to fix #5055 is to keep the single constructor information in the suggestion database and let the IDE filter that out.
  • Loading branch information
JaroslavTulach authored Feb 28, 2023
1 parent b8ceaec commit 0536eeb
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,14 @@ final class SuggestionBuilder[A: IndexedSource](
resolvedName: BindingsMap.ResolvedName
): TypeArg = resolvedName match {
case tp: BindingsMap.ResolvedType =>
TypeArg.Sum(
Some(tp.qualifiedName),
tp.getVariants.map(r => TypeArg.Value(r.qualifiedName))
)
if (tp.getVariants.size > 1) {
TypeArg.Sum(
Some(tp.qualifiedName),
tp.getVariants.map(r => TypeArg.Value(r.qualifiedName))
)
} else {
TypeArg.Sum(Some(tp.qualifiedName), Seq.empty)
}
case _: BindingsMap.ResolvedName =>
TypeArg.Value(resolvedName.qualifiedName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2125,10 +2125,160 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
)
}

"build module with overloaded functions" in {
"build module with overloaded functions and two constructors" in {
val code =
"""type A
| Mk_A
| Mk_A_Plus a
|
| quux : A -> A
| quux self x = x
|
|quux : A -> A
|quux x = x
|
|main =
| quux A
| A.quux A""".stripMargin
val module = code.preprocessModule

build(code, module) shouldEqual Tree.Root(
Vector(
ModuleNode,
Tree.Node(
Suggestion.Type(
externalId = None,
module = "Unnamed.Test",
name = "A",
params = List(),
returnType = "Unnamed.Test.A",
parentType = Some(SuggestionBuilder.Any),
documentation = None
),
Vector()
),
Tree.Node(
Suggestion.Constructor(
externalId = None,
module = "Unnamed.Test",
name = "Mk_A",
arguments = List(),
returnType = "Unnamed.Test.A",
documentation = None
),
Vector()
),
Tree.Node(
Suggestion.Constructor(
None,
"Unnamed.Test",
"Mk_A_Plus",
List(
Suggestion.Argument(
"a",
"Standard.Base.Any.Any",
false,
false,
None,
None
)
),
"Unnamed.Test.A",
None,
None,
None,
None
),
Vector()
),
Tree.Node(
Suggestion.Method(
None,
"Unnamed.Test",
"a",
Vector(
Suggestion
.Argument("self", "Unnamed.Test.A", false, false, None, None)
),
"Unnamed.Test.A",
"Standard.Base.Any.Any",
false,
None,
None,
None,
None
),
Vector()
),
Tree.Node(
Suggestion.Method(
None,
"Unnamed.Test",
"quux",
Vector(
Suggestion
.Argument("self", "Unnamed.Test.A", false, false, None),
Suggestion.Argument(
"x",
"Unnamed.Test.A",
false,
false,
None,
Some(List("Unnamed.Test.Mk_A", "Unnamed.Test.Mk_A_Plus"))
)
),
selfType = "Unnamed.Test.A",
returnType = "Unnamed.Test.A",
isStatic = false,
documentation = None
),
Vector()
),
Tree.Node(
Suggestion.Method(
externalId = None,
module = "Unnamed.Test",
name = "quux",
arguments = Vector(
Suggestion.Argument("self", "Unnamed.Test", false, false, None),
Suggestion.Argument(
"x",
"Unnamed.Test.A",
false,
false,
None,
Some(List("Unnamed.Test.Mk_A", "Unnamed.Test.Mk_A_Plus"))
)
),
selfType = "Unnamed.Test",
returnType = "Unnamed.Test.A",
isStatic = true,
documentation = None
),
Vector()
),
Tree.Node(
Suggestion.Method(
externalId = None,
module = "Unnamed.Test",
name = "main",
arguments = List(),
selfType = "Unnamed.Test",
returnType = SuggestionBuilder.Any,
isStatic = true,
documentation = None
),
Vector()
)
)
)
}

"single constructor isn't suggested" in {
val code =
"""type A
| Mk_A
|
| quux : A -> A
| quux self x = x
|
Expand Down Expand Up @@ -2180,7 +2330,7 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
false,
false,
None,
Some(List("Unnamed.Test.Mk_A"))
None
)
),
selfType = "Unnamed.Test.A",
Expand All @@ -2203,7 +2353,7 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
false,
false,
None,
Some(List("Unnamed.Test.Mk_A"))
None
)
),
selfType = "Unnamed.Test",
Expand Down

0 comments on commit 0536eeb

Please sign in to comment.