Skip to content

Commit

Permalink
remove self type from lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Apr 28, 2024
1 parent 5bb1356 commit 5286448
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/main/kotlin/org/move/lang/core/completion/FuncSignature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)}"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fun MvNamedElement.getLookupElementBuilder(
.withTypeText(signature.retTypeText())
} else {
lookupElementBuilder
.withTailText("${signature.paramsText()}${signature.retTypeSuffix()}")
.withTailText(this.signatureText)
.withTypeText(this.outerFileName)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,35 @@ class LookupElementTest: MvTestBase() {
//^
}
}
""", tailText = "(self: S<u8>)", typeText = "u8"
""", tailText = "(self)", typeText = "u8"
)

fun `test generic method ref`() = checkMethodOrFieldProvider(
"""
module 0x1::main {
struct S<T> { field: T }
fun receiver<T>(self: &S<T>): 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<T> { field: T }
fun receiver<T>(self: &mut S<T>): T {}
fun main() {
let s = S { field: 1u8 };
s.receiver();
//^
}
}
""", tailText = "(&mut self)", typeText = "u8"
)

private fun check(
Expand Down

0 comments on commit 5286448

Please sign in to comment.