From 547140e50515c54a882a5d92aa60137d566468fa Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Fri, 8 Nov 2024 13:26:17 +0100 Subject: [PATCH 1/3] refactor item presentation --- .../kotlin/org/move/ide/presentation/Utils.kt | 88 +++++++++++++++++ .../move/ide/structureView/ItemTypeSorter.kt | 13 +-- .../ide/structureView/MvStructureViewModel.kt | 23 ++--- .../MvStructureViewTreeElement.kt | 97 +++++++++++-------- .../org/move/lang/core/psi/MvFunctionLike.kt | 12 --- .../move/lang/core/psi/ext/MvAddressDef.kt | 8 +- .../org/move/lang/core/psi/ext/MvConst.kt | 10 -- .../org/move/lang/core/psi/ext/MvEnum.kt | 10 -- .../move/lang/core/psi/ext/MvEnumVariant.kt | 23 +---- .../org/move/lang/core/psi/ext/MvFunction.kt | 2 - .../org/move/lang/core/psi/ext/MvModule.kt | 12 --- .../move/lang/core/psi/ext/MvSpecFunction.kt | 19 ++-- .../org/move/lang/core/psi/ext/MvStruct.kt | 10 -- .../move/lang/core/psi/ext/MvStructField.kt | 10 -- .../org/move/lang/core/psi/ext/PsiElement.kt | 18 +--- .../psi/impl/MvNameIdentifierOwnerImpl.kt | 5 + .../lang/core/psi/impl/MvNamedElementImpl.kt | 10 +- .../org/move/lang/core/stubs/StubUtils.kt | 4 + .../structureView/StructureViewTestBase.kt | 4 +- 19 files changed, 181 insertions(+), 197 deletions(-) create mode 100644 src/main/kotlin/org/move/ide/presentation/Utils.kt diff --git a/src/main/kotlin/org/move/ide/presentation/Utils.kt b/src/main/kotlin/org/move/ide/presentation/Utils.kt new file mode 100644 index 000000000..ef478beac --- /dev/null +++ b/src/main/kotlin/org/move/ide/presentation/Utils.kt @@ -0,0 +1,88 @@ +package org.move.ide.presentation + +import com.intellij.ide.projectView.PresentationData +import com.intellij.navigation.ItemPresentation +import com.intellij.openapi.util.Iconable +import com.intellij.psi.PsiElement +import org.move.lang.MoveFile +import org.move.lang.core.psi.MvConst +import org.move.lang.core.psi.MvElement +import org.move.lang.core.psi.MvEnumVariant +import org.move.lang.core.psi.MvFunctionLike +import org.move.lang.core.psi.MvModule +import org.move.lang.core.psi.MvNamedElement +import org.move.lang.core.psi.MvNamedFieldDecl +import org.move.lang.core.psi.signatureText +import org.move.lang.core.types.address +import org.move.lang.moveProject +import org.move.lang.toNioPathOrNull +import org.move.openapiext.rootPath +import java.nio.file.Path + +fun getPresentation(psi: PsiElement): ItemPresentation { + if (psi is MoveFile) { + return psi.presentation!! + } + val location = psi.locationString(tryRelative = true) + val name = presentableName(psi) + return PresentationData(name, location, psi.getIcon(0), null) +} + +fun getPresentationForStructure(psi: PsiElement): ItemPresentation { + if (psi is MoveFile) { + return psi.presentation!! + } + val presentation = buildString { + fun appendCommaList(xs: List) { + append('(') + append(xs.joinToString(", ")) + append(')') + } + append(presentableName(psi)) + when (psi) { + is MvFunctionLike -> { + append(psi.signatureText) + } + is MvConst -> { + psi.type?.let { append(": ${it.text}") } + } + is MvNamedFieldDecl -> { + psi.type?.let { append(": ${it.text}") } + } + is MvEnumVariant -> { + val fields = psi.tupleFields + if (fields != null) { + appendCommaList(fields.tupleFieldDeclList.map { it.type.text }) + } + } + } + } + val icon = psi.getIcon(Iconable.ICON_FLAG_VISIBILITY) + return PresentationData(presentation, null, icon, null) +} + +fun PsiElement.locationString(tryRelative: Boolean): String? = when (this) { + is MvModule -> { + val moveProj = this.moveProject + this.address(moveProj)?.text() ?: "" + } + else -> containingFilePath(tryRelative)?.toString() +} + +private fun PsiElement.containingFilePath(tryRelative: Boolean): Path? { + val containingFilePath = this.containingFile.toNioPathOrNull() ?: return null + if (tryRelative) { + val rootPath = this.project.rootPath + if (rootPath != null) { + return rootPath.relativize(containingFilePath) + } + } + return containingFilePath +} + +private fun presentableName(psi: PsiElement): String? { + return when (psi) { + is MvNamedElement -> psi.name + else -> null + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/move/ide/structureView/ItemTypeSorter.kt b/src/main/kotlin/org/move/ide/structureView/ItemTypeSorter.kt index 48272665c..f3284af70 100644 --- a/src/main/kotlin/org/move/ide/structureView/ItemTypeSorter.kt +++ b/src/main/kotlin/org/move/ide/structureView/ItemTypeSorter.kt @@ -14,8 +14,8 @@ class ItemTypeComparator: Comparator { } private fun getIntKind(treeElement: MvStructureViewTreeElement): Int { - val element = treeElement.element - return when (element) { + val psi = treeElement.psi + return when (psi) { is MvConst -> 0 is MvStruct -> 1 is MvFunction -> 2 @@ -29,13 +29,8 @@ class ItemTypeComparator: Comparator { class ItemTypeSorter: Sorter { override fun getComparator(): Comparator<*> = ItemTypeComparator() - override fun getPresentation(): ActionPresentation { - return ActionPresentationData( - "By Type", - null, - AllIcons.ObjectBrowser.SortByType - ) - } + override fun getPresentation(): ActionPresentation = + ActionPresentationData("By Type", null, AllIcons.ObjectBrowser.SortByType) override fun isVisible(): Boolean = true diff --git a/src/main/kotlin/org/move/ide/structureView/MvStructureViewModel.kt b/src/main/kotlin/org/move/ide/structureView/MvStructureViewModel.kt index 4df94a40f..fafda4cdb 100644 --- a/src/main/kotlin/org/move/ide/structureView/MvStructureViewModel.kt +++ b/src/main/kotlin/org/move/ide/structureView/MvStructureViewModel.kt @@ -39,15 +39,12 @@ class MvStructureViewModel(editor: Editor?, moveFile: MoveFile): class HidePrivateFunctionsFilter: Filter { override fun isVisible(treeNode: TreeElement): Boolean { // if action is set, only public items are visible - return (treeNode as? MvStructureViewTreeElement)?.isPublic ?: true + return (treeNode as? MvStructureViewTreeElement)?.isPublicItem != false } @Suppress("DialogTitleCapitalization") - override fun getPresentation(): ActionPresentation { - return ActionPresentationData( - "Hide private functions", null, PlatformIcons.PRIVATE_ICON - ) - } + override fun getPresentation(): ActionPresentation = + ActionPresentationData("Hide private functions", null, PlatformIcons.PRIVATE_ICON) override fun getName() = ID @@ -65,11 +62,8 @@ class HideTestFunctionsFilter: Filter { } @Suppress("DialogTitleCapitalization") - override fun getPresentation(): ActionPresentation { - return ActionPresentationData( - "Hide #[test] functions", null, AllIcons.Nodes.Test - ) - } + override fun getPresentation(): ActionPresentation = + ActionPresentationData("Hide #[test] functions", null, AllIcons.Nodes.Test) override fun getName() = ID @@ -87,11 +81,8 @@ class HideTestOnlyItemsFilter: Filter { } @Suppress("DialogTitleCapitalization") - override fun getPresentation(): ActionPresentation { - return ActionPresentationData( - "Hide #[test_only] items", null, AllIcons.Nodes.Type - ) - } + override fun getPresentation(): ActionPresentation = + ActionPresentationData("Hide #[test_only] items", null, AllIcons.Nodes.Type) override fun getName() = ID diff --git a/src/main/kotlin/org/move/ide/structureView/MvStructureViewTreeElement.kt b/src/main/kotlin/org/move/ide/structureView/MvStructureViewTreeElement.kt index dfdf55214..250ba5db4 100644 --- a/src/main/kotlin/org/move/ide/structureView/MvStructureViewTreeElement.kt +++ b/src/main/kotlin/org/move/ide/structureView/MvStructureViewTreeElement.kt @@ -2,65 +2,76 @@ package org.move.ide.structureView import com.intellij.ide.projectView.PresentationData import com.intellij.ide.structureView.StructureViewTreeElement +import com.intellij.ide.util.treeView.TreeAnchorizer import com.intellij.ide.util.treeView.smartTree.TreeElement import com.intellij.navigation.ItemPresentation import com.intellij.openapi.ui.Queryable import com.intellij.psi.NavigatablePsiElement +import com.intellij.psi.PsiElement +import com.intellij.util.containers.map2Array +import org.move.ide.presentation.getPresentationForStructure import org.move.lang.MoveFile import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* import org.move.openapiext.common.isUnitTestMode -class MvStructureViewTreeElement(val element: NavigatablePsiElement): StructureViewTreeElement, - Queryable { - val isPublic: Boolean - get() { - return when (element) { - is MvFunction -> element.isPublic - is MvConst -> false - else -> true - } - } +class MvStructureViewTreeElement(element: NavigatablePsiElement): StructureViewTreeElement, + Queryable { - val isTestFunction: Boolean + val psiAnchor = TreeAnchorizer.getService().createAnchor(element) + val psi: NavigatablePsiElement? get() = - (element as? MvFunction)?.hasTestAttr ?: false + TreeAnchorizer.getService().retrieveElement(psiAnchor) as? NavigatablePsiElement - val isTestOnlyItem: Boolean - get() = - (element as? MvDocAndAttributeOwner)?.hasTestOnlyAttr ?: false + val isPublicItem: Boolean = + when (val psi = psi) { + is MvFunction -> psi.isPublic + is MvConst -> false + else -> true + } - override fun navigate(requestFocus: Boolean) = element.navigate(requestFocus) - override fun canNavigate(): Boolean = element.canNavigate() - override fun canNavigateToSource(): Boolean = element.canNavigateToSource() - override fun getPresentation(): ItemPresentation = this.element.presentation ?: PresentationData() + val isTestFunction: Boolean get() = (psi as? MvFunction)?.hasTestAttr == true - override fun getChildren(): Array { - val items = when (element) { - is MoveFile -> { - listOf( - element.modules().toList(), - element.scripts().flatMap { it.functionList } - ).flatten() - } - is MvAddressDef -> element.modules() - is MvModule -> { - listOf( - element.consts(), - element.structs(), - element.enumList, - element.allFunctions(), - element.specFunctions(), - ).flatten() - } - is MvFieldsOwner -> element.namedFields - is MvEnum -> element.variants - else -> emptyList() - } - return items.map { MvStructureViewTreeElement(it) }.toTypedArray() + val isTestOnlyItem: Boolean get() = (psi as? MvDocAndAttributeOwner)?.hasTestOnlyAttr == true + + override fun navigate(requestFocus: Boolean) { + psi?.navigate(requestFocus) } - override fun getValue(): Any = this.element + override fun canNavigate(): Boolean = psi?.canNavigate() == true + override fun canNavigateToSource(): Boolean = psi?.canNavigateToSource() == true + override fun getValue(): PsiElement? = psi + + override fun getPresentation(): ItemPresentation = + psi?.let(::getPresentationForStructure) ?: PresentationData("", null, null, null) + + override fun getChildren(): Array = + childElements.map2Array { MvStructureViewTreeElement(it) } + + private val childElements: List + get() { + return when (val psi = psi) { + is MoveFile -> { + listOf( + psi.modules().toList(), + psi.scripts().flatMap { it.functionList } + ).flatten() + } + is MvAddressDef -> psi.modules() + is MvModule -> { + listOf( + psi.consts(), + psi.structs(), + psi.enumList, + psi.allFunctions(), + psi.specFunctions(), + ).flatten() + } + is MvFieldsOwner -> psi.namedFields + is MvEnum -> psi.variants + else -> emptyList() + } + } // Used in `RsStructureViewTest` override fun putInfo(info: MutableMap) { diff --git a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt index 70baee89d..dd1a73253 100644 --- a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt +++ b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt @@ -23,18 +23,6 @@ interface MvFunctionLike: MvNameIdentifierOwner, val returnType: MvReturnType? } -val MvFunctionLike.functionItemPresentation: PresentationData? - get() { - val name = this.name ?: return null - val signature = this.signatureText - return PresentationData( - "$name$signature", - this.locationString(true), - MoveIcons.FUNCTION, - TextAttributesKey.createTextAttributesKey("public") - ) - } - val MvFunctionLike.isNative get() = hasChild(MvElementTypes.NATIVE) val MvFunctionLike.parameters get() = this.functionParameterList?.functionParameterList.orEmpty() diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvAddressDef.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvAddressDef.kt index 9e50a1d9a..0d4b4c5c2 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvAddressDef.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvAddressDef.kt @@ -3,6 +3,7 @@ package org.move.lang.core.psi.ext import com.intellij.ide.projectView.PresentationData import com.intellij.lang.ASTNode import com.intellij.navigation.ItemPresentation +import org.move.ide.presentation.locationString import org.move.lang.core.psi.MvAddressDef import org.move.lang.core.psi.MvElementImpl import org.move.lang.core.psi.MvModule @@ -13,13 +14,14 @@ fun MvAddressDef.modules(): List = addressBlock?.childrenOfType().orEmpty() -abstract class MvAddressDefMixin(node: ASTNode) : MvElementImpl(node), - MvAddressDef { +abstract class MvAddressDefMixin(node: ASTNode): MvElementImpl(node), + MvAddressDef { + override fun getPresentation(): ItemPresentation? { val addressText = this.addressRef?.address(this.moveProject)?.text() ?: "" return PresentationData( addressText, - this.locationString(true), + this.locationString(tryRelative = true), null, null ) diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvConst.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvConst.kt index a5719e711..32c1a1838 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvConst.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvConst.kt @@ -29,14 +29,4 @@ abstract class MvConstMixin : MvStubbedNamedElementImpl, } override fun getIcon(flags: Int): Icon? = MoveIcons.CONST - - override fun getPresentation(): ItemPresentation { - val type = this.type?.let { ": ${it.text}" } ?: "" - return PresentationData( - "${this.name}$type", - this.locationString(true), - MoveIcons.CONST, - null - ) - } } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvEnum.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvEnum.kt index 013251990..13bc2a708 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvEnum.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvEnum.kt @@ -43,15 +43,5 @@ abstract class MvEnumMixin: MvStubbedNamedElementImpl, 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() } \ No newline at end of file diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvEnumVariant.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvEnumVariant.kt index 37ea8ea9e..e00e6f841 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvEnumVariant.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvEnumVariant.kt @@ -21,26 +21,5 @@ abstract class MvEnumVariantMixin: MvStubbedNamedElementImpl, 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 - ) - } + override fun getIcon(flags: Int): Icon = MoveIcons.ENUM_VARIANT } \ No newline at end of file diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt index 5a156e884..e886d32c4 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt @@ -139,6 +139,4 @@ abstract class MvFunctionMixin : MvStubbedNamedElementImpl, override fun canNavigateToSource(): Boolean = !builtIn override fun getIcon(flags: Int): Icon = MoveIcons.FUNCTION - - override fun getPresentation(): ItemPresentation? = this.functionItemPresentation } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvModule.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvModule.kt index cfd7f6578..c3354b5b2 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvModule.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvModule.kt @@ -215,18 +215,6 @@ abstract class MvModuleMixin: MvStubbedNamedElementImpl, override fun getIcon(flags: Int): Icon = MoveIcons.MODULE - override fun getPresentation(): ItemPresentation? { - val name = this.name ?: return null - val moveProj = this.moveProject - val locationString = this.address(moveProj)?.text() ?: "" - return PresentationData( - name, - locationString, - MoveIcons.MODULE, - null - ) - } - override val qualName: ItemQualName? get() { // from stub diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt index c5edc09d8..ee6e6a63f 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt @@ -1,13 +1,11 @@ package org.move.lang.core.psi.ext 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.MvModule import org.move.lang.core.psi.MvSpecFunction import org.move.lang.core.psi.MvSpecInlineFunction -import org.move.lang.core.psi.functionItemPresentation import org.move.lang.core.psi.impl.MvNameIdentifierOwnerImpl import org.move.lang.core.stubs.MvSpecFunctionStub import org.move.lang.core.stubs.MvStubbedNamedElementImpl @@ -16,12 +14,12 @@ import javax.swing.Icon val MvSpecFunction.module: MvModule? get() = this.parent as? MvModule -abstract class MvSpecFunctionMixin : MvStubbedNamedElementImpl, - MvSpecFunction { +abstract class MvSpecFunctionMixin: MvStubbedNamedElementImpl, + MvSpecFunction { - constructor(node: ASTNode) : super(node) + constructor(node: ASTNode): super(node) - constructor(stub: MvSpecFunctionStub, nodeType: IStubElementType<*, *>) : super(stub, nodeType) + constructor(stub: MvSpecFunctionStub, nodeType: IStubElementType<*, *>): super(stub, nodeType) override val qualName: ItemQualName? get() { @@ -31,15 +29,10 @@ abstract class MvSpecFunctionMixin : MvStubbedNamedElementImpl, override fun getIcon(flags: Int): Icon = MoveIcons.STRUCT - override fun getPresentation(): ItemPresentation? { - val structName = this.name ?: return null - return PresentationData( - structName, - this.locationString(true), - MoveIcons.STRUCT, - null - ) - } - override val abilitiesList: MvAbilitiesList? get() = abilitiesListList.firstOrNull() } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvStructField.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvStructField.kt index 775e1c42f..8804085ac 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvStructField.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvStructField.kt @@ -17,14 +17,4 @@ abstract class MvNamedFieldDeclMixin(node: ASTNode) : MvMandatoryNameIdentifierO MvNamedFieldDecl { override fun getIcon(flags: Int): Icon = MoveIcons.STRUCT_FIELD - - override fun getPresentation(): ItemPresentation { - val type = this.type?.let { ": ${it.text}" } ?: "" - return PresentationData( - "${this.name}$type", - this.locationString(true), - MoveIcons.STRUCT_FIELD, - null - ) - } } \ No newline at end of file diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt b/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt index fa688f40a..761113db5 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt @@ -11,10 +11,11 @@ import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiUtilCore import com.intellij.psi.util.descendantsOfType import com.intellij.psi.util.prevLeaf -import com.intellij.util.SmartList import org.move.lang.MoveFile import org.move.lang.core.psi.* import org.move.lang.core.stubs.impl.MvFileStub +import org.move.lang.core.types.address +import org.move.lang.moveProject import org.move.lang.toNioPathOrNull import org.move.openapiext.document import org.move.openapiext.rootPath @@ -354,20 +355,5 @@ private fun PsiElement.getLineCount(): Int { return (text ?: "").count { it == '\n' } + 1 } -fun PsiWhiteSpace.isMultiLine(): Boolean = getLineCount() > 1 - -fun PsiElement.locationPath(tryRelative: Boolean): Path? { - val containingFilePath = this.containingFile.toNioPathOrNull() ?: return null - if (tryRelative) { - val rootPath = this.project.rootPath - if (rootPath != null) { - return rootPath.relativize(containingFilePath) - } - } - return containingFilePath -} - -fun PsiElement.locationString(tryRelative: Boolean): String? = - locationPath(tryRelative)?.toString() diff --git a/src/main/kotlin/org/move/lang/core/psi/impl/MvNameIdentifierOwnerImpl.kt b/src/main/kotlin/org/move/lang/core/psi/impl/MvNameIdentifierOwnerImpl.kt index 8dd92be33..000001f8b 100644 --- a/src/main/kotlin/org/move/lang/core/psi/impl/MvNameIdentifierOwnerImpl.kt +++ b/src/main/kotlin/org/move/lang/core/psi/impl/MvNameIdentifierOwnerImpl.kt @@ -1,6 +1,7 @@ package org.move.lang.core.psi.impl import com.intellij.lang.ASTNode +import com.intellij.navigation.ItemPresentation import com.intellij.psi.PsiElement import org.move.lang.core.psi.MvMandatoryNameIdentifierOwner import org.move.lang.core.psi.MvNameIdentifierOwner @@ -8,10 +9,14 @@ import org.move.lang.core.psi.MvNameIdentifierOwner abstract class MvNameIdentifierOwnerImpl(node: ASTNode) : MvNamedElementImpl(node), MvNameIdentifierOwner { override fun getNameIdentifier(): PsiElement? = nameElement + + override fun getPresentation(): ItemPresentation? = org.move.ide.presentation.getPresentation(this) } abstract class MvMandatoryNameIdentifierOwnerImpl(node: ASTNode): MvMandatoryNamedElementImpl(node), MvMandatoryNameIdentifierOwner { override fun getNameIdentifier(): PsiElement = nameElement + + override fun getPresentation(): ItemPresentation? = org.move.ide.presentation.getPresentation(this) } diff --git a/src/main/kotlin/org/move/lang/core/psi/impl/MvNamedElementImpl.kt b/src/main/kotlin/org/move/lang/core/psi/impl/MvNamedElementImpl.kt index 728bd34a7..fb5a61cbf 100644 --- a/src/main/kotlin/org/move/lang/core/psi/impl/MvNamedElementImpl.kt +++ b/src/main/kotlin/org/move/lang/core/psi/impl/MvNamedElementImpl.kt @@ -7,8 +7,8 @@ import org.move.lang.core.psi.MvMandatoryNamedElement import org.move.lang.core.psi.MvNamedElement import org.move.lang.core.psi.psiFactory -abstract class MvNamedElementImpl(node: ASTNode) : MvElementImpl(node), - MvNamedElement { +abstract class MvNamedElementImpl(node: ASTNode): MvElementImpl(node), + MvNamedElement { override fun getName(): String? = nameElement?.text override fun setName(name: String): PsiElement { @@ -20,11 +20,9 @@ abstract class MvNamedElementImpl(node: ASTNode) : MvElementImpl(node), override fun getNavigationElement(): PsiElement = nameElement ?: this override fun getTextOffset(): Int = nameElement?.textOffset ?: super.getTextOffset() - -// override val fqName: String get() = "" } -abstract class MvMandatoryNamedElementImpl(node: ASTNode) : MvNamedElementImpl(node), - MvMandatoryNamedElement { +abstract class MvMandatoryNamedElementImpl(node: ASTNode): MvNamedElementImpl(node), + MvMandatoryNamedElement { override fun getName(): String = nameElement.text } diff --git a/src/main/kotlin/org/move/lang/core/stubs/StubUtils.kt b/src/main/kotlin/org/move/lang/core/stubs/StubUtils.kt index 0145c7fbf..113a8a27d 100644 --- a/src/main/kotlin/org/move/lang/core/stubs/StubUtils.kt +++ b/src/main/kotlin/org/move/lang/core/stubs/StubUtils.kt @@ -2,6 +2,7 @@ package org.move.lang.core.stubs import com.intellij.extapi.psi.StubBasedPsiElementBase import com.intellij.lang.ASTNode +import com.intellij.navigation.ItemPresentation import com.intellij.psi.PsiElement import com.intellij.psi.stubs.IStubElementType import com.intellij.psi.stubs.StubElement @@ -9,6 +10,7 @@ import org.move.lang.MvElementTypes import org.move.lang.core.psi.MvElement import org.move.lang.core.psi.MvNameIdentifierOwner import org.move.lang.core.psi.MvPsiFactory +import org.move.ide.presentation.getPresentation abstract class MvStubbedElementImpl> : StubBasedPsiElementBase, MvElement { @@ -41,4 +43,6 @@ abstract class MvStubbedNamedElementImpl : MvStubbedElementImpl, } override fun getTextOffset(): Int = nameIdentifier?.textOffset ?: super.getTextOffset() + + override fun getPresentation(): ItemPresentation? = getPresentation(this) } diff --git a/src/test/kotlin/org/move/ide/structureView/StructureViewTestBase.kt b/src/test/kotlin/org/move/ide/structureView/StructureViewTestBase.kt index 5248318d1..766560d78 100644 --- a/src/test/kotlin/org/move/ide/structureView/StructureViewTestBase.kt +++ b/src/test/kotlin/org/move/ide/structureView/StructureViewTestBase.kt @@ -14,9 +14,7 @@ abstract class StructureViewTestBase: MvTestBase() { actions: StructureViewComponent.() -> Unit ) { myFixture.configureByText("main.move", code) - myFixture.testStructureView { - it.actions() - } + myFixture.testStructureView { it.actions() } } protected fun assertTreeEqual(tree: JTree, expected: String) { From 102402e09db47c576bcd51611d315aac5acb6dcd Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Fri, 8 Nov 2024 13:49:39 +0100 Subject: [PATCH 2/3] add old lookup element builder --- .../lang/core/completion/LookupElements.kt | 76 ++----------------- .../lang/core/completion/LookupElements2.kt | 18 +++-- .../providers/MvPathCompletionProvider2.kt | 6 +- .../StructFieldsCompletionProvider.kt | 4 +- .../lookups/BuiltInFunctionLookupTest.kt | 4 +- .../completion/lookups/LookupElementTest.kt | 5 +- 6 files changed, 24 insertions(+), 89 deletions(-) diff --git a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt index f5a113e25..d92be9279 100644 --- a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt +++ b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt @@ -62,21 +62,18 @@ data class MvCompletionContext( val structAsType: Boolean = false ) -fun MvNamedElement.createLookupElement( - completionContext: MvCompletionContext, +fun MvNamedElement.createLookupFromNamedElement( + completionCtx: MvCompletionContext, subst: Substitution = emptySubstitution, priority: Double = DEFAULT_PRIORITY, - insertHandler: InsertHandler = DefaultInsertHandler(completionContext), + insertHandler: InsertHandler = DefaultInsertHandler(completionCtx), ): LookupElement { + val scopeName = this.name ?: "" val builder = - this.getLookupElementBuilder( - completionContext, - subst = subst, - structAsType = completionContext.structAsType - ) + this.getLookupElementBuilder2(completionCtx, scopeName, subst) .withInsertHandler(insertHandler) .withPriority(priority) - val props = getLookupElementProperties(this, subst, completionContext) + val props = getLookupElementProperties(this, subst, completionCtx) return builder.toMvLookupElement(properties = props) } @@ -204,67 +201,6 @@ open class DefaultInsertHandler(val completionCtx: MvCompletionContext? = null): } } -private fun MvNamedElement.getLookupElementBuilder( - completionCtx: MvCompletionContext, - subst: Substitution = emptySubstitution, - structAsType: Boolean = false -): LookupElementBuilder { - val lookupElementBuilder = this.createLookupElementWithIcon() - val msl = completionCtx.msl - return when (this) { - is MvFunction -> { - val signature = FuncSignature.fromFunction(this, msl).substitute(subst) - if (completionCtx.contextElement is MvMethodOrField) { - lookupElementBuilder - .withTailText(signature.paramsText()) - .withTypeText(signature.retTypeText()) - } else { - lookupElementBuilder - .withTailText(this.signatureText) - .withTypeText(this.outerFileName) - } - } - is MvSpecFunction -> lookupElementBuilder - .withTailText(this.parameters.joinToSignature()) - .withTypeText(this.returnType?.type?.text ?: "()") - - is MvModule -> lookupElementBuilder - .withTailText(this.addressRef()?.let { " ${it.text}" } ?: "") - .withTypeText(this.containingFile?.name) - - is MvStruct -> { - val tailText = if (structAsType) "" else " { ... }" - lookupElementBuilder - .withTailText(tailText) - .withTypeText(this.containingFile?.name) - } - - is MvNamedFieldDecl -> { - val fieldTy = this.type?.loweredType(msl)?.substitute(subst) ?: TyUnknown - lookupElementBuilder - .withTypeText(fieldTy.text(false)) - } - is MvConst -> { - val constTy = this.type?.loweredType(msl) ?: TyUnknown - lookupElementBuilder - .withTypeText(constTy.text(true)) - } - - is MvPatBinding -> { - val bindingInference = this.inference(msl) - // race condition sometimes happens, when file is too big, inference is not finished yet - val ty = bindingInference?.getPatTypeOrUnknown(this) ?: TyUnknown - lookupElementBuilder - .withTypeText(ty.text(true)) - } - - is MvSchema -> lookupElementBuilder - .withTypeText(this.containingFile?.name) - - else -> lookupElementBuilder - } -} - // When a user types `(` while completion, // `com.intellij.codeInsight.completion.DefaultCharFilter` invokes completion with selected item. // And if we insert `()` for the item (for example, function), a user get double parentheses diff --git a/src/main/kotlin/org/move/lang/core/completion/LookupElements2.kt b/src/main/kotlin/org/move/lang/core/completion/LookupElements2.kt index f59b6f2c0..07442e1d8 100644 --- a/src/main/kotlin/org/move/lang/core/completion/LookupElements2.kt +++ b/src/main/kotlin/org/move/lang/core/completion/LookupElements2.kt @@ -21,25 +21,27 @@ fun createLookupElement( insertHandler: InsertHandler = DefaultInsertHandler(completionContext) ): LookupElement { val element = scopeEntry.element - val lookup = element.getLookupElementBuilder(completionContext, scopeEntry.name, subst) + val lookup = element + .getLookupElementBuilder2(completionContext, scopeEntry.name, subst) .withInsertHandler(insertHandler) .withPriority(priority) val props = getLookupElementProperties(element, subst, completionContext) return lookup.toMvLookupElement(properties = props) } -private fun MvNamedElement.getLookupElementBuilder( - context: MvCompletionContext, +fun MvNamedElement.getLookupElementBuilder2( + completionCtx: MvCompletionContext, scopeName: String, subst: Substitution = emptySubstitution, ): LookupElementBuilder { - val msl = context.msl - val base = LookupElementBuilder.createWithSmartPointer(scopeName, this) - .withIcon(this.getIcon(0)) + val base = + LookupElementBuilder.createWithSmartPointer(scopeName, this) + .withIcon(this.getIcon(0)) + val msl = completionCtx.msl return when (this) { is MvFunction -> { val signature = FuncSignature.fromFunction(this, msl).substitute(subst) - if (context.contextElement is MvMethodOrField) { + if (completionCtx.contextElement is MvMethodOrField) { base .withTailText(signature.paramsText()) .withTypeText(signature.retTypeText()) @@ -58,7 +60,7 @@ private fun MvNamedElement.getLookupElementBuilder( .withTypeText(this.containingFile?.name) is MvStruct -> { - val tailText = if (context.structAsType) "" else " { ... }" + val tailText = if (completionCtx.structAsType) "" else " { ... }" base .withTailText(tailText) .withTypeText(this.containingFile?.name) diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider2.kt b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider2.kt index 40a2f5873..855bf0c99 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider2.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider2.kt @@ -3,7 +3,6 @@ package org.move.lang.core.completion.providers import com.intellij.codeInsight.completion.CompletionParameters import com.intellij.codeInsight.completion.CompletionResultSet import com.intellij.openapi.progress.ProgressManager -import com.intellij.openapi.progress.checkCanceled import com.intellij.patterns.ElementPattern import com.intellij.psi.PsiElement import com.intellij.util.ProcessingContext @@ -13,14 +12,13 @@ import org.move.ide.utils.imports.ImportCandidateCollector import org.move.lang.core.MvPsiPattern.path import org.move.lang.core.completion.MvCompletionContext import org.move.lang.core.completion.UNIMPORTED_ITEM_PRIORITY -import org.move.lang.core.completion.createLookupElement +import org.move.lang.core.completion.createLookupFromNamedElement import org.move.lang.core.completion.getOriginalOrSelf import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* import org.move.lang.core.resolve.* import org.move.lang.core.resolve.ref.MvReferenceElement import org.move.lang.core.resolve.ref.Namespace -import org.move.lang.core.resolve.ref.Namespace.MODULE import org.move.lang.core.resolve.ref.TYPES_N_ENUMS import org.move.lang.core.resolve2.PathKind import org.move.lang.core.resolve2.pathKind @@ -134,7 +132,7 @@ object MvPathCompletionProvider2: MvCompletionProvider() { var candidatesCollector = createProcessor { e -> e as CandidateScopeEntry - val lookupElement = e.element.createLookupElement( + val lookupElement = e.element.createLookupFromNamedElement( completionContext, priority = UNIMPORTED_ITEM_PRIORITY, insertHandler = ImportInsertHandler(parameters, e.candidate) diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/StructFieldsCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/StructFieldsCompletionProvider.kt index 9f282a382..32509f4cd 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/StructFieldsCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/StructFieldsCompletionProvider.kt @@ -8,7 +8,7 @@ import com.intellij.patterns.StandardPatterns import com.intellij.psi.PsiElement import com.intellij.util.ProcessingContext import org.move.lang.core.completion.MvCompletionContext -import org.move.lang.core.completion.createLookupElement +import org.move.lang.core.completion.createLookupFromNamedElement import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* import org.move.lang.core.withParent @@ -68,7 +68,7 @@ object StructFieldsCompletionProvider: MvCompletionProvider() { ) { for (field in referredStruct.namedFields.filter { it.name !in providedFieldNames }) { result.addElement( - field.createLookupElement(completionContext) + field.createLookupFromNamedElement(completionContext) ) } } diff --git a/src/test/kotlin/org/move/lang/completion/lookups/BuiltInFunctionLookupTest.kt b/src/test/kotlin/org/move/lang/completion/lookups/BuiltInFunctionLookupTest.kt index 788756387..755bac729 100644 --- a/src/test/kotlin/org/move/lang/completion/lookups/BuiltInFunctionLookupTest.kt +++ b/src/test/kotlin/org/move/lang/completion/lookups/BuiltInFunctionLookupTest.kt @@ -3,7 +3,7 @@ package org.move.lang.completion.lookups import com.intellij.codeInsight.lookup.LookupElement import com.intellij.codeInsight.lookup.LookupElementPresentation import org.move.lang.core.completion.MvCompletionContext -import org.move.lang.core.completion.createLookupElement +import org.move.lang.core.completion.createLookupFromNamedElement import org.move.lang.core.psi.MvModule import org.move.lang.core.psi.ext.builtinFunctions import org.move.utils.tests.MvTestBase @@ -43,7 +43,7 @@ class BuiltInFunctionLookupTest: MvTestBase() { val moduleElement = myFixture.findElementInEditor() val lookup = moduleElement.builtinFunctions().single { it.name == name }.let { - it.createLookupElement(MvCompletionContext(it, false)) + it.createLookupFromNamedElement(MvCompletionContext(it, false)) // it.createLookupElement(CompletionContext(it, ContextScopeInfo.default())) } checkLookupPresentation( diff --git a/src/test/kotlin/org/move/lang/completion/lookups/LookupElementTest.kt b/src/test/kotlin/org/move/lang/completion/lookups/LookupElementTest.kt index b0f19f33c..802be2e4c 100644 --- a/src/test/kotlin/org/move/lang/completion/lookups/LookupElementTest.kt +++ b/src/test/kotlin/org/move/lang/completion/lookups/LookupElementTest.kt @@ -9,7 +9,7 @@ import com.intellij.patterns.ElementPattern import com.intellij.psi.NavigatablePsiElement import org.intellij.lang.annotations.Language import org.move.lang.core.completion.MvCompletionContext -import org.move.lang.core.completion.createLookupElement +import org.move.lang.core.completion.createLookupFromNamedElement import org.move.lang.core.completion.providers.MethodOrFieldCompletionProvider import org.move.lang.core.psi.MvElement import org.move.lang.core.psi.MvNamedElement @@ -197,8 +197,7 @@ class LookupElementTest: MvTestBase() { ?: error("Marker `^` should point to the MvNamedElement") val completionCtx = MvCompletionContext(element, false) -// val completionCtx = CompletionContext(element, ContextScopeInfo.default()) - val lookup = element.createLookupElement(completionCtx) + val lookup = element.createLookupFromNamedElement(completionCtx) checkLookupPresentation( lookup, tailText = tailText, From 7a932092c160851a61e10beca89f76a7069cb3d1 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Fri, 8 Nov 2024 14:02:11 +0100 Subject: [PATCH 3/3] remove old lookup builder functions --- .../lang/core/completion/LookupElements.kt | 24 +------------------ .../providers/MvPathCompletionProvider2.kt | 5 ++-- .../providers/SpecItemCompletionProvider.kt | 6 +++-- .../StructFieldsCompletionProvider.kt | 7 ++++-- .../lookups/BuiltInFunctionLookupTest.kt | 9 ++++--- .../completion/lookups/LookupElementTest.kt | 9 +++++-- 6 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt index d92be9279..dd62f211e 100644 --- a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt +++ b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt @@ -8,13 +8,12 @@ import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.openapi.editor.EditorModificationUtil import com.intellij.psi.PsiElement import com.intellij.psi.util.PsiTreeUtil -import org.move.ide.presentation.text import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* +import org.move.lang.core.resolve.ScopeEntry import org.move.lang.core.resolve2.ref.ResolutionContext import org.move.lang.core.types.infer.* import org.move.lang.core.types.ty.Ty -import org.move.lang.core.types.ty.TyUnknown const val KEYWORD_PRIORITY = 80.0 @@ -48,12 +47,6 @@ const val VECTOR_LITERAL_PRIORITY = 30.0 //const val MACRO_PRIORITY = -0.1 //const val DEPRECATED_PRIORITY = -1.0 -fun MvNamedElement.createLookupElementWithIcon(): LookupElementBuilder { - return LookupElementBuilder - .createWithIcon(this) - .withLookupString(this.name ?: "") -} - data class MvCompletionContext( val contextElement: MvElement, val msl: Boolean, @@ -62,21 +55,6 @@ data class MvCompletionContext( val structAsType: Boolean = false ) -fun MvNamedElement.createLookupFromNamedElement( - completionCtx: MvCompletionContext, - subst: Substitution = emptySubstitution, - priority: Double = DEFAULT_PRIORITY, - insertHandler: InsertHandler = DefaultInsertHandler(completionCtx), -): LookupElement { - val scopeName = this.name ?: "" - val builder = - this.getLookupElementBuilder2(completionCtx, scopeName, subst) - .withInsertHandler(insertHandler) - .withPriority(priority) - val props = getLookupElementProperties(this, subst, completionCtx) - return builder.toMvLookupElement(properties = props) -} - fun InsertionContext.addSuffix(suffix: String) { document.insertString(selectionEndOffset, suffix) EditorModificationUtil.moveCaretRelatively(editor, suffix.length) diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider2.kt b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider2.kt index 855bf0c99..0d6f1bf03 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider2.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider2.kt @@ -12,7 +12,7 @@ import org.move.ide.utils.imports.ImportCandidateCollector import org.move.lang.core.MvPsiPattern.path import org.move.lang.core.completion.MvCompletionContext import org.move.lang.core.completion.UNIMPORTED_ITEM_PRIORITY -import org.move.lang.core.completion.createLookupFromNamedElement +import org.move.lang.core.completion.createLookupElement import org.move.lang.core.completion.getOriginalOrSelf import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* @@ -132,7 +132,8 @@ object MvPathCompletionProvider2: MvCompletionProvider() { var candidatesCollector = createProcessor { e -> e as CandidateScopeEntry - val lookupElement = e.element.createLookupFromNamedElement( + val lookupElement = createLookupElement( + e, completionContext, priority = UNIMPORTED_ITEM_PRIORITY, insertHandler = ImportInsertHandler(parameters, e.candidate) diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/SpecItemCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/SpecItemCompletionProvider.kt index 5db74e8fd..8c7833d12 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/SpecItemCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/SpecItemCompletionProvider.kt @@ -2,11 +2,11 @@ package org.move.lang.core.completion.providers import com.intellij.codeInsight.completion.CompletionParameters import com.intellij.codeInsight.completion.CompletionResultSet +import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.util.ProcessingContext import org.move.lang.core.MvPsiPattern import org.move.lang.core.completion.addSuffix import org.move.lang.core.completion.alreadyHasSpace -import org.move.lang.core.completion.createLookupElementWithIcon import org.move.lang.core.psi.MvItemSpecRef import org.move.lang.core.psi.ext.itemSpec import org.move.lang.core.psi.ext.module @@ -24,7 +24,9 @@ object SpecItemCompletionProvider: MvCompletionProvider() { val module = itemSpecRef.itemSpec.module ?: return module.mslSpecifiableItems .forEach { - val lookup = it.createLookupElementWithIcon() + val name = it.name ?: return@forEach + val lookup = LookupElementBuilder.createWithSmartPointer(name, it) + .withIcon(it.getIcon(0)) .withInsertHandler { ctx, _ -> if (!ctx.alreadyHasSpace) ctx.addSuffix(" ") } diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/StructFieldsCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/StructFieldsCompletionProvider.kt index 32509f4cd..ad4714fba 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/StructFieldsCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/StructFieldsCompletionProvider.kt @@ -8,9 +8,10 @@ import com.intellij.patterns.StandardPatterns import com.intellij.psi.PsiElement import com.intellij.util.ProcessingContext import org.move.lang.core.completion.MvCompletionContext -import org.move.lang.core.completion.createLookupFromNamedElement +import org.move.lang.core.completion.createLookupElement import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* +import org.move.lang.core.resolve2.ref.FieldResolveVariant import org.move.lang.core.withParent object StructFieldsCompletionProvider: MvCompletionProvider() { @@ -67,8 +68,10 @@ object StructFieldsCompletionProvider: MvCompletionProvider() { completionContext: MvCompletionContext, ) { for (field in referredStruct.namedFields.filter { it.name !in providedFieldNames }) { + val scopeEntry = FieldResolveVariant(field.name, field) + createLookupElement(scopeEntry, completionContext) result.addElement( - field.createLookupFromNamedElement(completionContext) + createLookupElement(scopeEntry, completionContext) ) } } diff --git a/src/test/kotlin/org/move/lang/completion/lookups/BuiltInFunctionLookupTest.kt b/src/test/kotlin/org/move/lang/completion/lookups/BuiltInFunctionLookupTest.kt index 755bac729..80aa4da56 100644 --- a/src/test/kotlin/org/move/lang/completion/lookups/BuiltInFunctionLookupTest.kt +++ b/src/test/kotlin/org/move/lang/completion/lookups/BuiltInFunctionLookupTest.kt @@ -3,9 +3,11 @@ package org.move.lang.completion.lookups import com.intellij.codeInsight.lookup.LookupElement import com.intellij.codeInsight.lookup.LookupElementPresentation import org.move.lang.core.completion.MvCompletionContext -import org.move.lang.core.completion.createLookupFromNamedElement +import org.move.lang.core.completion.createLookupElement import org.move.lang.core.psi.MvModule import org.move.lang.core.psi.ext.builtinFunctions +import org.move.lang.core.resolve.SimpleScopeEntry +import org.move.lang.core.resolve.ref.NAMES import org.move.utils.tests.MvTestBase import org.move.utils.tests.base.findElementInEditor @@ -43,8 +45,9 @@ class BuiltInFunctionLookupTest: MvTestBase() { val moduleElement = myFixture.findElementInEditor() val lookup = moduleElement.builtinFunctions().single { it.name == name }.let { - it.createLookupFromNamedElement(MvCompletionContext(it, false)) -// it.createLookupElement(CompletionContext(it, ContextScopeInfo.default())) + val scopeEntry = SimpleScopeEntry(name, it, NAMES) + val completionCtx = MvCompletionContext(it, false) + createLookupElement(scopeEntry, completionCtx) } checkLookupPresentation( lookup, diff --git a/src/test/kotlin/org/move/lang/completion/lookups/LookupElementTest.kt b/src/test/kotlin/org/move/lang/completion/lookups/LookupElementTest.kt index 802be2e4c..1535092b8 100644 --- a/src/test/kotlin/org/move/lang/completion/lookups/LookupElementTest.kt +++ b/src/test/kotlin/org/move/lang/completion/lookups/LookupElementTest.kt @@ -9,12 +9,14 @@ import com.intellij.patterns.ElementPattern import com.intellij.psi.NavigatablePsiElement import org.intellij.lang.annotations.Language import org.move.lang.core.completion.MvCompletionContext -import org.move.lang.core.completion.createLookupFromNamedElement +import org.move.lang.core.completion.createLookupElement import org.move.lang.core.completion.providers.MethodOrFieldCompletionProvider import org.move.lang.core.psi.MvElement import org.move.lang.core.psi.MvNamedElement import org.move.lang.core.psi.ext.MvMethodOrField +import org.move.lang.core.resolve.SimpleScopeEntry import org.move.lang.core.resolve.ref.MvReferenceElement +import org.move.lang.core.resolve.ref.NAMES import org.move.utils.tests.MoveV2 import org.move.utils.tests.MvTestBase import org.move.utils.tests.base.findElementInEditor @@ -196,8 +198,11 @@ class LookupElementTest: MvTestBase() { val element = myFixture.findElementInEditor() as? MvNamedElement ?: error("Marker `^` should point to the MvNamedElement") + val name = element.name ?: error("name == null") + val scopeEntry = SimpleScopeEntry(name, element, NAMES) val completionCtx = MvCompletionContext(element, false) - val lookup = element.createLookupFromNamedElement(completionCtx) + + val lookup = createLookupElement(scopeEntry, completionCtx) checkLookupPresentation( lookup, tailText = tailText,