diff --git a/src/main/kotlin/org/move/lang/core/completion/CommonCompletionContributor.kt b/src/main/kotlin/org/move/lang/core/completion/CommonCompletionContributor.kt index aac24bebd..301164942 100644 --- a/src/main/kotlin/org/move/lang/core/completion/CommonCompletionContributor.kt +++ b/src/main/kotlin/org/move/lang/core/completion/CommonCompletionContributor.kt @@ -3,9 +3,7 @@ package org.move.lang.core.completion import com.intellij.codeInsight.completion.* import com.intellij.codeInsight.completion.impl.CompletionSorterImpl import com.intellij.psi.util.elementType -import org.move.lang.MvElementTypes.IDENTIFIER import org.move.lang.MvElementTypes.MODULE_KW -import org.move.lang.core.MvPsiPattern import org.move.lang.core.completion.providers.* import org.move.lang.core.completion.sort.COMPLETION_WEIGHERS_GROUPED import org.move.lang.core.psi.MvModule @@ -14,7 +12,6 @@ import org.move.lang.core.psi.ext.prevNonWsSibling class CommonCompletionContributor: CompletionContributor() { init { extend(CompletionType.BASIC, PrimitiveTypesCompletionProvider) - extend(CompletionType.BASIC, SpecItemCompletionProvider) // addresses extend(CompletionType.BASIC, NamedAddressInUseStmtCompletionProvider) @@ -26,11 +23,9 @@ class CommonCompletionContributor: CompletionContributor() { extend(CompletionType.BASIC, SchemaFieldsCompletionProvider) extend(CompletionType.BASIC, MvPathCompletionProvider2) - extend(CompletionType.BASIC, MvPsiPattern.ability(), AbilitiesCompletionProvider) -// extend(CompletionType.BASIC, MvPsiPattern.refExpr(), BoolsCompletionProvider) - + extend(CompletionType.BASIC, AbilitiesCompletionProvider) extend(CompletionType.BASIC, BoolsCompletionProvider) - extend(CompletionType.BASIC, MacrosCompletionProvider) + extend(CompletionType.BASIC, AssertMacroCompletionProvider) extend(CompletionType.BASIC, VectorLiteralCompletionProvider) extend(CompletionType.BASIC, MethodOrFieldCompletionProvider) 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 dd62f211e..6ac350ac5 100644 --- a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt +++ b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt @@ -10,9 +10,7 @@ import com.intellij.psi.PsiElement import com.intellij.psi.util.PsiTreeUtil 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 const val KEYWORD_PRIORITY = 80.0 @@ -114,6 +112,16 @@ open class DefaultInsertHandler(val completionCtx: MvCompletionContext? = null): item: LookupElement ) { val document = context.document + + val itemSpecRef = context.getElementOfType() + if (itemSpecRef != null) { + // inserting item in `spec /*caret*/ {}`, no need for the signature, just insert with leading space + if (!context.alreadyHasSpace) { + context.addSuffix(" ") + } + return + } + when (element) { is MvFunctionLike -> { // no suffix for imports diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/AbilitiesCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/AbilitiesCompletionProvider.kt index 0bec4ae2a..1ea386bcc 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/AbilitiesCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/AbilitiesCompletionProvider.kt @@ -5,10 +5,15 @@ import com.intellij.codeInsight.completion.CompletionProvider import com.intellij.codeInsight.completion.CompletionResultSet import com.intellij.codeInsight.completion.PrioritizedLookupElement import com.intellij.codeInsight.lookup.LookupElementBuilder +import com.intellij.patterns.ElementPattern +import com.intellij.psi.PsiElement import com.intellij.util.ProcessingContext +import org.move.lang.core.MvPsiPattern import org.move.lang.core.completion.KEYWORD_PRIORITY -object AbilitiesCompletionProvider : CompletionProvider() { +object AbilitiesCompletionProvider : MvCompletionProvider() { + override val elementPattern: ElementPattern get() = MvPsiPattern.ability() + override fun addCompletions( parameters: CompletionParameters, context: ProcessingContext, diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/MacrosCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/AssertMacroCompletionProvider.kt similarity index 96% rename from src/main/kotlin/org/move/lang/core/completion/providers/MacrosCompletionProvider.kt rename to src/main/kotlin/org/move/lang/core/completion/providers/AssertMacroCompletionProvider.kt index b7889983d..a983ed0a0 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/MacrosCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/AssertMacroCompletionProvider.kt @@ -14,7 +14,7 @@ import org.move.lang.core.MvPsiPattern import org.move.lang.core.completion.MACRO_PRIORITY import org.move.lang.core.psi.MvPath -object MacrosCompletionProvider : MvCompletionProvider() { +object AssertMacroCompletionProvider : MvCompletionProvider() { override val elementPattern: ElementPattern get() = MvPsiPattern.path() .andNot(MvPsiPattern.pathType()) diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/ReferenceCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/ReferenceCompletionProvider.kt index fc1420c03..b7a217e85 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/ReferenceCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/ReferenceCompletionProvider.kt @@ -7,6 +7,7 @@ import com.intellij.patterns.PlatformPatterns import com.intellij.psi.PsiElement import com.intellij.util.ProcessingContext import org.move.lang.core.completion.MvCompletionContext +import org.move.lang.core.psi.MvItemSpecRef import org.move.lang.core.psi.MvLabel import org.move.lang.core.psi.MvPatBinding import org.move.lang.core.psi.MvPatField @@ -17,6 +18,7 @@ import org.move.lang.core.psiElement import org.move.lang.core.resolve.RsResolveProcessor import org.move.lang.core.resolve.collectCompletionVariants import org.move.lang.core.resolve.ref.MvReferenceElement +import org.move.lang.core.resolve.ref.processItemSpecRefResolveVariants import org.move.lang.core.resolve.wrapWithFilter import org.move.lang.core.resolve2.processLabelResolveVariants import org.move.lang.core.resolve2.processPatBindingResolveVariants @@ -46,9 +48,9 @@ object ReferenceCompletionProvider: MvCompletionProvider() { fun addCompletionVariants( element: MvReferenceElement, result: CompletionResultSet, - context: MvCompletionContext, + completionCtx: MvCompletionContext, ) { - collectCompletionVariants(result, context) { + collectCompletionVariants(result, completionCtx) { val processor0 = filterCompletionVariantsByVisibility(element, it) // todo: filter test functions when (element) { @@ -59,7 +61,10 @@ object ReferenceCompletionProvider: MvCompletionProvider() { val processor = skipAlreadyProvidedFields(element, processor0) processPatBindingResolveVariants(element, true, processor) } + // loop labels is MvLabel -> processLabelResolveVariants(element, it) + // `spec ITEM {}` module items, where ITEM is a reference to the function/struct/enum + is MvItemSpecRef -> processItemSpecRefResolveVariants(element, it) } } } 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 deleted file mode 100644 index 8c7833d12..000000000 --- a/src/main/kotlin/org/move/lang/core/completion/providers/SpecItemCompletionProvider.kt +++ /dev/null @@ -1,38 +0,0 @@ -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.psi.MvItemSpecRef -import org.move.lang.core.psi.ext.itemSpec -import org.move.lang.core.psi.ext.module -import org.move.lang.core.psi.ext.mslSpecifiableItems - -object SpecItemCompletionProvider: MvCompletionProvider() { - override val elementPattern get() = MvPsiPattern.itemSpecRef() - - override fun addCompletions( - parameters: CompletionParameters, - context: ProcessingContext, - result: CompletionResultSet - ) { - val itemSpecRef = parameters.position.parent as? MvItemSpecRef ?: return - val module = itemSpecRef.itemSpec.module ?: return - module.mslSpecifiableItems - .forEach { - val name = it.name ?: return@forEach - val lookup = LookupElementBuilder.createWithSmartPointer(name, it) - .withIcon(it.getIcon(0)) - .withInsertHandler { ctx, _ -> - if (!ctx.alreadyHasSpace) ctx.addSuffix(" ") - } - result.addElement(lookup) - } - } - - -} diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpec.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpec.kt index 494824dc9..572dfb0c5 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpec.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpec.kt @@ -11,10 +11,6 @@ val MvItemSpec.funcItem get() = this.item as? MvFunction val MvModuleItemSpec.itemSpecBlock: MvSpecCodeBlock? get() = this.childOfType() -val MvModule.mslSpecifiableItems: List - get() = - this.allFunctions().chain(this.structs()).toList() - val MvItemSpec.module: MvModule? get() { val parent = this.parent 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 c3354b5b2..1d6e32603 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 @@ -1,8 +1,6 @@ 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.openapi.project.Project import com.intellij.openapi.util.Key import com.intellij.psi.stubs.IStubElementType @@ -51,16 +49,8 @@ fun MvModule.allFunctions(): List { return stub?.childrenStubsOfType()?.map { it.psi } ?: functionList } -fun MvModule.allNonTestFunctions(): List = -// allFunctions().filter { f -> !f.isTest } - this.allFunctions().filter { f -> !f.hasTestAttr } -// getProjectPsiDependentCache(this) { -// } - -fun MvModule.testFunctions(): List = - getProjectPsiDependentCache(this) { - it.allFunctions().filter { f -> f.hasTestAttr } - } +fun MvModule.allNonTestFunctions(): List = this.allFunctions().filter { f -> !f.hasTestAttr } +fun MvModule.testFunctions(): List = this.allFunctions().filter { f -> f.hasTestAttr } val MvModule.isBuiltins: Boolean get() = this.name == "builtins" && (this.address(null)?.is0x0 ?: false) val MvModule.isSpecBuiltins: Boolean diff --git a/src/main/kotlin/org/move/lang/core/resolve/ref/MvItemSpecRefReferenceImpl.kt b/src/main/kotlin/org/move/lang/core/resolve/ref/MvItemSpecRefReferenceImpl.kt index a2bccbb18..9507f8741 100644 --- a/src/main/kotlin/org/move/lang/core/resolve/ref/MvItemSpecRefReferenceImpl.kt +++ b/src/main/kotlin/org/move/lang/core/resolve/ref/MvItemSpecRefReferenceImpl.kt @@ -2,17 +2,37 @@ package org.move.lang.core.resolve.ref import org.move.lang.core.psi.MvItemSpecRef import org.move.lang.core.psi.MvNamedElement +import org.move.lang.core.psi.ext.allNonTestFunctions import org.move.lang.core.psi.ext.itemSpec import org.move.lang.core.psi.ext.module -import org.move.lang.core.psi.ext.mslSpecifiableItems +import org.move.lang.core.psi.ext.structs +import org.move.lang.core.resolve.RsResolveProcessor +import org.move.lang.core.resolve.SimpleScopeEntry +import org.move.lang.core.resolve.collectResolveVariants +import org.move.lang.core.resolve.processAll class MvItemSpecRefReferenceImpl(element: MvItemSpecRef): MvPolyVariantReferenceCached(element) { - override fun multiResolveInner(): List { - val module = element.itemSpec.module ?: return emptyList() - val referenceName = element.referenceName - return module.mslSpecifiableItems - .filter { it.name == referenceName } - } + override fun multiResolveInner(): List = + collectResolveVariants(element.referenceName) { + processItemSpecRefResolveVariants(element, it) + } +} +fun processItemSpecRefResolveVariants( + itemSpecRef: MvItemSpecRef, + processor: RsResolveProcessor +): Boolean { + val module = itemSpecRef.itemSpec.module ?: return false + val mslEnabledItems = + listOf( + module.allNonTestFunctions(), + module.structs(), + module.enumList, + ).flatten() + return processor.processAll( + mslEnabledItems.mapNotNull { + it.name?.let { name -> SimpleScopeEntry(name, it, ALL_NAMESPACES) } + } + ) }