From dcb1ad95680e9825c3def2b5509629a6fc1baae0 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Tue, 6 Aug 2024 20:57:58 +0300 Subject: [PATCH] remove old code --- .../completion/CommonCompletionContributor.kt | 7 - .../providers/FQModuleCompletionProvider.kt | 39 ---- .../providers/ImportsCompletionProvider.kt | 48 ---- .../MethodOrFieldCompletionProvider.kt | 22 +- .../providers/ModulesCompletionProvider.kt | 65 ------ .../providers/MvPathCompletionProvider.kt | 213 ------------------ .../move/lang/core/psi/ext/MvMethodCall.kt | 13 +- .../lang/core/psi/ext/MvStructDotField.kt | 17 +- .../lang/core/resolve/MatchingProcessor.kt | 8 - .../org/move/lang/core/resolve/Processors.kt | 48 +++- .../core/types/infer/TypeInferenceWalker.kt | 6 +- 11 files changed, 64 insertions(+), 422 deletions(-) delete mode 100644 src/main/kotlin/org/move/lang/core/completion/providers/FQModuleCompletionProvider.kt delete mode 100644 src/main/kotlin/org/move/lang/core/completion/providers/ImportsCompletionProvider.kt delete mode 100644 src/main/kotlin/org/move/lang/core/completion/providers/ModulesCompletionProvider.kt delete mode 100644 src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt delete mode 100644 src/main/kotlin/org/move/lang/core/resolve/MatchingProcessor.kt 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 fdf13423c..7a649b2b6 100644 --- a/src/main/kotlin/org/move/lang/core/completion/CommonCompletionContributor.kt +++ b/src/main/kotlin/org/move/lang/core/completion/CommonCompletionContributor.kt @@ -10,9 +10,6 @@ import org.move.lang.core.psi.MvModule class CommonCompletionContributor : CompletionContributor() { init { extend(CompletionType.BASIC, PrimitiveTypesCompletionProvider) -// extend(CompletionType.BASIC, NamesCompletionProvider) -// extend(CompletionType.BASIC, FunctionsCompletionProvider) -// extend(CompletionType.BASIC, SchemasCompletionProvider) extend(CompletionType.BASIC, SpecItemCompletionProvider) // addresses @@ -20,10 +17,6 @@ class CommonCompletionContributor : CompletionContributor() { extend(CompletionType.BASIC, NamedAddressAtValueExprCompletionProvider) extend(CompletionType.BASIC, AddressInModuleDeclCompletionProvider) -// extend(CompletionType.BASIC, TypesCompletionProvider) -// extend(CompletionType.BASIC, ImportsCompletionProvider) -// extend(CompletionType.BASIC, ModulesCompletionProvider) -// extend(CompletionType.BASIC, FQModuleCompletionProvider) extend(CompletionType.BASIC, StructFieldsCompletionProvider) extend(CompletionType.BASIC, StructPatCompletionProvider) extend(CompletionType.BASIC, SchemaFieldsCompletionProvider) diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/FQModuleCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/FQModuleCompletionProvider.kt deleted file mode 100644 index 22d3b4dd2..000000000 --- a/src/main/kotlin/org/move/lang/core/completion/providers/FQModuleCompletionProvider.kt +++ /dev/null @@ -1,39 +0,0 @@ -package org.move.lang.core.completion.providers - -//object FQModuleCompletionProvider: MvCompletionProvider() { -// override val elementPattern: ElementPattern -// get() = -// PlatformPatterns.psiElement() -// .withParent() -// -// override fun addCompletions( -// parameters: CompletionParameters, -// context: ProcessingContext, -// result: CompletionResultSet, -// ) { -// val directParent = parameters.position.parent -// val fqModuleRef = -// directParent as? MvFQModuleRef -// ?: directParent.parent as MvFQModuleRef -// if (parameters.position !== fqModuleRef.referenceNameElement) return -// -// val contextScopeInfo = ContextScopeInfo( -// letStmtScope = fqModuleRef.letStmtScope, -// refItemScopes = fqModuleRef.refItemScopes, -// ) -// val completionContext = CompletionContext(fqModuleRef, contextScopeInfo) -// -// val moveProj = fqModuleRef.moveProject -// val positionAddress = fqModuleRef.addressRef.address(moveProj) -// -// processFQModuleRef(fqModuleRef) { -// val module = it.element -// val moduleAddress = module.address(moveProj) -// if (Address.eq(positionAddress, moduleAddress)) { -// val lookup = module.createLookupElement(completionContext) -// result.addElement(lookup) -// } -// false -// } -// } -//} diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/ImportsCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/ImportsCompletionProvider.kt deleted file mode 100644 index 872455647..000000000 --- a/src/main/kotlin/org/move/lang/core/completion/providers/ImportsCompletionProvider.kt +++ /dev/null @@ -1,48 +0,0 @@ -package org.move.lang.core.completion.providers - -//object ImportsCompletionProvider: MvCompletionProvider() { -// override val elementPattern: ElementPattern -// get() = PlatformPatterns -// .psiElement().withParent() -// -// override fun addCompletions( -// parameters: CompletionParameters, -// context: ProcessingContext, -// result: CompletionResultSet -// ) { -// val itemImport = parameters.position.parent as MvUseItem -// if (parameters.position !== itemImport.referenceNameElement) return -// -// val moduleRef = itemImport.itemUseSpeck.fqModuleRef -// val referredModule = moduleRef.reference?.resolve() as? MvModule -// ?: return -// -// val p = itemImport.parent -// if (p is MvUseItemGroup && "Self" !in p.names) { -// result.addElement(referredModule.createSelfLookup()) -// } -// -// val vs = when { -// moduleRef.isSelfModuleRef -> setOf(Visibility.Internal) -// else -> Visibility.visibilityScopesForElement(itemImport) -// } -// val ns = setOf(Namespace.NAME, Namespace.TYPE, Namespace.FUNCTION) -// val contextScopeInfo = -// ContextScopeInfo( -// letStmtScope = itemImport.letStmtScope, -// refItemScopes = itemImport.refItemScopes, -// ) -// -// val completionContext = CompletionContext(itemImport, contextScopeInfo) -// processModuleItems(referredModule, ns, vs, contextScopeInfo) { -// result.addElement( -// it.element.createLookupElement( -// completionContext, -// insertHandler = BasicInsertHandler(), -// structAsType = true -// ) -// ) -// false -// } -// } -//} diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/MethodOrFieldCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/MethodOrFieldCompletionProvider.kt index de5c37753..3a0b0d2ac 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/MethodOrFieldCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/MethodOrFieldCompletionProvider.kt @@ -10,11 +10,9 @@ import org.jetbrains.annotations.VisibleForTesting import org.move.lang.core.completion.CompletionContext import org.move.lang.core.completion.createLookupElement import org.move.lang.core.psi.MvFunction -import org.move.lang.core.psi.ext.MvMethodOrField -import org.move.lang.core.psi.ext.getFieldVariants -import org.move.lang.core.psi.ext.inferReceiverTy -import org.move.lang.core.psi.ext.isMsl +import org.move.lang.core.psi.ext.* import org.move.lang.core.psi.tyInfers +import org.move.lang.core.resolve.collectCompletionVariants import org.move.lang.core.resolve.createProcessor import org.move.lang.core.resolve2.processMethodResolveVariants import org.move.lang.core.types.infer.InferenceContext @@ -47,25 +45,15 @@ object MethodOrFieldCompletionProvider: MvCompletionProvider() { fun addMethodOrFieldVariants(element: MvMethodOrField, result: CompletionResultSet) { val msl = element.isMsl() val receiverTy = element.inferReceiverTy(msl).knownOrNull() ?: return -// val scopeInfo = ContextScopeInfo( -// letStmtScope = element.letStmtScope, -// refItemScopes = element.refItemScopes, -// ) val expectedTy = getExpectedTypeForEnclosingPathOrDotExpr(element, msl) val ctx = CompletionContext(element, msl, expectedTy) -// val ctx = CompletionContext(element, scopeInfo, msl, expectedTy) val structTy = receiverTy.derefIfNeeded() as? TyStruct if (structTy != null) { - getFieldVariants(element, structTy, msl) - .forEach { (_, field) -> - val lookupElement = field.createLookupElement( - ctx, - subst = structTy.substitution - ) - result.addElement(lookupElement) - } + collectCompletionVariants(result, ctx, subst = structTy.substitution) { + processNamedFieldVariants(element, structTy, msl, it) + } } processMethodResolveVariants(element, receiverTy, ctx.msl, createProcessor { e -> diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/ModulesCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/ModulesCompletionProvider.kt deleted file mode 100644 index 24599d4dc..000000000 --- a/src/main/kotlin/org/move/lang/core/completion/providers/ModulesCompletionProvider.kt +++ /dev/null @@ -1,65 +0,0 @@ -package org.move.lang.core.completion.providers - -//object ModulesCompletionProvider2: MvCompletionProvider() { -// override val elementPattern: ElementPattern -// get() = -// MvPsiPatterns.path() -// -// override fun addCompletions( -// parameters: CompletionParameters, -// context: ProcessingContext, -// result: CompletionResultSet, -// ) { -// val maybePath = parameters.position.parent -// val refElement = -// maybePath as? MvPath ?: maybePath.parent as MvPath -// -// if (parameters.position !== refElement.referenceNameElement) return -// if (refElement.moduleRef != null) return -// -// val processedNames = mutableSetOf() -// val namespaces = setOf(Namespace.MODULE) -// val contextScopeInfo = -// ContextScopeInfo( -// letStmtScope = refElement.letStmtScope, -// refItemScopes = refElement.refItemScopes, -// ) -// val completionCtx = CompletionContext(refElement, contextScopeInfo) -// processItems(refElement, namespaces, contextScopeInfo) { (name, element) -> -// result.addElement( -// element.createLookupElement(completionCtx, priority = IMPORTED_MODULE_PRIORITY) -// ) -// processedNames.add(name) -// false -// } -// -// // disable auto-import in module specs for now -// if (refElement.containingModuleSpec != null) return -// -// val path = parameters.originalPosition?.parent as? MvPath ?: return -// val importContext = -// ImportContext.from( -// path, -// namespaces, -// setOf(Visibility.Public), -// contextScopeInfo -// ) -// val containingMod = path.containingModule -// val candidates = getCompletionCandidates(parameters, result.prefixMatcher, processedNames, importContext, -// itemFilter = { -// containingMod != null && !it.equalsTo( -// containingMod -// ) -// }) -// candidates.forEach { candidate -> -// val lookupElement = -// candidate.element.createLookupElement( -// completionCtx, -// structAsType = Namespace.TYPE in importContext.ns, -// priority = UNIMPORTED_ITEM_PRIORITY, -// insertHandler = ImportInsertHandler(parameters, candidate) -// ) -// result.addElement(lookupElement) -// } -// } -//} diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt deleted file mode 100644 index 0dc7f4228..000000000 --- a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt +++ /dev/null @@ -1,213 +0,0 @@ -package org.move.lang.core.completion.providers - -//fun interface CompletionFilter { -// fun removeEntry(entry: ScopeEntry, ctx: PathResolutionContext): Boolean -//} - -//abstract class MvPathCompletionProvider: MvCompletionProvider() { -// -// abstract val namespaces: Set -// -// open val completionFilters: List = emptyList() -// -// open fun pathScopeInfo(pathElement: MvPath): ContextScopeInfo = -// ContextScopeInfo( -// letStmtScope = pathElement.letStmtScope, -// refItemScopes = pathElement.refItemScopes, -// ) -// -// final override fun addCompletions( -// parameters: CompletionParameters, -// context: ProcessingContext, -// result: CompletionResultSet -// ) { -// val maybePath = parameters.position.parent -// val pathElement = maybePath as? MvPath ?: maybePath.parent as MvPath -// -// if (parameters.position !== pathElement.referenceNameElement) return -// -// val qualifier = pathElement.qualifier -// -// val contextScopeInfo = pathScopeInfo(pathElement) -// val msl = pathElement.isMslScope -// val expectedTy = getExpectedTypeForEnclosingPathOrDotExpr(pathElement, msl) -// val structAsType = Namespace.TYPE in this.namespaces -// -// val completionContext = CompletionContext( -// pathElement, -// contextScopeInfo, -// expectedTy, -// ) -// -// var completionCollector = createProcessor { e -> -// val element = e.element as? MvNamedElement ?: return@createProcessor -// val lookup = -// element.createLookupElement( -// completionContext, -// structAsType = structAsType, -// priority = element.completionPriority -// ) -// result.addElement(lookup) -// } -// -// if (qualifier != null) { -// val resolvedQualifier = qualifier.reference?.resolveFollowingAliases() -// when (resolvedQualifier) { -// is MvModule -> { -// val moduleBlock = resolvedQualifier.moduleBlock -// if (moduleBlock != null) { -// processItemDeclarations(moduleBlock, this.namespaces, completionCollector) -// } -// } -// } -// return -// } -// -//// if (moduleRef != null) { -//// val module = moduleRef.reference?.resolveWithAliases() as? MvModule -//// ?: return -//// val vs = when { -//// moduleRef.isSelfModuleRef -> setOf(Visibility.Internal) -//// else -> Visibility.visibilityScopesForElement(pathElement) -//// } -//// processModuleItems(module, namespaces, vs, contextScopeInfo) { -//// val lookup = -//// it.element.createLookupElement(ctx, structAsType = structAsType) -//// result.addElement(lookup) -//// false -//// } -//// return -//// } -// -// val processedNames = mutableSetOf() -// completionCollector = completionCollector.wrapWithFilter { e -> -// if (processedNames.contains(e.name)) { -// return@wrapWithFilter false -// } -// processedNames.add(e.name) -// true -// } -// -// val resolutionCtx = PathResolutionContext(pathElement, contextScopeInfo) -// -// // custom filters -// completionCollector = completionCollector.wrapWithFilter { -// for (completionFilter in this.completionFilters) { -// if (!completionFilter.removeEntry(it, resolutionCtx)) return@wrapWithFilter false -// } -// true -// } -// -// val ctx = PathResolutionContext(pathElement, contextScopeInfo) -// processNestedScopesUpwards(pathElement, this.namespaces, ctx, completionCollector) -// -//// processItems(pathElement, namespaces, contextScopeInfo) { (name, element) -> -//// if (processedNames.contains(name)) { -//// return@processItems false -//// } -//// processedNames.add(name) -//// result.addElement( -//// element.createLookupElement( -//// completionContext, -//// structAsType = structAsType, -//// priority = element.completionPriority -//// ) -//// ) -//// false -//// } -// -// // disable auto-import in module specs for now -// if (pathElement.containingModuleSpec != null) return -// -// val originalPathElement = parameters.originalPosition?.parent as? MvPath ?: return -// val importContext = -// ImportContext.from( -// originalPathElement, -// this.namespaces, -// setOf(Visibility.Public), -// contextScopeInfo -// ) -// val candidates = getCompletionCandidates( -// parameters, -// result.prefixMatcher, -// processedNames, -// importContext, -// ) -// candidates.forEach { candidate -> -// val entry = SimpleScopeEntry(candidate.qualName.itemName, candidate.element, namespaces) -// for (completionFilter in completionFilters) { -// if (!completionFilter.removeEntry(entry, resolutionCtx)) return@forEach -// } -// val lookupElement = candidate.element.createLookupElement( -// completionContext, -// structAsType = structAsType, -// priority = UNIMPORTED_ITEM_PRIORITY, -// insertHandler = ImportInsertHandler(parameters, candidate) -// ) -// result.addElement(lookupElement) -// } -// } -//} - -//object NamesCompletionProvider: MvPathCompletionProvider() { -// override val elementPattern: ElementPattern -// get() = -// MvPsiPatterns.path() -// .andNot(MvPsiPatterns.pathType()) -// .andNot(MvPsiPatterns.schemaLit()) -// -// override val namespaces: Set get() = EnumSet.of(Namespace.NAME) -//} - -//object FunctionsCompletionProvider: MvPathCompletionProvider() { -// override val elementPattern: ElementPattern -// get() = -// MvPsiPatterns.path() -// .andNot(MvPsiPatterns.pathType()) -// .andNot(MvPsiPatterns.schemaLit()) -// -// override val namespaces: Set get() = EnumSet.of(Namespace.FUNCTION) -//} - -//object TypesCompletionProvider: MvPathCompletionProvider() { -// override val elementPattern: ElementPattern -// get() = MvPsiPatterns.pathType() -// -// override val namespaces: Set get() = EnumSet.of(Namespace.TYPE) -//} - -//object SchemasCompletionProvider: MvPathCompletionProvider() { -// override val elementPattern: ElementPattern -// get() = -// StandardPatterns.or( -// MvPsiPatterns.schemaLit(), MvPsiPatterns.pathInsideIncludeStmt() -// ) -// -// override val namespaces: Set get() = EnumSet.of(Namespace.SCHEMA) -// -// override fun pathScopeInfo(pathElement: MvPath): ContextScopeInfo { -// return ContextScopeInfo( -// letStmtScope = LetStmtScope.EXPR_STMT, -// refItemScopes = pathElement.refItemScopes, -// ) -// } -//} - -//object ModulesCompletionProvider: MvPathCompletionProvider() { -// override val elementPattern: ElementPattern -// get() = -// MvPsiPatterns.path() -// .andNot(MvPsiPatterns.pathType()) -// .andNot(MvPsiPatterns.schemaLit()) -// -// override val namespaces: Set get() = EnumSet.of(Namespace.MODULE) -// -// override val completionFilters: List -// get() = listOf( -// // filter out the current module -// CompletionFilter { e, ctx -> -// if (e.element is MvModule) -// return@CompletionFilter ctx.containingModule?.let { e.element.equalsTo(it) } ?: true -// true -// }) -//} diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvMethodCall.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvMethodCall.kt index 3395740bc..a5b5d71d8 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvMethodCall.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvMethodCall.kt @@ -4,7 +4,6 @@ import com.intellij.lang.ASTNode import com.intellij.psi.PsiElement import org.move.cli.MoveProject import org.move.lang.core.psi.* -import org.move.lang.core.resolve.ScopeItem import org.move.lang.core.resolve.ref.MvPolyVariantReference import org.move.lang.core.resolve.ref.MvPolyVariantReferenceBase import org.move.lang.core.types.address @@ -14,13 +13,13 @@ import org.move.lang.core.types.ty.TyStruct import org.move.lang.core.types.ty.TyVector import org.move.stdext.wrapWithList -typealias MatchSequence = Sequence> +//typealias MatchSequence = Sequence> -fun MatchSequence.filterByName(refName: String): Sequence { - return this - .filter { it.name == refName } - .map { it.element } -} +//fun MatchSequence.filterByName(refName: String): Sequence { +// return this +// .filter { it.name == refName } +// .map { it.element } +//} fun Ty.itemModule(moveProject: MoveProject): MvModule? { val norefTy = this.derefIfNeeded() diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvStructDotField.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvStructDotField.kt index bbd467238..d2016aa8e 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvStructDotField.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvStructDotField.kt @@ -2,26 +2,27 @@ package org.move.lang.core.psi.ext import com.intellij.lang.ASTNode import org.move.lang.core.psi.* -import org.move.lang.core.resolve.ScopeItem +import org.move.lang.core.resolve.RsResolveProcessor +import org.move.lang.core.resolve.processAll import org.move.lang.core.resolve.ref.MvPolyVariantReference import org.move.lang.core.resolve.ref.MvPolyVariantReferenceBase import org.move.lang.core.types.infer.inference import org.move.lang.core.types.ty.TyStruct import org.move.stdext.wrapWithList -fun getFieldVariants( +fun processNamedFieldVariants( element: MvMethodOrField, receiverTy: TyStruct, - msl: Boolean -): MatchSequence { + msl: Boolean, + processor: RsResolveProcessor +): Boolean { val structItem = receiverTy.item if (!msl) { // cannot resolve field if not in the same module as struct definition - val dotExprModule = element.namespaceModule ?: return emptySequence() - if (structItem.containingModule != dotExprModule) return emptySequence() + val dotExprModule = element.namespaceModule ?: return false + if (structItem.containingModule != dotExprModule) return false } - return structItem.fields - .map { ScopeItem(it.name, it) }.asSequence() + return processor.processAll(structItem.namedFields) } class MvStructDotFieldReferenceImpl( diff --git a/src/main/kotlin/org/move/lang/core/resolve/MatchingProcessor.kt b/src/main/kotlin/org/move/lang/core/resolve/MatchingProcessor.kt deleted file mode 100644 index 5e0d69ee1..000000000 --- a/src/main/kotlin/org/move/lang/core/resolve/MatchingProcessor.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.move.lang.core.resolve - -import org.move.lang.core.psi.MvNamedElement - -data class ScopeItem( - val name: String, - val element: T -) diff --git a/src/main/kotlin/org/move/lang/core/resolve/Processors.kt b/src/main/kotlin/org/move/lang/core/resolve/Processors.kt index 92917afcc..e1cd5155a 100644 --- a/src/main/kotlin/org/move/lang/core/resolve/Processors.kt +++ b/src/main/kotlin/org/move/lang/core/resolve/Processors.kt @@ -13,6 +13,8 @@ import org.move.lang.core.resolve2.createFilter import org.move.lang.core.resolve2.ref.ResolutionContext import org.move.lang.core.resolve2.ref.RsPathResolveResult import org.move.lang.core.resolve2.visInfo +import org.move.lang.core.types.infer.Substitution +import org.move.lang.core.types.infer.emptySubstitution import org.move.stdext.intersects /** @@ -354,8 +356,8 @@ private fun collectMethodOrPathScopeEntry( result += RsPathResolveResult(element, isVisible) } -//fun pickFirstResolveVariant(referenceName: String?, f: (RsResolveProcessor) -> Unit): MvElement? = -// pickFirstResolveEntry(referenceName, f)?.element +fun pickFirstResolveVariant(referenceName: String?, f: (RsResolveProcessor) -> Unit): MvNamedElement? = + pickFirstResolveEntry(referenceName, f)?.element fun pickFirstResolveEntry(referenceName: String?, f: (RsResolveProcessor) -> Unit): ScopeEntry? { if (referenceName == null) return null @@ -383,17 +385,44 @@ private class PickFirstScopeEntryCollector( } +fun resolveSingleResolveVariant(referenceName: String?, f: (RsResolveProcessor) -> Unit): MvNamedElement? = + resolveSingleResolveEntry(referenceName, f).singleOrNull()?.element + +fun resolveSingleResolveEntry(referenceName: String?, f: (RsResolveProcessor) -> Unit): List { + if (referenceName == null) return emptyList() + val processor = ResolveSingleScopeEntryCollector(referenceName) + f(processor) + return processor.result +} + +private class ResolveSingleScopeEntryCollector( + private val referenceName: String, + val result: MutableList = SmartList(), +): RsResolveProcessorBase { + override val names: Set = setOf(referenceName) + + override fun process(entry: ScopeEntry): Boolean { + if (entry.name == referenceName) { + result += entry + } + return result.isNotEmpty() + } +} + + fun collectCompletionVariants( result: CompletionResultSet, context: CompletionContext, + subst: Substitution = emptySubstitution, f: (RsResolveProcessor) -> Unit ) { - val processor = CompletionVariantsCollector(result, context) + val processor = CompletionVariantsCollector(result, subst, context) f(processor) } private class CompletionVariantsCollector( private val result: CompletionResultSet, + private val subst: Substitution, private val context: CompletionContext, ): RsResolveProcessorBase { override val names: Set? get() = null @@ -401,11 +430,14 @@ private class CompletionVariantsCollector( override fun process(entry: ScopeEntry): Boolean { // addEnumVariantsIfNeeded(entry) - result.addElement(createLookupElement( - scopeEntry = entry, - completionContext = context, - priority = entry.element.completionPriority - )) + result.addElement( + createLookupElement( + scopeEntry = entry, + completionContext = context, + priority = entry.element.completionPriority, + subst = subst, + ) + ) return false } diff --git a/src/main/kotlin/org/move/lang/core/types/infer/TypeInferenceWalker.kt b/src/main/kotlin/org/move/lang/core/types/infer/TypeInferenceWalker.kt index 3efc20d34..b4d2542a1 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/TypeInferenceWalker.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/TypeInferenceWalker.kt @@ -10,6 +10,7 @@ import org.move.ide.formatter.impl.location import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* import org.move.lang.core.resolve.collectMethodOrPathResolveVariants +import org.move.lang.core.resolve.resolveSingleResolveVariant import org.move.lang.core.resolve2.processMethodResolveVariants import org.move.lang.core.resolve2.ref.ResolutionContext import org.move.lang.core.types.ty.* @@ -406,8 +407,9 @@ class TypeInferenceWalker( val structTy = receiverTy.derefIfNeeded() as? TyStruct ?: return TyUnknown - val field = - getFieldVariants(dotField, structTy, msl).filterByName(dotField.referenceName).singleOrNull() + val field = resolveSingleResolveVariant(dotField.referenceName) { + processNamedFieldVariants(dotField, structTy, msl, it) + } as? MvNamedFieldDecl ctx.resolvedFields[dotField] = field val fieldTy = field?.type?.loweredType(msl)?.substitute(structTy.typeParameterValues)