Skip to content

Commit

Permalink
remove SpecItemCompletionProvider, move code to ReferenceProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Nov 8, 2024
1 parent 136d6f1 commit e9dc260
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.move.lang.core.psi.ext.prevNonWsSibling
class CommonCompletionContributor: CompletionContributor() {
init {
extend(CompletionType.BASIC, PrimitiveTypesCompletionProvider)
extend(CompletionType.BASIC, SpecItemCompletionProvider)
// extend(CompletionType.BASIC, SpecItemCompletionProvider)

// addresses
extend(CompletionType.BASIC, NamedAddressInUseStmtCompletionProvider)
Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/org/move/lang/core/completion/LookupElements.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,6 +112,16 @@ open class DefaultInsertHandler(val completionCtx: MvCompletionContext? = null):
item: LookupElement
) {
val document = context.document

val itemSpecRef = context.getElementOfType<MvItemSpecRef>()
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
}
}
Expand Down

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ val MvItemSpec.funcItem get() = this.item as? MvFunction

val MvModuleItemSpec.itemSpecBlock: MvSpecCodeBlock? get() = this.childOfType()

val MvModule.mslSpecifiableItems: List<MvNameIdentifierOwner>
get() =
this.allFunctions().chain(this.structs()).toList()

val MvItemSpec.module: MvModule?
get() {
val parent = this.parent
Expand Down
14 changes: 2 additions & 12 deletions src/main/kotlin/org/move/lang/core/psi/ext/MvModule.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -51,16 +49,8 @@ fun MvModule.allFunctions(): List<MvFunction> {
return stub?.childrenStubsOfType<MvFunctionStub>()?.map { it.psi } ?: functionList
}

fun MvModule.allNonTestFunctions(): List<MvFunction> =
// allFunctions().filter { f -> !f.isTest }
this.allFunctions().filter { f -> !f.hasTestAttr }
// getProjectPsiDependentCache(this) {
// }

fun MvModule.testFunctions(): List<MvFunction> =
getProjectPsiDependentCache(this) {
it.allFunctions().filter { f -> f.hasTestAttr }
}
fun MvModule.allNonTestFunctions(): List<MvFunction> = this.allFunctions().filter { f -> !f.hasTestAttr }
fun MvModule.testFunctions(): List<MvFunction> = this.allFunctions().filter { f -> f.hasTestAttr }

val MvModule.isBuiltins: Boolean get() = this.name == "builtins" && (this.address(null)?.is0x0 ?: false)
val MvModule.isSpecBuiltins: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MvItemSpecRef>(element) {

override fun multiResolveInner(): List<MvNamedElement> {
val module = element.itemSpec.module ?: return emptyList()
val referenceName = element.referenceName
return module.mslSpecifiableItems
.filter { it.name == referenceName }
}
override fun multiResolveInner(): List<MvNamedElement> =
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) }
}
)
}

0 comments on commit e9dc260

Please sign in to comment.