-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
infer types in completion lookups for methods
- Loading branch information
Showing
10 changed files
with
153 additions
and
93 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/kotlin/org/move/lang/core/completion/FuncSignature.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.move.lang.core.completion | ||
|
||
import org.move.ide.presentation.text | ||
import org.move.lang.core.psi.MvFunction | ||
import org.move.lang.core.psi.ext.name | ||
import org.move.lang.core.psi.parameters | ||
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.TyUnit | ||
|
||
data class FuncSignature( | ||
private val params: Map<String, Ty>, | ||
private val retType: Ty, | ||
): TypeFoldable<FuncSignature> { | ||
|
||
override fun innerFoldWith(folder: TypeFolder): FuncSignature { | ||
return FuncSignature( | ||
params = params.mapValues { (_, it) -> folder.fold(it) }, | ||
retType = folder.fold(retType) | ||
) | ||
} | ||
|
||
override fun innerVisitWith(visitor: TypeVisitor): Boolean = | ||
params.values.any { visitor(it) } || visitor(retType) | ||
|
||
fun paramsText(): String { | ||
return params.entries | ||
.joinToString(", ", prefix = "(", postfix = ")") { (paramName, paramTy) -> | ||
"$paramName: ${paramTy.text(false)}" | ||
} | ||
} | ||
|
||
fun retTypeText(): String = retType.text(false) | ||
|
||
fun retTypeSuffix(): String { | ||
return if (retType is TyUnit) "" else ": ${retTypeText()}" | ||
} | ||
|
||
companion object { | ||
fun fromFunction(function: MvFunction, msl: Boolean): FuncSignature { | ||
val declaredType = function.declaredType(msl) | ||
val params = function.parameters.zip(declaredType.paramTypes) | ||
.associate { (param, paramTy) -> Pair(param.name, paramTy) } | ||
val retType = declaredType.retType | ||
return FuncSignature(params, retType) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters