Skip to content

Commit

Permalink
enums and enum variants in structure view
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Nov 8, 2024
1 parent 7b565bf commit 6c04aba
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ class MvStructureViewTreeElement(val element: NavigatablePsiElement): StructureV
listOf(
element.consts(),
element.structs(),
element.enumList,
element.allFunctions(),
element.specFunctions(),
).flatten()
}
is MvStruct -> element.namedFields
is MvFieldsOwner -> element.namedFields
is MvEnum -> element.variants
else -> emptyList()
}
return items.map { MvStructureViewTreeElement(it) }.toTypedArray()
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/org/move/lang/core/psi/ext/MvEnum.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.move.lang.core.psi.ext

import com.intellij.ide.projectView.PresentationData
import com.intellij.lang.ASTNode
import com.intellij.navigation.ItemPresentation
import com.intellij.psi.PsiElement
import com.intellij.psi.stubs.IStubElementType
import org.move.ide.MoveIcons
Expand Down Expand Up @@ -41,5 +43,15 @@ abstract class MvEnumMixin: MvStubbedNamedElementImpl<MvEnumStub>,
return ItemQualName(this, moduleFQName.address, moduleFQName.itemName, itemName)
}

override fun getPresentation(): ItemPresentation? {
val enumName = this.name ?: return null
return PresentationData(
enumName,
this.locationString(true),
MoveIcons.STRUCT,
null
)
}

override val abilitiesList: MvAbilitiesList? get() = abilitiesListList.firstOrNull()
}
23 changes: 23 additions & 0 deletions src/main/kotlin/org/move/lang/core/psi/ext/MvEnumVariant.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.move.lang.core.psi.ext

import com.intellij.ide.projectView.PresentationData
import com.intellij.lang.ASTNode
import com.intellij.navigation.ItemPresentation
import com.intellij.psi.stubs.IStubElementType
import org.move.ide.MoveIcons
import org.move.lang.core.psi.MvEnum
Expand All @@ -20,4 +22,25 @@ abstract class MvEnumVariantMixin: MvStubbedNamedElementImpl<MvEnumVariantStub>,
constructor(stub: MvEnumVariantStub, nodeType: IStubElementType<*, *>): super(stub, nodeType)

override fun getIcon(flags: Int): Icon = MoveIcons.STRUCT

override fun getPresentation(): ItemPresentation? {
val variant = this
val variantName = this.name ?: return null
val presentationText = buildString {
append(variantName)
val fields = variant.tupleFields
if (fields != null) {
append('(')
val xs = fields.tupleFieldDeclList.map { it.type.text }
append(xs.joinToString(", "))
append(')')
}
}
return PresentationData(
presentationText,
this.locationString(true),
MoveIcons.ENUM_VARIANT,
null
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ address 0x1 {
struct Struct2 {
field2: u8
}
enum S { One, Two, Three { val: u8 }, Four(u8, u8)}
public fun call_pub() {}
public(friend) fun call_pub_friend() {}
entry fun call_entry() {}
Expand All @@ -59,6 +60,12 @@ address 0x1 {
field1: u8
-Struct2
field2: u8
-S
One
Two
-Three
val: u8
Four(u8, u8)
call_pub()
call_pub_friend()
call_entry()
Expand Down

0 comments on commit 6c04aba

Please sign in to comment.