diff --git a/src/main/kotlin/org/move/lang/core/completion/FuncSignature.kt b/src/main/kotlin/org/move/lang/core/completion/FuncSignature.kt index f038c9bb6..cb1ce1b0f 100644 --- a/src/main/kotlin/org/move/lang/core/completion/FuncSignature.kt +++ b/src/main/kotlin/org/move/lang/core/completion/FuncSignature.kt @@ -8,6 +8,7 @@ import org.move.lang.core.types.infer.TypeFoldable import org.move.lang.core.types.infer.TypeFolder import org.move.lang.core.types.infer.TypeVisitor import org.move.lang.core.types.ty.Ty +import org.move.lang.core.types.ty.TyReference import org.move.lang.core.types.ty.TyUnit data class FuncSignature( @@ -27,8 +28,17 @@ data class FuncSignature( fun paramsText(): String { return params.entries - .joinToString(", ", prefix = "(", postfix = ")") { (paramName, paramTy) -> - "$paramName: ${paramTy.text(false)}" + .withIndex() + .joinToString(", ", prefix = "(", postfix = ")") { (i, value) -> + val (paramName, paramTy) = value + if (i == 0 && paramName == "self") { + when (paramTy) { + is TyReference -> "&${if (paramTy.isMut) "mut " else ""}self" + else -> "self" + } + } else { + "$paramName: ${paramTy.text(false)}" + } } } 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 6e14b5f59..3fd46d0d3 100644 --- a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt +++ b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt @@ -77,7 +77,7 @@ fun MvNamedElement.getLookupElementBuilder( .withTypeText(signature.retTypeText()) } else { lookupElementBuilder - .withTailText("${signature.paramsText()}${signature.retTypeSuffix()}") + .withTailText(this.signatureText) .withTypeText(this.outerFileName) } } 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 a24105cee..d1c634aaf 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 @@ -66,7 +66,6 @@ object MethodOrFieldCompletionProvider: MvCompletionProvider() { } getMethodVariants(element, receiverTy, msl) .forEach { (_, function) -> - // TODO: can instantiation of TyFunction every time be avoided here? is it slow? val subst = function.tyInfers val declaredFuncTy = function.declaredType(msl).substitute(subst) as TyFunction val declaredSelfTy = declaredFuncTy.paramTypes.first() 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 967cd3639..a869039fa 100644 --- a/src/test/kotlin/org/move/lang/completion/lookups/LookupElementTest.kt +++ b/src/test/kotlin/org/move/lang/completion/lookups/LookupElementTest.kt @@ -107,7 +107,35 @@ class LookupElementTest: MvTestBase() { //^ } } - """, tailText = "(self: S)", typeText = "u8" + """, tailText = "(self)", typeText = "u8" + ) + + fun `test generic method ref`() = checkMethodOrFieldProvider( + """ + module 0x1::main { + struct S { field: T } + fun receiver(self: &S): T {} + fun main() { + let s = S { field: 1u8 }; + s.receiver(); + //^ + } + } + """, tailText = "(&self)", typeText = "u8" + ) + + fun `test generic method ref mut`() = checkMethodOrFieldProvider( + """ + module 0x1::main { + struct S { field: T } + fun receiver(self: &mut S): T {} + fun main() { + let s = S { field: 1u8 }; + s.receiver(); + //^ + } + } + """, tailText = "(&mut self)", typeText = "u8" ) private fun check(