Skip to content

Commit fc2d55e

Browse files
committed
sync code from IntelliJ-EmmyLua
1 parent 478e9ba commit fc2d55e

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

EmmyLua-Common/src/main/java/com/tang/intellij/lua/psi/PsiExtension.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@ val LuaFuncDef.forwardDeclaration: PsiElement? get() {
452452
}
453453
}
454454

455+
val LuaCallExpr.prefixExpr: LuaExpr? get() {
456+
val expr = this.expr
457+
if (expr is LuaIndexExpr) {
458+
return expr.prefixExpr
459+
}
460+
return null
461+
}
462+
455463
val LuaCallExpr.argList: List<LuaExpr> get() {
456464
val args = this.args
457465
return when (args) {

EmmyLua-Common/src/main/java/com/tang/intellij/lua/ty/Expressions.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,18 @@ private fun guessBinaryOpType(binaryExpr : LuaBinaryExpr, context:SearchContext)
112112

113113
fun LuaCallExpr.createSubstitutor(sig: IFunSignature, context: SearchContext): ITySubstitutor? {
114114
if (sig.isGeneric()) {
115-
val list = this.argList.map { it.guessType(context) }
115+
val list = mutableListOf<ITy>()
116+
// self type
117+
if (this.isMethodColonCall) {
118+
this.prefixExpr?.let { prefix ->
119+
list.add(prefix.guessType(context))
120+
}
121+
}
122+
this.argList.map { list.add(it.guessType(context)) }
116123
val map = mutableMapOf<String, ITy>()
117124
var processedIndex = -1
118125
sig.tyParameters.forEach { map[it.name] = Ty.UNKNOWN }
119-
sig.processArgs(this) { index, param ->
126+
sig.processArgs { index, param ->
120127
val arg = list.getOrNull(index)
121128
if (arg != null) {
122129
GenericAnalyzer(arg, param.ty).analyze(map)

EmmyLua-Common/src/main/java/com/tang/intellij/lua/ty/Ty.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ interface ITy : Comparable<ITy> {
6666

6767
fun union(ty: ITy): ITy
6868

69-
@Deprecated("use `displayName` instead")
70-
fun createTypeString(): String
71-
7269
fun subTypeOf(other: ITy, context: SearchContext, strict: Boolean): Boolean
7370

7471
fun getSuperClass(context: SearchContext): ITy?
@@ -136,11 +133,6 @@ abstract class Ty(override val kind: TyKind) : ITy {
136133
return TyUnion.union(this, ty)
137134
}
138135

139-
override fun createTypeString(): String {
140-
val s = toString()
141-
return if (s.isEmpty()) Constants.WORD_ANY else s
142-
}
143-
144136
override fun toString(): String {
145137
val list = mutableListOf<String>()
146138
TyUnion.each(this) { //尽量不使用Global

EmmyLua-Common/src/main/java/com/tang/intellij/lua/ty/TyFunction.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ fun IFunSignature.processArgs(thisTy: ITy?, colonStyle: Boolean, processor: (ind
6262
}
6363
}
6464

65+
fun IFunSignature.processArgs(processor: (index:Int, param: LuaParamInfo) -> Boolean) {
66+
var index = 0
67+
if (colonCall)
68+
index++
69+
for (i in params.indices) {
70+
if (!processor(index++, params[i])) return
71+
}
72+
}
73+
6574
fun IFunSignature.processParams(thisTy: ITy?, colonStyle: Boolean, processor: (index:Int, param: LuaParamInfo) -> Boolean) {
6675
var index = 0
6776
if (colonCall) {

EmmyLua-LS/src/main/kotlin/com/tang/vscode/documentation/DocRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ internal fun renderTy(sb: StringBuilder, ty: ITy) {
6868
sb.appendClassLink(ty.displayName)
6969
}
7070
else -> {
71-
sb.append(ty.createTypeString())
71+
sb.append(ty.displayName)
7272
}
7373
}
7474
}

0 commit comments

Comments
 (0)