Skip to content

Commit

Permalink
#263: Suggest global enum
Browse files Browse the repository at this point in the history
  • Loading branch information
simerplaha committed Aug 6, 2024
1 parent cc8a304 commit ab28ac9
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.alephium.ralph.lsp.pc.search.completion

import org.alephium.ralph.Ast
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import org.alephium.ralph.lsp.pc.search.TestCodeProvider._
Expand Down Expand Up @@ -447,6 +448,69 @@ class FunctionBodyCompleterSpec extends AnyWordSpec with Matchers {

actual.sortBy(_.label) shouldBe expected.sortBy(_.label)
}

"global enums exist" in {
val suggestions =
suggest {
"""
|enum GlobalEnumTop {
| ONE = 1
| TWO = 2
|}
|
|Contract Foo() {
|
| enum LocalEnum {
| THREE = 3
| FOUR = 4
| }
|
| pub fn test() -> () {
| @@
| }
|}
|
|enum GlobalEnumBottom {
| FIVE = 5
| SIX = 6
|}
|""".stripMargin
}

val actual =
suggestions
.collect {
case enums: Suggestion.EnumDef =>
enums

case enumCreatedTypes: Suggestion.CreatedType if enumCreatedTypes.node.source.tree.ast.isInstanceOf[Ast.EnumDef[_]] =>
enumCreatedTypes
}
.flatMap(_.toCompletion())

// FIXME: Global enums should not be suggested as Classes. This is the case right now because
// All `GlobalDefinition`s that contain `typeId` are returned as Suggestion.CreatedInstance.
val expected =
List(
Completion.Enum(
label = "LocalEnum",
insert = "LocalEnum",
detail = ""
),
Completion.Class(
label = "GlobalEnumTop",
insert = "GlobalEnumTop",
detail = ""
),
Completion.Class(
label = "GlobalEnumBottom",
insert = "GlobalEnumBottom",
detail = ""
)
)

actual.sortBy(_.label) shouldBe expected.sortBy(_.label)
}
}

"TxScript" should {
Expand Down

0 comments on commit ab28ac9

Please sign in to comment.