mirror of
https://github.com/enso-org/enso.git
synced 2024-12-22 21:01:37 +03:00
Filter private constructors from Suggestions Database (#10032)
close #10011 Changelog: - feat: exclude private constructors from Suggestions database # Important Notes `java_table` field of the `Table` is hidden ![2024-05-22-084751_892x913_scrot](https://github.com/enso-org/enso/assets/357683/4770e173-f5af-4726-a7fc-2dab1ef3eea5)
This commit is contained in:
parent
16c1b74218
commit
4ca26c84ef
@ -55,8 +55,9 @@ public final class PrivateConstructorAnalysis implements IRPass {
|
||||
.map(
|
||||
binding -> {
|
||||
if (binding instanceof Definition.Type type) {
|
||||
var privateCtorsCnt = type.members().filter(ctor -> ctor.isPrivate()).size();
|
||||
var publicCtorsCnt = type.members().filter(ctor -> !ctor.isPrivate()).size();
|
||||
var partitions = type.members().partition(Definition.Data::isPrivate);
|
||||
var privateCtorsCnt = partitions._1.size();
|
||||
var publicCtorsCnt = partitions._2.size();
|
||||
var ctorsCnt = type.members().size();
|
||||
if (!(privateCtorsCnt == ctorsCnt || publicCtorsCnt == ctorsCnt)) {
|
||||
assert type.location().isDefined();
|
||||
|
@ -3098,6 +3098,51 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
|
||||
)
|
||||
}
|
||||
|
||||
"build type with private constructor" in {
|
||||
val code =
|
||||
"""type T
|
||||
| private A x y
|
||||
|
|
||||
| foo self = x + y
|
||||
|""".stripMargin
|
||||
val module = code.preprocessModule
|
||||
|
||||
build(code, module) shouldEqual Tree.Root(
|
||||
Vector(
|
||||
ModuleNode,
|
||||
Tree.Node(
|
||||
Suggestion.Type(
|
||||
externalId = None,
|
||||
module = "Unnamed.Test",
|
||||
name = "T",
|
||||
params = Seq(),
|
||||
returnType = "Unnamed.Test.T",
|
||||
parentType = Some(SuggestionBuilder.Any),
|
||||
documentation = None
|
||||
),
|
||||
Vector()
|
||||
),
|
||||
Tree.Node(
|
||||
Suggestion.DefinedMethod(
|
||||
externalId = None,
|
||||
module = "Unnamed.Test",
|
||||
name = "foo",
|
||||
arguments = Seq(
|
||||
Suggestion
|
||||
.Argument("self", "Unnamed.Test.T", false, false, None)
|
||||
),
|
||||
selfType = "Unnamed.Test.T",
|
||||
returnType = SuggestionBuilder.Any,
|
||||
isStatic = false,
|
||||
documentation = None,
|
||||
annotations = Seq()
|
||||
),
|
||||
Vector()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
"build Integer type" in {
|
||||
|
||||
val code = "type Integer"
|
||||
@ -3252,6 +3297,19 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
|
||||
)
|
||||
}
|
||||
|
||||
"build private module" in {
|
||||
val code =
|
||||
"""private
|
||||
|
|
||||
|type T
|
||||
|
|
||||
|main = "Hello World!"
|
||||
|""".stripMargin
|
||||
val module = code.preprocessModule
|
||||
|
||||
build(code, module) shouldEqual Tree.Root(Vector())
|
||||
}
|
||||
|
||||
"build module with a type named as module" in {
|
||||
val code =
|
||||
"""type Test
|
||||
|
@ -11,6 +11,7 @@ import org.enso.compiler.core.ir.{
|
||||
Function,
|
||||
IdentifiedLocation,
|
||||
Location,
|
||||
Module,
|
||||
Name,
|
||||
Type
|
||||
}
|
||||
@ -87,16 +88,16 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
) =>
|
||||
val tpe =
|
||||
buildAtomType(module, tpName.name, tpName.name, params, doc)
|
||||
val conses = members.map {
|
||||
val conses = members.collect {
|
||||
case data @ Definition.Data(
|
||||
name,
|
||||
arguments,
|
||||
annotations,
|
||||
_,
|
||||
_,
|
||||
isPrivate,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
) if !isPrivate =>
|
||||
buildAtomConstructor(
|
||||
module,
|
||||
tpName.name,
|
||||
@ -107,6 +108,7 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
)
|
||||
}
|
||||
val getters = members
|
||||
.filterNot(_.isPrivate)
|
||||
.flatMap(_.arguments)
|
||||
.filterNot { argument =>
|
||||
argument.name.name.startsWith(InternalPrefix) ||
|
||||
@ -227,6 +229,10 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
}
|
||||
}
|
||||
|
||||
ir match {
|
||||
case module: Module if module.isPrivate =>
|
||||
Tree.Root(Vector())
|
||||
case _ =>
|
||||
val builder: TreeBuilder = Vector.newBuilder
|
||||
builder += Tree.Node(
|
||||
buildModule(
|
||||
@ -240,6 +246,7 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
go(builder, Scope(ir.children, ir.location))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Build a method suggestion. */
|
||||
private def buildMethod(
|
||||
|
Loading…
Reference in New Issue
Block a user